aboutsummaryrefslogtreecommitdiffstats
path: root/vespaclient-core
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2019-04-23 09:53:50 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2019-04-23 09:53:50 +0200
commit4c39893e8d5d3ecf13b22f9da3d33c875aef4a6a (patch)
treeec4913b727a817efb62e573c313aa23bc91be3fd /vespaclient-core
parent4c4afce3ab48fdfca83f0a3217d0fe18431e68a7 (diff)
Remove dependency to unmaintained metrics library and stuff only used for /feed api.
Diffstat (limited to 'vespaclient-core')
-rwxr-xr-xvespaclient-core/src/main/java/com/yahoo/clientmetrics/ClientMetrics.java26
-rw-r--r--vespaclient-core/src/main/java/com/yahoo/clientmetrics/MessageTypeMetricSet.java84
-rw-r--r--vespaclient-core/src/main/java/com/yahoo/clientmetrics/RouteMetricSet.java33
-rwxr-xr-xvespaclient-core/src/main/java/com/yahoo/feedapi/FeedContext.java42
-rwxr-xr-xvespaclient-core/src/main/java/com/yahoo/feedapi/SingleSender.java6
-rwxr-xr-xvespaclient-core/src/main/java/com/yahoo/feedhandler/FeedResponse.java3
-rw-r--r--vespaclient-core/src/main/java/com/yahoo/feedhandler/MetricResponse.java38
-rwxr-xr-xvespaclient-core/src/main/java/com/yahoo/feedhandler/VespaFeedHandler.java30
-rwxr-xr-xvespaclient-core/src/main/java/com/yahoo/feedhandler/VespaFeedHandlerBase.java26
9 files changed, 41 insertions, 247 deletions
diff --git a/vespaclient-core/src/main/java/com/yahoo/clientmetrics/ClientMetrics.java b/vespaclient-core/src/main/java/com/yahoo/clientmetrics/ClientMetrics.java
index a94d006675f..ff54f3d4063 100755
--- a/vespaclient-core/src/main/java/com/yahoo/clientmetrics/ClientMetrics.java
+++ b/vespaclient-core/src/main/java/com/yahoo/clientmetrics/ClientMetrics.java
@@ -1,39 +1,21 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.clientmetrics;
-import com.yahoo.messagebus.Reply;
-import com.yahoo.metrics.*;
-import com.yahoo.text.XMLWriter;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.PrintStream;
-import java.text.DecimalFormat;
-import java.text.NumberFormat;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.HashMap;
+import java.util.Map;
/**
* @author thomasg
*/
public class ClientMetrics {
- MetricSet topSet;
- SumMetric sum;
- List<String> routes = new ArrayList<String>();
+ Map<String, RouteMetricSet> routes = new HashMap<>();
public ClientMetrics() {
- topSet = new SimpleMetricSet("routes", "", "", null);
- sum = new SumMetric("total", "", "Messages sent to all routes", topSet);
- }
- public MetricSet getMetricSet() {
- return topSet;
}
public void addRouteMetricSet(RouteMetricSet metric) {
- topSet.registerMetric(metric);
- sum.addMetricToSum(metric);
- routes.add(metric.getRoute());
+ routes.put(metric.getRoute(), metric);
}
}
diff --git a/vespaclient-core/src/main/java/com/yahoo/clientmetrics/MessageTypeMetricSet.java b/vespaclient-core/src/main/java/com/yahoo/clientmetrics/MessageTypeMetricSet.java
index 731a08513e9..45b1a11b4af 100644
--- a/vespaclient-core/src/main/java/com/yahoo/clientmetrics/MessageTypeMetricSet.java
+++ b/vespaclient-core/src/main/java/com/yahoo/clientmetrics/MessageTypeMetricSet.java
@@ -6,61 +6,27 @@ import com.yahoo.documentapi.messagebus.protocol.DocumentProtocol;
import com.yahoo.messagebus.Reply;
import com.yahoo.concurrent.SystemTimer;
import com.yahoo.messagebus.Error;
-import com.yahoo.metrics.CountMetric;
-import com.yahoo.metrics.Metric;
-import com.yahoo.metrics.MetricSet;
-import com.yahoo.metrics.SimpleMetricSet;
-import com.yahoo.metrics.SumMetric;
-import com.yahoo.metrics.ValueMetric;
+import java.util.HashMap;
+import java.util.Map;
import java.util.stream.Stream;
/**
* @author thomasg
*/
-public class MessageTypeMetricSet extends MetricSet {
- ValueMetric<Long> latency;
- CountMetric count;
- CountMetric ignored;
-
- SumMetric errorSum;
- MetricSet errors;
- String msgName;
-
- class ErrorMetric extends CountMetric {
- ErrorMetric(String name, MetricSet owner) {
- super(name, "", "Number of errors of type " + name, owner);
- }
-
- ErrorMetric(ErrorMetric other, CopyType copyType, MetricSet owner) {
- super(other, copyType, owner);
- }
-
- @Override
- public String getXMLTag() {
- return "error";
- }
-
- @Override
- public Metric clone(CopyType type, MetricSet owner, boolean includeUnused) {
- return new ErrorMetric(this, type, owner);
- }
-
- }
-
- public MessageTypeMetricSet(String msgName, MetricSet owner) {
- super(msgName.toLowerCase(), "", "", owner);
+public class MessageTypeMetricSet {
+ public long latency_total;
+ public long latency_min = Long.MAX_VALUE;
+ public long latency_max = Long.MIN_VALUE;
+ public long count = 0;
+ public long ignored = 0;
+ public long errorCount = 0;
+ private final Map<String, Long> errorCounts = new HashMap<>();
+
+ private final String msgName;
+
+ public MessageTypeMetricSet(String msgName) {
this.msgName = msgName;
- latency = new ValueMetric<Long>("latency", "", "Latency (in ms)", this).averageMetric().createAverageOnJoin();
- count = new CountMetric("count", "", "Number received", this);
- ignored = new CountMetric("ignored", "", "Number ignored due to no matching document routing selectors", this);
- errors = new SimpleMetricSet("errors", "", "The errors returned", this);
- errorSum = new SumMetric("total", "", "Total number of errors", errors);
- }
-
- public MessageTypeMetricSet(MessageTypeMetricSet source, CopyType copyType, MetricSet owner, boolean includeUnused) {
- super(source, copyType, owner, includeUnused);
- msgName = source.msgName;
}
public String getMessageName() {
@@ -76,30 +42,30 @@ public class MessageTypeMetricSet extends MetricSet {
}
private void updateFailureMetrics(Reply r) {
+ errorCount++;
String error = DocumentProtocol.getErrorName(r.getError(0).getCode());
- CountMetric s = (CountMetric)errors.getMetric(error);
+ Long s = errorCounts.get(error);
if (s == null) {
- s = new ErrorMetric(error, errors);
- errorSum.addMetricToSum(s);
+ errorCounts.put(error, 1L);
+ } else {
+ errorCounts.put(error, s+1);
}
- s.inc();
}
private void updateSuccessMetrics(Reply r) {
if (!(r instanceof DocumentIgnoredReply)) {
if (r.getMessage().getTimeReceived() != 0) {
- latency.addValue(SystemTimer.INSTANCE.milliTime() - r.getMessage().getTimeReceived());
+ long latency = (SystemTimer.INSTANCE.milliTime() - r.getMessage().getTimeReceived());
+ latency_max = Math.max(latency_max, latency);
+ latency_min = Math.min(latency_min, latency);
+ latency_total += latency;
}
- count.inc();
+ count++;
} else {
- ignored.inc();
+ ignored++;
}
}
- @Override
- public Metric clone(CopyType type, MetricSet owner, boolean includeUnused)
- { return new MessageTypeMetricSet(this, type, owner, includeUnused); }
-
/**
* Returns true if every error in a stream is a test and set condition failed
*/
diff --git a/vespaclient-core/src/main/java/com/yahoo/clientmetrics/RouteMetricSet.java b/vespaclient-core/src/main/java/com/yahoo/clientmetrics/RouteMetricSet.java
index c5469e8a4f1..21efd53d7a5 100644
--- a/vespaclient-core/src/main/java/com/yahoo/clientmetrics/RouteMetricSet.java
+++ b/vespaclient-core/src/main/java/com/yahoo/clientmetrics/RouteMetricSet.java
@@ -2,9 +2,6 @@
package com.yahoo.clientmetrics;
import com.yahoo.messagebus.Reply;
-import com.yahoo.metrics.Metric;
-import com.yahoo.metrics.MetricSet;
-import com.yahoo.metrics.SumMetric;
import java.util.HashMap;
import java.util.Map;
@@ -12,9 +9,9 @@ import java.util.Map;
/**
* @author thomasg
*/
-public class RouteMetricSet extends MetricSet {
+public class RouteMetricSet {
- private final SumMetric sum;
+ private final String route;
private final ProgressCallback callback;
private final Map<Integer, MessageTypeMetricSet> typeMap = new HashMap<>();
@@ -24,28 +21,17 @@ public class RouteMetricSet extends MetricSet {
}
public RouteMetricSet(String route, ProgressCallback callback) {
- super(route, "", "Messages sent to the named route", null);
- sum = new SumMetric("total", "", "All kinds of messages sent to the given route", this);
+ this.route = route;
this.callback = callback;
}
- @Override
- public String getXMLTag() {
- return "route";
- }
-
- private RouteMetricSet(RouteMetricSet source, CopyType copyType, MetricSet owner, boolean includeUnused) {
- super(source, copyType, owner, includeUnused);
- sum = null;
- callback = null;
- }
+ public Map<Integer, MessageTypeMetricSet> getMetrics() { return typeMap; }
public void addReply(Reply r) {
MessageTypeMetricSet type = typeMap.get(r.getMessage().getType());
if (type == null) {
String msgName = r.getMessage().getClass().getSimpleName().replace("Message", "");
- type = new MessageTypeMetricSet(msgName, this);
- sum.addMetricToSum(type);
+ type = new MessageTypeMetricSet(msgName);
typeMap.put(r.getMessage().getType(), type);
}
@@ -61,12 +47,7 @@ public class RouteMetricSet extends MetricSet {
}
}
- @Override
- public Metric clone(CopyType type, MetricSet owner, boolean includeUnused) {
- return new RouteMetricSet(this, type, owner, includeUnused);
- }
-
- String getRoute() {
- return getName();
+ public String getRoute() {
+ return route;
}
}
diff --git a/vespaclient-core/src/main/java/com/yahoo/feedapi/FeedContext.java b/vespaclient-core/src/main/java/com/yahoo/feedapi/FeedContext.java
index 6bfd132a70f..3a435f7cda2 100755
--- a/vespaclient-core/src/main/java/com/yahoo/feedapi/FeedContext.java
+++ b/vespaclient-core/src/main/java/com/yahoo/feedapi/FeedContext.java
@@ -1,14 +1,9 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.feedapi;
-import com.yahoo.cloud.config.ClusterListConfig;
-import com.yahoo.cloud.config.SlobroksConfig;
-import com.yahoo.document.config.DocumentmanagerConfig;
import com.yahoo.jdisc.Metric;
-import com.yahoo.vespa.config.content.LoadTypeConfig;
import com.yahoo.document.DocumentTypeManager;
import com.yahoo.clientmetrics.ClientMetrics;
-import com.yahoo.vespaclient.config.FeederConfig;
import java.util.Map;
import java.util.TreeMap;
@@ -33,10 +28,6 @@ public class FeedContext {
this.metric = metric;
}
- public ClientMetrics getMetrics() {
- return metrics;
- }
-
public Metric getMetricAPI() {
return metric;
}
@@ -83,37 +74,4 @@ public class FeedContext {
return docTypeManager;
}
- public static FeedContext getInstance(FeederConfig feederConfig,
- LoadTypeConfig loadTypeConfig,
- DocumentmanagerConfig documentmanagerConfig,
- SlobroksConfig slobroksConfig,
- Metric metric) {
- synchronized (sync) {
- try {
- if (instance == null) {
- MessagePropertyProcessor proc = new MessagePropertyProcessor(feederConfig, loadTypeConfig);
-
- if (System.getProperty("vespa.local", "false").equals("true")) {
- // Use injected configs when running from Application. This means we cannot reconfigure
- MessageBusSessionFactory mbusFactory = new MessageBusSessionFactory(proc, documentmanagerConfig, slobroksConfig);
- instance = new FeedContext(proc, mbusFactory, mbusFactory.getAccess().getDocumentTypeManager(), metric);
- }
- else {
- // Don't send configs to messagebus to make it self-subscribe instead as this instance
- // survives reconfig :-/
- // This code will die soon ...
- MessageBusSessionFactory mbusFactory = new MessageBusSessionFactory(proc, null, null);
- instance = new FeedContext(proc, mbusFactory, mbusFactory.getAccess().getDocumentTypeManager(), metric);
- }
- } else {
- instance.getPropertyProcessor().configure(feederConfig, loadTypeConfig);
- }
-
- return instance;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- }
-
}
diff --git a/vespaclient-core/src/main/java/com/yahoo/feedapi/SingleSender.java b/vespaclient-core/src/main/java/com/yahoo/feedapi/SingleSender.java
index 9d0c740789e..d78e3a62302 100755
--- a/vespaclient-core/src/main/java/com/yahoo/feedapi/SingleSender.java
+++ b/vespaclient-core/src/main/java/com/yahoo/feedapi/SingleSender.java
@@ -19,12 +19,10 @@ public class SingleSender implements SimpleFeedAccess {
private final SharedSender.ResultCallback owner;
private final SharedSender sender;
private final List<MessageProcessor> messageProcessors = new ArrayList<>();
- private boolean blockingQueue;
- public SingleSender(SharedSender.ResultCallback owner, SharedSender sender, boolean blockingQueue) {
+ public SingleSender(SharedSender.ResultCallback owner, SharedSender sender) {
this.owner = owner;
this.sender = sender;
- this.blockingQueue = blockingQueue;
}
@Override
@@ -86,7 +84,7 @@ public class SingleSender implements SimpleFeedAccess {
* @param m The message to send
*/
public void send(Message m) {
- sender.send(processMessage(m), owner, blockingQueue);
+ sender.send(processMessage(m), owner, true);
}
public void done() {
diff --git a/vespaclient-core/src/main/java/com/yahoo/feedhandler/FeedResponse.java b/vespaclient-core/src/main/java/com/yahoo/feedhandler/FeedResponse.java
index 4bf1267201a..da226e9ece6 100755
--- a/vespaclient-core/src/main/java/com/yahoo/feedhandler/FeedResponse.java
+++ b/vespaclient-core/src/main/java/com/yahoo/feedhandler/FeedResponse.java
@@ -57,9 +57,6 @@ public final class FeedResponse extends HttpResponse implements SharedSender.Res
XMLWriter writer = new XMLWriter(new OutputStreamWriter(outputStream));
writer.openTag("result");
- if (metrics != null) {
- metrics.printXml(writer, 0, 0);
- }
if (traces.length() > 0) {
writer.openTag("trace");
writer.append(traces);
diff --git a/vespaclient-core/src/main/java/com/yahoo/feedhandler/MetricResponse.java b/vespaclient-core/src/main/java/com/yahoo/feedhandler/MetricResponse.java
deleted file mode 100644
index 4947032e649..00000000000
--- a/vespaclient-core/src/main/java/com/yahoo/feedhandler/MetricResponse.java
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.feedhandler;
-
-import com.yahoo.container.jdisc.HttpResponse;
-import com.yahoo.metrics.MetricSet;
-import com.yahoo.text.XMLWriter;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-
-/**
- * Response that generates metric output like a status page.
- */
-public final class MetricResponse extends HttpResponse {
-
- MetricSet set;
-
- MetricResponse(MetricSet set) {
- super(com.yahoo.jdisc.http.HttpResponse.Status.OK);
- this.set = set;
- }
-
- @Override
- public void render(OutputStream stream) throws IOException {
- XMLWriter writer = new XMLWriter(new OutputStreamWriter(stream));
- writer.openTag("status");
- set.printXml(writer, 0, 2);
- writer.closeTag();
- writer.flush();
- }
-
- @Override
- public java.lang.String getContentType() {
- return "application/xml";
- }
-
-}
diff --git a/vespaclient-core/src/main/java/com/yahoo/feedhandler/VespaFeedHandler.java b/vespaclient-core/src/main/java/com/yahoo/feedhandler/VespaFeedHandler.java
index 4587c84f9dc..59cd86670e1 100755
--- a/vespaclient-core/src/main/java/com/yahoo/feedhandler/VespaFeedHandler.java
+++ b/vespaclient-core/src/main/java/com/yahoo/feedhandler/VespaFeedHandler.java
@@ -1,15 +1,11 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.feedhandler;
-import com.google.inject.Inject;
import com.yahoo.clientmetrics.RouteMetricSet;
-import com.yahoo.cloud.config.ClusterListConfig;
-import com.yahoo.cloud.config.SlobroksConfig;
import com.yahoo.container.jdisc.EmptyResponse;
import com.yahoo.container.jdisc.HttpRequest;
import com.yahoo.container.jdisc.HttpResponse;
import com.yahoo.container.protect.Error;
-import com.yahoo.document.config.DocumentmanagerConfig;
import com.yahoo.feedapi.DocprocMessageProcessor;
import com.yahoo.feedapi.FeedContext;
import com.yahoo.feedapi.Feeder;
@@ -18,9 +14,6 @@ import com.yahoo.feedapi.MessagePropertyProcessor;
import com.yahoo.feedapi.SimpleFeedAccess;
import com.yahoo.feedapi.SingleSender;
import com.yahoo.feedapi.XMLFeeder;
-import com.yahoo.jdisc.Metric;
-import com.yahoo.vespa.config.content.LoadTypeConfig;
-import com.yahoo.vespaclient.config.FeederConfig;
import java.util.List;
import java.util.concurrent.Executor;
@@ -40,18 +33,6 @@ public final class VespaFeedHandler extends VespaFeedHandlerBase {
private final AtomicInteger busyThreads = new AtomicInteger(0);
private final int maxBusyThreads;
- @SuppressWarnings("unused")
- @Inject
- public VespaFeedHandler(FeederConfig feederConfig,
- LoadTypeConfig loadTypeConfig,
- DocumentmanagerConfig documentmanagerConfig,
- SlobroksConfig slobroksConfig,
- Executor executor,
- Metric metric) {
- super(feederConfig, loadTypeConfig, documentmanagerConfig, slobroksConfig, executor, metric);
- this.maxBusyThreads = feederConfig.maxbusythreads();
- }
-
private VespaFeedHandler(FeedContext context, Executor executor) {
super(context, executor);
this.maxBusyThreads = 32;
@@ -67,22 +48,17 @@ public final class VespaFeedHandler extends VespaFeedHandlerBase {
}
public HttpResponse handle(HttpRequest request, RouteMetricSet.ProgressCallback callback, int numThreads) {
- 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);
+ SingleSender sender = new SingleSender(response, getSharedSender(route));
sender.addMessageProcessor(properties);
sender.addMessageProcessor(new DocprocMessageProcessor(getDocprocChain(request), getDocprocServiceRegistry(request)));
ThreadedFeedAccess feedAccess = new ThreadedFeedAccess(numThreads, sender);
@@ -101,10 +77,6 @@ public final class VespaFeedHandler extends VespaFeedHandlerBase {
sender.done();
feedAccess.close();
-
- if (asynchronous) {
- return response;
- }
long millis = getTimeoutMillis(request);
boolean completed = sender.waitForPending(millis);
if (!completed) {
diff --git a/vespaclient-core/src/main/java/com/yahoo/feedhandler/VespaFeedHandlerBase.java b/vespaclient-core/src/main/java/com/yahoo/feedhandler/VespaFeedHandlerBase.java
index 9dc81c31a0d..ec2b7202f09 100755
--- a/vespaclient-core/src/main/java/com/yahoo/feedhandler/VespaFeedHandlerBase.java
+++ b/vespaclient-core/src/main/java/com/yahoo/feedhandler/VespaFeedHandlerBase.java
@@ -1,22 +1,16 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.feedhandler;
-import com.google.inject.Inject;
-import com.yahoo.clientmetrics.ClientMetrics;
-import com.yahoo.cloud.config.SlobroksConfig;
import com.yahoo.component.provider.ComponentRegistry;
import com.yahoo.container.jdisc.HttpRequest;
import com.yahoo.container.jdisc.ThreadedHttpRequestHandler;
import com.yahoo.docproc.DocprocService;
import com.yahoo.document.DocumentTypeManager;
-import com.yahoo.document.config.DocumentmanagerConfig;
import com.yahoo.feedapi.FeedContext;
import com.yahoo.feedapi.MessagePropertyProcessor;
import com.yahoo.feedapi.SharedSender;
-import com.yahoo.jdisc.Metric;
import com.yahoo.search.query.ParameterParser;
-import com.yahoo.vespa.config.content.LoadTypeConfig;
-import com.yahoo.vespaclient.config.FeederConfig;
+
import java.io.IOException;
import java.io.InputStream;
@@ -28,23 +22,11 @@ public abstract class VespaFeedHandlerBase extends ThreadedHttpRequestHandler {
protected FeedContext context;
private final long defaultTimeoutMillis;
- @Inject
- public VespaFeedHandlerBase(FeederConfig feederConfig,
- LoadTypeConfig loadTypeConfig,
- DocumentmanagerConfig documentmanagerConfig,
- SlobroksConfig slobroksConfig,
- Executor executor,
- Metric metric) {
- this(FeedContext.getInstance(feederConfig, loadTypeConfig, documentmanagerConfig,
- slobroksConfig, metric),
- executor, (long)feederConfig.timeout() * 1000);
- }
-
VespaFeedHandlerBase(FeedContext context, Executor executor) {
this(context, executor, context.getPropertyProcessor().getDefaultTimeoutMillis());
}
- VespaFeedHandlerBase(FeedContext context, Executor executor, long defaultTimeoutMillis) {
+ private VespaFeedHandlerBase(FeedContext context, Executor executor, long defaultTimeoutMillis) {
super(executor, context.getMetricAPI());
this.context = context;
this.defaultTimeoutMillis = defaultTimeoutMillis;
@@ -88,10 +70,6 @@ public abstract class VespaFeedHandlerBase extends ThreadedHttpRequestHandler {
return context.getDocumentTypeManager();
}
- public ClientMetrics getMetrics() {
- return context.getMetrics();
- }
-
protected long getTimeoutMillis(HttpRequest request) {
return ParameterParser.asMilliSeconds(request.getProperty("timeout"), defaultTimeoutMillis);
}