summaryrefslogtreecommitdiffstats
path: root/vespaclient-container-plugin
diff options
context:
space:
mode:
authorvalerijf <valerijf@yahoo-inc.com>2017-05-11 12:54:47 +0200
committervalerijf <valerijf@yahoo-inc.com>2017-05-11 12:54:47 +0200
commit605ae73f3699b35a9071b0736235b5c5cfbc5ad4 (patch)
tree64e10d1129e591575ccc5ed7e99d39e679d62202 /vespaclient-container-plugin
parent2ffb9f91d8cefb9a83e3018c599445ce1990d251 (diff)
Created helper classes to collect feed metrics
Diffstat (limited to 'vespaclient-container-plugin')
-rw-r--r--vespaclient-container-plugin/src/main/java/com/yahoo/documentapi/metrics/DocumentApiMetricsHelper.java53
-rw-r--r--vespaclient-container-plugin/src/main/java/com/yahoo/documentapi/metrics/DocumentOperationStatus.java33
-rw-r--r--vespaclient-container-plugin/src/main/java/com/yahoo/documentapi/metrics/DocumentOperationType.java26
3 files changed, 112 insertions, 0 deletions
diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/documentapi/metrics/DocumentApiMetricsHelper.java b/vespaclient-container-plugin/src/main/java/com/yahoo/documentapi/metrics/DocumentApiMetricsHelper.java
new file mode 100644
index 00000000000..a082f7dba8a
--- /dev/null
+++ b/vespaclient-container-plugin/src/main/java/com/yahoo/documentapi/metrics/DocumentApiMetricsHelper.java
@@ -0,0 +1,53 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.documentapi.metrics;
+
+import com.yahoo.metrics.simple.Counter;
+import com.yahoo.metrics.simple.Gauge;
+import com.yahoo.metrics.simple.MetricReceiver;
+import com.yahoo.metrics.simple.Point;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ * @author freva
+ */
+public class DocumentApiMetricsHelper {
+ private final Counter feeds;
+ private final Gauge feedLatency;
+ private final Map<DocumentOperationStatus, Map<DocumentOperationType, Point>> points = new HashMap<>();
+
+ public DocumentApiMetricsHelper(MetricReceiver metricReceiver, String apiName) {
+ Map<String, String> dimensions = new HashMap<>();
+ dimensions.put("api", apiName);
+ for (DocumentOperationStatus status : DocumentOperationStatus.values()) {
+ points.put(status, new HashMap<>());
+ dimensions.put("status", status.name());
+ for (DocumentOperationType operation : DocumentOperationType.values()) {
+ dimensions.put("operation", operation.name());
+ points.get(status).put(operation, new Point(dimensions));
+ }
+ }
+
+ feeds = metricReceiver.declareCounter("feed_operations");
+ feedLatency = metricReceiver.declareGauge("feed_latency");
+ }
+
+ public void reportSuccessful(DocumentOperationType documentOperationType, double latency) {
+ Point point = points.get(DocumentOperationStatus.OK).get(documentOperationType);
+
+ feedLatency.sample(latency, point);
+ feeds.add(point);
+ }
+
+ public void reportSuccessful(DocumentOperationType documentOperationType, long startTime) {
+ final double latency = (System.currentTimeMillis() - startTime) / 1000.0d;
+ reportSuccessful(documentOperationType, latency);
+ }
+
+ public void reportFailure(DocumentOperationType documentOperationType, DocumentOperationStatus documentOperationStatus) {
+ Point point = points.get(documentOperationStatus).get(documentOperationType);
+ feeds.add(point);
+ }
+}
diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/documentapi/metrics/DocumentOperationStatus.java b/vespaclient-container-plugin/src/main/java/com/yahoo/documentapi/metrics/DocumentOperationStatus.java
new file mode 100644
index 00000000000..3ed1f42ca14
--- /dev/null
+++ b/vespaclient-container-plugin/src/main/java/com/yahoo/documentapi/metrics/DocumentOperationStatus.java
@@ -0,0 +1,33 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.documentapi.metrics;
+
+import com.yahoo.document.restapi.OperationHandlerImpl;
+
+import java.util.Set;
+
+/**
+ * @author freva
+ */
+public enum DocumentOperationStatus {
+ OK, CLIENT_ERROR, SERVER_ERROR;
+
+ public static DocumentOperationStatus fromHttpStatusCode(int httpStatus) {
+ switch (httpStatus / 100) {
+ case 2:
+ return OK;
+
+ case 4:
+ return CLIENT_ERROR;
+
+ case 5:
+ return SERVER_ERROR;
+
+ default:
+ return null;
+ }
+ }
+
+ public static DocumentOperationStatus fromMessageBusErrorCodes(Set<Integer> errorCodes) {
+ return fromHttpStatusCode(OperationHandlerImpl.getHTTPStatusCode(errorCodes));
+ }
+}
diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/documentapi/metrics/DocumentOperationType.java b/vespaclient-container-plugin/src/main/java/com/yahoo/documentapi/metrics/DocumentOperationType.java
new file mode 100644
index 00000000000..56849b9db8f
--- /dev/null
+++ b/vespaclient-container-plugin/src/main/java/com/yahoo/documentapi/metrics/DocumentOperationType.java
@@ -0,0 +1,26 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.documentapi.metrics;
+
+import com.yahoo.documentapi.messagebus.protocol.DocumentProtocol;
+import com.yahoo.messagebus.Message;
+
+/**
+ * @author freva
+ */
+public enum DocumentOperationType {
+ PUT, REMOVE, UPDATE;
+
+ public static DocumentOperationType fromMessage(Message msg) {
+ switch (msg.getType()) {
+ case DocumentProtocol.MESSAGE_PUTDOCUMENT:
+ return PUT;
+ case DocumentProtocol.MESSAGE_UPDATEDOCUMENT:
+ return UPDATE;
+ case DocumentProtocol.MESSAGE_REMOVEDOCUMENT:
+ return REMOVE;
+ default:
+ return null;
+ }
+ }
+}
+