diff options
author | gjoranv <gv@verizonmedia.com> | 2019-08-27 13:49:50 +0200 |
---|---|---|
committer | gjoranv <gv@verizonmedia.com> | 2019-08-27 13:51:27 +0200 |
commit | 4a1e122f1fc87b7f024bbf1449188718dba0b0c3 (patch) | |
tree | fd32f5edc784d5447bc37a8f934b8d17b7621e7e /metrics-proxy/src | |
parent | abec40773cd964b7244278b96b72748d76385760 (diff) |
Make ValuesFetcher return MetricsPackets instead of json
.. to allow using it for other handlers that require other formats
Diffstat (limited to 'metrics-proxy/src')
-rw-r--r-- | metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/MetricsHandler.java | 5 | ||||
-rw-r--r-- | metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/ValuesFetcher.java | 5 |
2 files changed, 6 insertions, 4 deletions
diff --git a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/MetricsHandler.java b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/MetricsHandler.java index ea9bb38245f..e191c5e1c43 100644 --- a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/MetricsHandler.java +++ b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/MetricsHandler.java @@ -6,6 +6,7 @@ package ai.vespa.metricsproxy.http; import ai.vespa.metricsproxy.core.MetricsConsumers; import ai.vespa.metricsproxy.core.MetricsManager; +import ai.vespa.metricsproxy.metric.model.MetricsPacket; import ai.vespa.metricsproxy.metric.model.json.JsonRenderingException; import ai.vespa.metricsproxy.service.VespaServices; import com.google.inject.Inject; @@ -18,6 +19,7 @@ import java.util.List; import java.util.concurrent.Executor; import static ai.vespa.metricsproxy.http.RestApiUtil.resourceListResponse; +import static ai.vespa.metricsproxy.metric.model.json.GenericJsonUtil.toGenericJsonModel; 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; @@ -59,7 +61,8 @@ public class MetricsHandler extends ThreadedHttpRequestHandler { private JsonResponse valuesResponse(HttpRequest request) { try { - return new JsonResponse(OK, valuesFetcher.fetch(request.getProperty("consumer"))); + List<MetricsPacket> metrics = valuesFetcher.fetch(request.getProperty("consumer")); + return new JsonResponse(OK, toGenericJsonModel(metrics).serialize()); } catch (JsonRenderingException e) { return new ErrorResponse(INTERNAL_SERVER_ERROR, e.getMessage()); } diff --git a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/ValuesFetcher.java b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/ValuesFetcher.java index 4686d9c1751..f99fe962f38 100644 --- a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/ValuesFetcher.java +++ b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/ValuesFetcher.java @@ -41,14 +41,13 @@ public class ValuesFetcher { this.metricsConsumers = metricsConsumers; } - public String fetch(String requestedConsumer) throws JsonRenderingException { + public List<MetricsPacket> fetch(String requestedConsumer) throws JsonRenderingException { ConsumerId consumer = getConsumerOrDefault(requestedConsumer); - List<MetricsPacket> metrics = metricsManager.getMetrics(vespaServices.getVespaServices(), Instant.now()) + return metricsManager.getMetrics(vespaServices.getVespaServices(), Instant.now()) .stream() .filter(metricsPacket -> metricsPacket.consumers().contains(consumer)) .collect(Collectors.toList()); - return toGenericJsonModel(metrics).serialize(); } private ConsumerId getConsumerOrDefault(String consumer) { |