summaryrefslogtreecommitdiffstats
path: root/metrics-proxy
diff options
context:
space:
mode:
authorOla Aunrønning <olaa@verizonmedia.com>2019-08-30 12:10:12 +0200
committerOla Aunrønning <olaa@verizonmedia.com>2019-08-30 12:10:12 +0200
commit94174f2b0d660d183041f22732cadd20b0655720 (patch)
tree8f1b82d6bbc7b7559386dfae67407212f8f55980 /metrics-proxy
parent27de6084e585507dd0f253f4d20fcca9a9a325d4 (diff)
Added handler to metrics proxy container cluster
Diffstat (limited to 'metrics-proxy')
-rw-r--r--metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/Yamas/YamasHandler.java (renamed from metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/YamasHandler.java)50
1 files changed, 11 insertions, 39 deletions
diff --git a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/YamasHandler.java b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/Yamas/YamasHandler.java
index fca1b66342f..e29cf202bd9 100644
--- a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/YamasHandler.java
+++ b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/Yamas/YamasHandler.java
@@ -2,11 +2,14 @@
* Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
*/
-package ai.vespa.metricsproxy.http;
+package ai.vespa.metricsproxy.http.Yamas;
import ai.vespa.metricsproxy.core.MetricsConsumers;
import ai.vespa.metricsproxy.core.MetricsManager;
import ai.vespa.metricsproxy.gatherer.NodeMetricGatherer;
+import ai.vespa.metricsproxy.http.ErrorResponse;
+import ai.vespa.metricsproxy.http.JsonResponse;
+import ai.vespa.metricsproxy.http.ValuesFetcher;
import ai.vespa.metricsproxy.metric.dimensions.ApplicationDimensions;
import ai.vespa.metricsproxy.metric.dimensions.NodeDimensions;
import ai.vespa.metricsproxy.metric.model.MetricsPacket;
@@ -18,30 +21,26 @@ import com.yahoo.container.jdisc.HttpRequest;
import com.yahoo.container.jdisc.HttpResponse;
import com.yahoo.container.jdisc.ThreadedHttpRequestHandler;
import com.yahoo.restapi.Path;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-import java.net.URI;
import java.util.List;
import java.util.concurrent.Executor;
+import static ai.vespa.metricsproxy.http.RestApiUtil.resourceListResponse;
import static com.yahoo.jdisc.Response.Status.INTERNAL_SERVER_ERROR;
import static com.yahoo.jdisc.Response.Status.METHOD_NOT_ALLOWED;
import static com.yahoo.jdisc.Response.Status.NOT_FOUND;
import static com.yahoo.jdisc.Response.Status.OK;
import static com.yahoo.jdisc.http.HttpRequest.Method.GET;
-import static java.util.logging.Level.WARNING;
/**
* @author olaa
*/
-// TODO: Merge with gjoranv's API util changes
+
public class YamasHandler extends ThreadedHttpRequestHandler {
- static final String V1_PATH = "/yamas/v1";
- static final String VALUES_PATH = V1_PATH + "/values";
+ public static final String V1_PATH = "/yamas/v1";
+ private static final String VALUES_PATH = V1_PATH + "/values";
private final ValuesFetcher valuesFetcher;
private final NodeMetricGatherer nodeMetricGatherer;
@@ -54,7 +53,7 @@ public class YamasHandler extends ThreadedHttpRequestHandler {
ApplicationDimensions applicationDimensions,
NodeDimensions nodeDimensions) {
super(executor);
- valuesFetcher = new ValuesFetcher(metricsManager, vespaServices, metricsConsumers);
+ this.valuesFetcher = new ValuesFetcher(metricsManager, vespaServices, metricsConsumers);
this.nodeMetricGatherer = new NodeMetricGatherer(metricsManager, vespaServices, applicationDimensions, nodeDimensions);
}
@@ -64,47 +63,20 @@ public class YamasHandler extends ThreadedHttpRequestHandler {
Path path = new Path(request.getUri());
- if (path.matches(V1_PATH)) return v1Response(request.getUri());
+ if (path.matches(V1_PATH)) return resourceListResponse(request.getUri(), List.of(VALUES_PATH));
if (path.matches(VALUES_PATH)) return valuesResponse(request);
return new ErrorResponse(NOT_FOUND, "No content at given path");
}
- private JsonResponse v1Response(URI requestUri) {
- try {
- return new JsonResponse(OK, v1Content(requestUri));
- } catch (JSONException e) {
- log.log(WARNING, "Bad JSON construction in " + V1_PATH + " response", e);
- return new ErrorResponse(INTERNAL_SERVER_ERROR, "An error occurred, please try path '" + VALUES_PATH + "'");
- }
- }
-
private JsonResponse valuesResponse(HttpRequest request) {
try {
List<MetricsPacket> metrics = valuesFetcher.fetch(request.getProperty("consumer"));
- metrics.addAll(nodeMetricGatherer.gatherMetrics());
+ metrics.addAll(nodeMetricGatherer.gatherMetrics()); // TODO: Currently only add these metrics in this handler. Eventually should be included in all handlers
return new JsonResponse(OK, YamasJsonUtil.toYamasArray(metrics).serialize());
} catch (JsonRenderingException e) {
return new ErrorResponse(INTERNAL_SERVER_ERROR, e.getMessage());
}
}
- // TODO: Use jackson with a "Resources" class instead of JSONObject
- private String v1Content(URI requestUri) throws JSONException {
- int port = requestUri.getPort();
- String host = requestUri.getHost();
- StringBuilder base = new StringBuilder("http://");
- base.append(host);
- if (port >= 0) {
- base.append(":").append(port);
- }
- String uriBase = base.toString();
- JSONArray linkList = new JSONArray();
- for (String api : new String[] {VALUES_PATH}) {
- JSONObject resource = new JSONObject();
- resource.put("url", uriBase + api);
- linkList.put(resource);
- }
- return new JSONObject().put("resources", linkList).toString(4);
- }
} \ No newline at end of file