summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmund Bergland Kvalsvik <31984662+Oracien@users.noreply.github.com>2020-07-20 11:27:09 +0200
committerGitHub <noreply@github.com>2020-07-20 11:27:09 +0200
commitf11e22927b86725998507ad2eee262036f2c473d (patch)
tree6231a7cd0e2a71ccc7a1647793c306b1d156d3b1
parent9ba56dd4bcab7cad71f04737cf858a76236a5acf (diff)
parent02c7d5ed8bc25280ae8961cdb5d485a6dbe86f2e (diff)
Merge pull request #13920 from vespa-engine/adding-prometheus-unit-tests
added regex and hostname test
-rw-r--r--metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/application/ApplicationMetricsHandlerTest.java30
1 files changed, 29 insertions, 1 deletions
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 cc6b6b36057..0fa6fea7d11 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
@@ -11,6 +11,8 @@ import ai.vespa.metricsproxy.metric.model.json.GenericService;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
import com.yahoo.container.jdisc.RequestHandlerTestDriver;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Before;
@@ -62,6 +64,8 @@ public class ApplicationMetricsHandlerTest {
private static final String MOCK_METRICS_PATH = "/node0";
+ private static final Pattern PROMETHEUS_REGEX_FORMAT = Pattern.compile("[a-z_]+([{]([A-Za-z_]+=\"[A-Za-z.\\-\\/0.9_]+\",)*[}])?( [0-9E]+(\\.[0-9E]+)?){2}");
+
private int port;
private static RequestHandlerTestDriver testDriver;
@@ -112,13 +116,20 @@ public class ApplicationMetricsHandlerTest {
@Ignore
@Test
- public void visually_inspect_values_response() throws Exception {
+ public void visually_inspect_values_response_metrics() throws Exception {
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));
}
+ @Ignore
+ @Test
+ public void visually_inspect_values_response_prometheus() throws Exception {
+ String response = testDriver.sendRequest(PROMETHEUS_VALUES_URI).readAll();
+ System.out.println(response);
+ }
+
@Test
public void response_contains_node() {
GenericApplicationModel jsonModel = getResponseAsJsonModel(DEFAULT_PUBLIC_CONSUMER_ID.id);
@@ -132,6 +143,23 @@ public class ApplicationMetricsHandlerTest {
}
@Test
+ public void prometheus_response_contains_hostname() {
+ String response = testDriver.sendRequest(PROMETHEUS_VALUES_URI).readAll();
+ Arrays.stream(response.split("\n"))
+ .filter(line -> line.contains("{"))
+ .forEach(line -> assertTrue(line.contains("hostname")));
+ }
+
+ @Test
+ public void prometheus_response_obeys_format() {
+ String response = testDriver.sendRequest(PROMETHEUS_VALUES_URI).readAll();
+ Arrays.stream(response.split("\n"))
+ .filter(line -> !line.startsWith("#"))
+ .filter(line -> !line.contains("{"))
+ .forEach(line -> assertTrue(PROMETHEUS_REGEX_FORMAT.matcher(line).find()));
+ }
+
+ @Test
public void response_contains_services_with_metrics() {
GenericApplicationModel jsonModel = getResponseAsJsonModel(DEFAULT_PUBLIC_CONSUMER_ID.id);