summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgjoranv <gv@verizonmedia.com>2020-07-01 13:52:04 +0200
committerGitHub <noreply@github.com>2020-07-01 13:52:04 +0200
commitcd2020277c6bf9ba7c1812495bdd9ff403b66578 (patch)
treefadcd7475b0956c60413bf44a7b2b6b02ed2e724
parent33e855b00dd02506fc19aa078b3992b5f4ff11de (diff)
parentfac243d4e5c44513012d074070b4de2e9502398a (diff)
Merge pull request #13761 from vespa-engine/add-prometheus-to-resource-list
Add prometheus path to the resource list in the root response
-rw-r--r--metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/application/ApplicationMetricsHandler.java3
-rw-r--r--metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/application/ApplicationMetricsHandlerTest.java20
2 files changed, 14 insertions, 9 deletions
diff --git a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/application/ApplicationMetricsHandler.java b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/application/ApplicationMetricsHandler.java
index c910ac26833..f5f1eb5791d 100644
--- a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/application/ApplicationMetricsHandler.java
+++ b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/application/ApplicationMetricsHandler.java
@@ -56,7 +56,8 @@ public class ApplicationMetricsHandler extends HttpHandlerBase {
@Override
public Optional<HttpResponse> doHandle(URI requestUri, Path apiPath, String consumer) {
- if (apiPath.matches(METRICS_V1_PATH)) return Optional.of(resourceListResponse(requestUri, List.of(METRICS_VALUES_PATH)));
+ if (apiPath.matches(METRICS_V1_PATH)) return Optional.of(resourceListResponse(requestUri, List.of(METRICS_VALUES_PATH,
+ PROMETHEUS_VALUES_PATH)));
if (apiPath.matches(METRICS_VALUES_PATH)) return Optional.of(applicationMetricsResponse(consumer));
if (apiPath.matches(PROMETHEUS_VALUES_PATH)) return Optional.of(applicationPrometheusResponse(consumer));
diff --git a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/application/ApplicationMetricsHandlerTest.java b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/application/ApplicationMetricsHandlerTest.java
index 46c4af4c1f4..cc6b6b36057 100644
--- a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/application/ApplicationMetricsHandlerTest.java
+++ b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/application/ApplicationMetricsHandlerTest.java
@@ -27,6 +27,7 @@ import static ai.vespa.metricsproxy.TestUtil.getFileContents;
import static ai.vespa.metricsproxy.http.ValuesFetcher.DEFAULT_PUBLIC_CONSUMER_ID;
import static ai.vespa.metricsproxy.http.application.ApplicationMetricsHandler.METRICS_V1_PATH;
import static ai.vespa.metricsproxy.http.application.ApplicationMetricsHandler.METRICS_VALUES_PATH;
+import static ai.vespa.metricsproxy.http.application.ApplicationMetricsHandler.PROMETHEUS_VALUES_PATH;
import static ai.vespa.metricsproxy.metric.model.json.JacksonUtil.createObjectMapper;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
@@ -48,8 +49,9 @@ public class ApplicationMetricsHandlerTest {
private static final String HOST = "localhost";
private static final String URI_BASE = "http://" + HOST;
- private static final String APP_METRICS_V1_URI = URI_BASE + METRICS_V1_PATH;
- private static final String APP_METRICS_VALUES_URI = URI_BASE + METRICS_VALUES_PATH;
+ private static final String METRICS_V1_URI = URI_BASE + METRICS_V1_PATH;
+ private static final String METRICS_VALUES_URI = URI_BASE + METRICS_VALUES_PATH;
+ private static final String PROMETHEUS_VALUES_URI = URI_BASE + PROMETHEUS_VALUES_PATH;
private static final String TEST_FILE = "generic-sample.json";
private static final String RESPONSE = getFileContents(TEST_FILE);
@@ -95,21 +97,23 @@ public class ApplicationMetricsHandlerTest {
@Test
public void v1_response_contains_values_uri() throws Exception {
- String response = testDriver.sendRequest(APP_METRICS_V1_URI).readAll();
+ String response = testDriver.sendRequest(METRICS_V1_URI).readAll();
JSONObject root = new JSONObject(response);
assertTrue(root.has("resources"));
JSONArray resources = root.getJSONArray("resources");
- assertEquals(1, resources.length());
+ assertEquals(2, resources.length());
JSONObject valuesUrl = resources.getJSONObject(0);
- assertEquals(APP_METRICS_VALUES_URI, valuesUrl.getString("url"));
+ assertEquals(METRICS_VALUES_URI, valuesUrl.getString("url"));
+ JSONObject prometheusUrl = resources.getJSONObject(1);
+ assertEquals(PROMETHEUS_VALUES_URI, prometheusUrl.getString("url"));
}
@Ignore
@Test
public void visually_inspect_values_response() throws Exception {
- String response = testDriver.sendRequest(APP_METRICS_VALUES_URI).readAll();
+ String response = testDriver.sendRequest(METRICS_VALUES_URI).readAll();
ObjectMapper mapper = createObjectMapper();
var jsonModel = mapper.readValue(response, GenericApplicationModel.class);
System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonModel));
@@ -166,13 +170,13 @@ public class ApplicationMetricsHandlerTest {
@Test
public void invalid_path_yields_error_response() throws Exception {
- String response = testDriver.sendRequest(APP_METRICS_V1_URI + "/invalid").readAll();
+ String response = testDriver.sendRequest(METRICS_V1_URI + "/invalid").readAll();
JSONObject root = new JSONObject(response);
assertTrue(root.has("error"));
}
private GenericApplicationModel getResponseAsJsonModel(String consumer) {
- String response = testDriver.sendRequest(APP_METRICS_VALUES_URI + "?consumer=" + consumer).readAll();
+ String response = testDriver.sendRequest(METRICS_VALUES_URI + "?consumer=" + consumer).readAll();
try {
return createObjectMapper().readValue(response, GenericApplicationModel.class);
} catch (IOException e) {