summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmund Bergland Kvalsvik <akvalsvik@verizonmedia.com>2020-07-17 16:27:43 +0200
committerAmund Bergland Kvalsvik <akvalsvik@verizonmedia.com>2020-07-17 16:27:43 +0200
commitc3abfa48aa42b04d23edefe218d7dc1a73fdc8bb (patch)
tree858217e5bc96487111df3012dfce97e25f68c134
parentf1d49e5d8be88d61c832569ca0871dc240f2ebe2 (diff)
added regex and hostname test
-rw-r--r--metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/application/ApplicationMetricsHandlerTest.java31
1 files changed, 30 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..19ba02a0469 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,24 @@ 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.startsWith("#"))
+ .forEach(line -> assertTrue(line.contains("hostname")));
+ assertTrue(response.contains("hostname"));
+ }
+
+ @Test
+ public void prometheus_response_contains_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);