Search in sources :

Example 1 with RouteMetricSet

use of com.yahoo.clientmetrics.RouteMetricSet in project vespa by vespa-engine.

the class ProgressPrinter method getOkMessageCount.

public long getOkMessageCount(RouteMetricSet metrics) {
    SumMetric sum = (SumMetric) metrics.getMetric("total");
    MetricSet ms = (MetricSet) sum.generateSum();
    if (ms != null) {
        Metric latency = ms.getMetric("latency");
        if (latency != null) {
            return latency.getLongValue("count");
        }
    }
    return 0;
}
Also used : SumMetric(com.yahoo.metrics.SumMetric) Metric(com.yahoo.metrics.Metric) SumMetric(com.yahoo.metrics.SumMetric) MetricSet(com.yahoo.metrics.MetricSet) MessageTypeMetricSet(com.yahoo.clientmetrics.MessageTypeMetricSet) RouteMetricSet(com.yahoo.clientmetrics.RouteMetricSet)

Example 2 with RouteMetricSet

use of com.yahoo.clientmetrics.RouteMetricSet in project vespa by vespa-engine.

the class BenchmarkProgressPrinterTest method testSimple.

public void testSimple() {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    DummyTimer timer = new DummyTimer();
    timer.ms = 0;
    BenchmarkProgressPrinter printer = new BenchmarkProgressPrinter(timer, new PrintStream(output));
    RouteMetricSet metrics = new RouteMetricSet("foobar", printer);
    {
        EmptyReply reply = new EmptyReply();
        reply.setMessage(PutDocumentMessage.createEmpty().setTimeReceived(1));
        metrics.addReply(reply);
    }
    timer.ms = 1200;
    {
        EmptyReply reply = new EmptyReply();
        reply.setMessage(PutDocumentMessage.createEmpty().setTimeReceived(2));
        metrics.addReply(reply);
    }
    {
        EmptyReply reply = new EmptyReply();
        reply.setMessage(UpdateDocumentMessage.createEmpty().setTimeReceived(3));
        metrics.addReply(reply);
    }
    timer.ms = 2400;
    {
        EmptyReply reply = new EmptyReply();
        reply.setMessage(UpdateDocumentMessage.createEmpty().setTimeReceived(4));
        reply.addError(new com.yahoo.messagebus.Error(32, "foo"));
        metrics.addReply(reply);
    }
    timer.ms = 62000;
    {
        EmptyReply reply = new EmptyReply();
        reply.setMessage(UpdateDocumentMessage.createEmpty().setTimeReceived(5));
        reply.addError(new com.yahoo.messagebus.Error(64, "bar"));
        metrics.addReply(reply);
    }
    metrics.done();
    String val = output.toString().split("\n")[1];
    String correctPattern = "62000,\\s*3,\\s*2,\\s*\\d+,\\s*\\d+,\\s*\\d+$";
    assertTrue("Value '" + val + "' does not match pattern '" + correctPattern + "'", val.matches(correctPattern));
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RouteMetricSet(com.yahoo.clientmetrics.RouteMetricSet) EmptyReply(com.yahoo.messagebus.EmptyReply)

Example 3 with RouteMetricSet

use of com.yahoo.clientmetrics.RouteMetricSet in project vespa by vespa-engine.

the class VespaFeedHandler method handle.

public HttpResponse handle(HttpRequest request, RouteMetricSet.ProgressCallback callback) {
    if (request.getProperty("status") != null) {
        return new MetricResponse(context.getMetrics().getMetricSet());
    }
    try {
        int busy = busyThreads.incrementAndGet();
        if (busy > maxBusyThreads)
            return new EmptyResponse(com.yahoo.jdisc.http.HttpResponse.Status.SERVICE_UNAVAILABLE);
        boolean asynchronous = request.getBooleanProperty("asynchronous");
        MessagePropertyProcessor.PropertySetter properties = getPropertyProcessor().buildPropertySetter(request);
        String route = properties.getRoute().toString();
        FeedResponse response = new FeedResponse(new RouteMetricSet(route, callback));
        SingleSender sender = new SingleSender(response, getSharedSender(route), !asynchronous);
        sender.addMessageProcessor(properties);
        sender.addMessageProcessor(new DocprocMessageProcessor(getDocprocChain(request), getDocprocServiceRegistry(request)));
        Feeder feeder = createFeeder(sender, request);
        feeder.setAbortOnDocumentError(properties.getAbortOnDocumentError());
        feeder.setCreateIfNonExistent(properties.getCreateIfNonExistent());
        response.setAbortOnFeedError(properties.getAbortOnFeedError());
        List<String> errors = feeder.parse();
        for (String s : errors) {
            response.addXMLParseError(s);
        }
        if (errors.size() > 0 && feeder instanceof XMLFeeder) {
            response.addXMLParseError("If you are trying to feed JSON, set the Content-Type header to application/json.");
        }
        sender.done();
        if (asynchronous) {
            return response;
        }
        long millis = getTimeoutMillis(request);
        boolean completed = sender.waitForPending(millis);
        if (!completed) {
            response.addError(Error.TIMEOUT, "Timed out after " + millis + " ms waiting for responses");
        }
        response.done();
        return response;
    } finally {
        busyThreads.decrementAndGet();
    }
}
Also used : DocprocMessageProcessor(com.yahoo.feedapi.DocprocMessageProcessor) RouteMetricSet(com.yahoo.clientmetrics.RouteMetricSet) SingleSender(com.yahoo.feedapi.SingleSender) XMLFeeder(com.yahoo.feedapi.XMLFeeder) Feeder(com.yahoo.feedapi.Feeder) JsonFeeder(com.yahoo.feedapi.JsonFeeder) XMLFeeder(com.yahoo.feedapi.XMLFeeder) EmptyResponse(com.yahoo.container.jdisc.EmptyResponse) MessagePropertyProcessor(com.yahoo.feedapi.MessagePropertyProcessor)

Example 4 with RouteMetricSet

use of com.yahoo.clientmetrics.RouteMetricSet in project vespa by vespa-engine.

the class VespaFeedHandlerRemoveLocation method handle.

@Override
public HttpResponse handle(HttpRequest request) {
    MessagePropertyProcessor.PropertySetter properties = getPropertyProcessor().buildPropertySetter(request);
    FeedResponse response;
    if (request.getProperty("route") == null) {
        if (context.getClusterList().getStorageClusters().size() == 0) {
            return new FeedResponse(null).addError("No storage clusters configured and no alternate route specified.");
        } else if (context.getClusterList().getStorageClusters().size() > 1) {
            return new FeedResponse(null).addError("More than one storage cluster configured and no route specified.");
        } else {
            properties.setRoute(Route.parse(context.getClusterList().getStorageClusters().get(0).getName()));
        }
    }
    response = new FeedResponse(new RouteMetricSet(properties.getRoute().toString(), null));
    SingleSender sender = new SingleSender(response, getSharedSender(properties.getRoute().toString()));
    sender.addMessageProcessor(properties);
    String user = request.getProperty("user");
    String group = request.getProperty("group");
    String selection = request.getProperty("selection");
    boolean oneFound = (user != null) ^ (group != null) ^ (selection != null);
    if (!oneFound) {
        response.addError("Exactly one of \"user\", \"group\" or \"selection\" must be specified for removelocation");
        return response;
    }
    if (user != null) {
        selection = "id.user=" + user;
    }
    if (group != null) {
        selection = "id.group=\"" + group + "\"";
    }
    sender.send(new RemoveLocationMessage(selection));
    sender.done();
    long millis = getTimeoutMillis(request);
    boolean completed = sender.waitForPending(millis);
    if (!completed)
        response.addError(Error.TIMEOUT, "Timed out after " + millis + " ms waiting for responses");
    return response;
}
Also used : RemoveLocationMessage(com.yahoo.documentapi.messagebus.protocol.RemoveLocationMessage) RouteMetricSet(com.yahoo.clientmetrics.RouteMetricSet) SingleSender(com.yahoo.feedapi.SingleSender) MessagePropertyProcessor(com.yahoo.feedapi.MessagePropertyProcessor)

Example 5 with RouteMetricSet

use of com.yahoo.clientmetrics.RouteMetricSet in project vespa by vespa-engine.

the class VespaFeedHandlerRemove method handle.

@Override
public HttpResponse handle(HttpRequest request) {
    if (request.getProperty("status") != null) {
        return new MetricResponse(context.getMetrics().getMetricSet());
    }
    MessagePropertyProcessor.PropertySetter properties = getPropertyProcessor().buildPropertySetter(request);
    String route = properties.getRoute().toString();
    FeedResponse response = new FeedResponse(new RouteMetricSet(route, null));
    SingleSender sender = new SingleSender(response, getSharedSender(route));
    sender.addMessageProcessor(properties);
    response.setAbortOnFeedError(properties.getAbortOnFeedError());
    if (request.hasProperty("id")) {
        sender.remove(new DocumentId(request.getProperty("id")));
    } else if (request.hasProperty("id[0]")) {
        int index = 0;
        while (request.hasProperty("id[" + index + "]")) {
            sender.remove(new DocumentId(request.getProperty("id[" + index + "]")));
            ++index;
        }
    }
    if (request.getData() != null) {
        try {
            String line;
            BufferedReader reader = new BufferedReader(new InputStreamReader(getRequestInputStream(request), "UTF-8"));
            while ((line = reader.readLine()) != null) {
                sender.remove(new DocumentId(line));
            }
        } catch (Exception e) {
            response.addError(e.getClass() + ": " + e.getCause());
        }
    }
    sender.done();
    long millis = getTimeoutMillis(request);
    boolean completed = sender.waitForPending(millis);
    if (!completed)
        response.addError(Error.TIMEOUT, "Timed out after " + millis + " ms waiting for responses");
    return response;
}
Also used : InputStreamReader(java.io.InputStreamReader) DocumentId(com.yahoo.document.DocumentId) RouteMetricSet(com.yahoo.clientmetrics.RouteMetricSet) SingleSender(com.yahoo.feedapi.SingleSender) BufferedReader(java.io.BufferedReader) MessagePropertyProcessor(com.yahoo.feedapi.MessagePropertyProcessor)

Aggregations

RouteMetricSet (com.yahoo.clientmetrics.RouteMetricSet)6 MessagePropertyProcessor (com.yahoo.feedapi.MessagePropertyProcessor)3 SingleSender (com.yahoo.feedapi.SingleSender)3 EmptyReply (com.yahoo.messagebus.EmptyReply)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 PrintStream (java.io.PrintStream)2 MessageTypeMetricSet (com.yahoo.clientmetrics.MessageTypeMetricSet)1 EmptyResponse (com.yahoo.container.jdisc.EmptyResponse)1 DocumentId (com.yahoo.document.DocumentId)1 DocumentIgnoredReply (com.yahoo.documentapi.messagebus.protocol.DocumentIgnoredReply)1 RemoveLocationMessage (com.yahoo.documentapi.messagebus.protocol.RemoveLocationMessage)1 DocprocMessageProcessor (com.yahoo.feedapi.DocprocMessageProcessor)1 Feeder (com.yahoo.feedapi.Feeder)1 JsonFeeder (com.yahoo.feedapi.JsonFeeder)1 XMLFeeder (com.yahoo.feedapi.XMLFeeder)1 Metric (com.yahoo.metrics.Metric)1 MetricSet (com.yahoo.metrics.MetricSet)1 SumMetric (com.yahoo.metrics.SumMetric)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1