diff options
author | valerijf <valerijf@yahoo-inc.com> | 2017-05-11 14:40:17 +0200 |
---|---|---|
committer | valerijf <valerijf@yahoo-inc.com> | 2017-05-11 14:40:17 +0200 |
commit | 73655beaa410faec8cf5ef7f5c3891ce4f69cc4e (patch) | |
tree | d8a31cca57403803fb2142ea2403056aa2100243 | |
parent | e227d212b3c0791fe233cd7ffa95d295cc9e078c (diff) |
Update feed metrics in vespa.http.server
3 files changed, 28 insertions, 11 deletions
diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedHandler.java b/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedHandler.java index fdfc64d7ba4..acb12d291ba 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedHandler.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedHandler.java @@ -11,16 +11,19 @@ import com.yahoo.container.jdisc.messagebus.SessionCache; import com.yahoo.container.logging.AccessLog; import com.yahoo.document.DocumentTypeManager; import com.yahoo.document.config.DocumentmanagerConfig; +import com.yahoo.documentapi.metrics.DocumentApiMetricsHelper; import com.yahoo.jdisc.Metric; import com.yahoo.jdisc.http.HttpResponse.Status; import com.yahoo.log.LogLevel; import com.yahoo.messagebus.ReplyHandler; import com.yahoo.messagebus.SourceSessionParams; +import com.yahoo.metrics.simple.MetricReceiver; import com.yahoo.net.HostName; import com.yahoo.yolean.Exceptions; import com.yahoo.vespa.http.client.core.Headers; import com.yahoo.vespa.http.client.core.OperationStatus; +import javax.inject.Inject; import java.io.IOException; import java.io.InputStream; import java.net.InetSocketAddress; @@ -56,20 +59,23 @@ public class FeedHandler extends LoggingRequestHandler { private final String localHostname; private final FeedHandlerV3 feedHandlerV3; + @Inject public FeedHandler( Executor executor, DocumentmanagerConfig documentManagerConfig, SessionCache sessionCache, Metric metric, AccessLog accessLog, - ThreadpoolConfig threadpoolConfig) throws Exception { + ThreadpoolConfig threadpoolConfig, + MetricReceiver metricReceiver) throws Exception { super(executor, accessLog); - feedHandlerV3 = new FeedHandlerV3(executor, documentManagerConfig, sessionCache, metric, accessLog, threadpoolConfig); + DocumentApiMetricsHelper metricsHelper = new DocumentApiMetricsHelper(metricReceiver, "vespa.http.server"); + feedHandlerV3 = new FeedHandlerV3(executor, documentManagerConfig, sessionCache, metric, accessLog, threadpoolConfig, metricsHelper); docTypeManager = createDocumentManager(documentManagerConfig); clients = new HashMap<>(); this.sessionCache = sessionCache; sessionId = new AtomicLong(new Random(System.currentTimeMillis()).nextLong()); - feedReplyHandler = new FeedReplyReader(metric); + feedReplyHandler = new FeedReplyReader(metric, metricsHelper); cron = new ScheduledThreadPoolExecutor(1, ThreadFactoryFactory.getThreadFactory("feedhandler.cron")); cron.scheduleWithFixedDelay(new CleanClients(), 16, 11, TimeUnit.MINUTES); this.metric = metric; diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedHandlerV3.java b/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedHandlerV3.java index 72fe87ad9b6..134387f0114 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedHandlerV3.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedHandlerV3.java @@ -10,6 +10,7 @@ import com.yahoo.container.jdisc.messagebus.SessionCache; import com.yahoo.container.logging.AccessLog; import com.yahoo.document.DocumentTypeManager; import com.yahoo.document.config.DocumentmanagerConfig; +import com.yahoo.documentapi.metrics.DocumentApiMetricsHelper; import com.yahoo.jdisc.Metric; import com.yahoo.jdisc.ReferencedResource; import com.yahoo.log.LogLevel; @@ -53,11 +54,12 @@ public class FeedHandlerV3 extends LoggingRequestHandler { SessionCache sessionCache, Metric metric, AccessLog accessLog, - ThreadpoolConfig threadpoolConfig) throws Exception { + ThreadpoolConfig threadpoolConfig, + DocumentApiMetricsHelper metricsHelper) throws Exception { super(executor, accessLog); docTypeManager = new DocumentTypeManager(documentManagerConfig); this.sessionCache = sessionCache; - feedReplyHandler = new FeedReplyReader(metric); + feedReplyHandler = new FeedReplyReader(metric, metricsHelper); cron = new ScheduledThreadPoolExecutor(1, ThreadFactoryFactory.getThreadFactory("feedhandlerv3.cron")); cron.scheduleWithFixedDelay(this::removeOldClients, 16, 11, TimeUnit.MINUTES); this.metric = metric; diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedReplyReader.java b/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedReplyReader.java index 26dc97c5c65..3dd75e3d7eb 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedReplyReader.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedReplyReader.java @@ -1,9 +1,14 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.http.server; +import java.util.Set; import java.util.logging.Logger; +import com.yahoo.documentapi.messagebus.MessageBusAsyncSession; import com.yahoo.documentapi.messagebus.protocol.DocumentProtocol; +import com.yahoo.documentapi.metrics.DocumentApiMetricsHelper; +import com.yahoo.documentapi.metrics.DocumentOperationStatus; +import com.yahoo.documentapi.metrics.DocumentOperationType; import com.yahoo.jdisc.Metric; import com.yahoo.log.LogLevel; import com.yahoo.messagebus.Reply; @@ -21,9 +26,11 @@ public class FeedReplyReader implements ReplyHandler { private static final Logger log = Logger.getLogger(FeedReplyReader.class.getName()); private final Metric metric; + private final DocumentApiMetricsHelper metricsHelper; - public FeedReplyReader(Metric metric) { + public FeedReplyReader(Metric metric, DocumentApiMetricsHelper metricsHelper) { this.metric = metric; + this.metricsHelper = metricsHelper; } @Override @@ -33,15 +40,18 @@ public class FeedReplyReader implements ReplyHandler { return; } ReplyContext context = (ReplyContext) o; - metric.set( - MetricNames.LATENCY, - Double.valueOf((System.currentTimeMillis() - context.creationTime) / 1000.0d), - null); + final double latency = (System.currentTimeMillis() - context.creationTime) / 1000.0d; + metric.set(MetricNames.LATENCY, latency, null); + if (reply.hasErrors()) { + //Set<Integer> errorCodes = MessageBusAsyncSession.getErrorCodes(reply); + //metricsHelper.reportFailure(DocumentOperationType.fromMessage(reply.getMessage()), + // DocumentOperationStatus.fromMessageBusErrorCodes(errorCodes)); metric.add(MetricNames.FAILED, 1, null); enqueue(context, reply.getError(0).getMessage(), ErrorCode.ERROR, reply.getError(0).getCode() == DocumentProtocol.ERROR_TEST_AND_SET_CONDITION_FAILED, reply.getTrace()); } else { + metricsHelper.reportSuccessful(DocumentOperationType.fromMessage(reply.getMessage()), latency); metric.add(MetricNames.SUCCEEDED, 1, null); enqueue(context, "Document processed.", ErrorCode.OK, false, reply.getTrace()); } @@ -58,5 +68,4 @@ public class FeedReplyReader implements ReplyHandler { Thread.currentThread().interrupt(); } } - }
\ No newline at end of file |