summaryrefslogtreecommitdiffstats
path: root/metrics-proxy
diff options
context:
space:
mode:
authorOla Aunronning <olaa@yahooinc.com>2023-11-13 13:45:08 +0100
committerOla Aunronning <olaa@yahooinc.com>2023-11-13 13:45:08 +0100
commit7d413afce5949da4dfd25baf8d170acdb7d919d1 (patch)
tree9f8e382782293d52c2aca9d66fcf08758fd56100 /metrics-proxy
parent87d3284e7a77304d4781dfb6808ddb1d5d9f98c3 (diff)
Add host_life metric to prometheus output
Diffstat (limited to 'metrics-proxy')
-rw-r--r--metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/prometheus/PrometheusHandler.java10
-rw-r--r--metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/prometheus/PrometheusHandlerTest.java8
2 files changed, 15 insertions, 3 deletions
diff --git a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/prometheus/PrometheusHandler.java b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/prometheus/PrometheusHandler.java
index e8da690ea9b..aa7ac3356cb 100644
--- a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/prometheus/PrometheusHandler.java
+++ b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/prometheus/PrometheusHandler.java
@@ -6,6 +6,7 @@ import ai.vespa.metricsproxy.core.MetricsManager;
import ai.vespa.metricsproxy.http.TextResponse;
import ai.vespa.metricsproxy.http.ValuesFetcher;
import ai.vespa.metricsproxy.metric.model.MetricsPacket;
+import ai.vespa.metricsproxy.node.NodeMetricGatherer;
import ai.vespa.metricsproxy.service.VespaServices;
import com.yahoo.component.annotation.Inject;
import com.yahoo.container.handler.metrics.HttpHandlerBase;
@@ -13,6 +14,7 @@ import com.yahoo.container.jdisc.HttpResponse;
import com.yahoo.restapi.Path;
import java.net.URI;
+import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.Executor;
@@ -31,14 +33,17 @@ public class PrometheusHandler extends HttpHandlerBase {
static final String VALUES_PATH = V1_PATH + "/values";
private final ValuesFetcher valuesFetcher;
+ private final NodeMetricGatherer nodeMetricGatherer;
@Inject
public PrometheusHandler(Executor executor,
MetricsManager metricsManager,
VespaServices vespaServices,
- MetricsConsumers metricsConsumers) {
+ MetricsConsumers metricsConsumers,
+ NodeMetricGatherer nodeMetricGatherer) {
super(executor);
valuesFetcher = new ValuesFetcher(metricsManager, vespaServices, metricsConsumers);
+ this.nodeMetricGatherer = nodeMetricGatherer;
}
@Override
@@ -50,7 +55,8 @@ public class PrometheusHandler extends HttpHandlerBase {
private TextResponse valuesResponse(String consumer) {
try {
- List<MetricsPacket> metrics = valuesFetcher.fetch(consumer);
+ List<MetricsPacket> metrics = new ArrayList<>(valuesFetcher.fetch(consumer));
+ metrics.addAll(nodeMetricGatherer.gatherMetrics());
return new TextResponse(OK, toPrometheusModel(metrics).serialize());
} catch (Exception e) {
log.log(Level.WARNING, "Got exception when rendering metrics:", e);
diff --git a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/prometheus/PrometheusHandlerTest.java b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/prometheus/PrometheusHandlerTest.java
index d6bde07d39a..e49a3c2bf50 100644
--- a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/prometheus/PrometheusHandlerTest.java
+++ b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/prometheus/PrometheusHandlerTest.java
@@ -2,6 +2,7 @@
package ai.vespa.metricsproxy.http.prometheus;
import ai.vespa.metricsproxy.http.HttpHandlerTestBase;
+import ai.vespa.metricsproxy.node.NodeMetricGatherer;
import ai.vespa.metricsproxy.service.DummyService;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -35,7 +36,8 @@ public class PrometheusHandlerTest extends HttpHandlerTestBase {
PrometheusHandler handler = new PrometheusHandler(Executors.newSingleThreadExecutor(),
getMetricsManager(),
vespaServices,
- getMetricsConsumers());
+ getMetricsConsumers(),
+ getNodeMetricGatherer());
testDriver = new RequestHandlerTestDriver(handler);
valuesResponse = testDriver.sendRequest(VALUES_URI).readAll();
}
@@ -92,4 +94,8 @@ public class PrometheusHandlerTest extends HttpHandlerTestBase {
}
throw new IllegalArgumentException("No line containing string: " + searchString);
}
+
+ private static NodeMetricGatherer getNodeMetricGatherer() {
+ return new NodeMetricGatherer(getMetricsManager(), getApplicationDimensions(), getNodeDimensions());
+ }
}