aboutsummaryrefslogtreecommitdiffstats
path: root/container-core/src/test/java/com/yahoo/container/handler/metrics
diff options
context:
space:
mode:
authorAmund Bergland Kvalsvik <akvalsvik@verizonmedia.com>2020-06-29 11:18:48 +0200
committerAmund Bergland Kvalsvik <akvalsvik@verizonmedia.com>2020-06-29 11:18:48 +0200
commitc2fbfa9ebf866d9be5ec4826bab056b2f517f8a4 (patch)
tree1241957666d0b2591538d23ad3a3466ca986d981 /container-core/src/test/java/com/yahoo/container/handler/metrics
parente3a53542dbff6121488db259959e85965b87600b (diff)
Fixed review comments
Diffstat (limited to 'container-core/src/test/java/com/yahoo/container/handler/metrics')
-rw-r--r--container-core/src/test/java/com/yahoo/container/handler/metrics/MetricsV2HandlerTest.java3
-rw-r--r--container-core/src/test/java/com/yahoo/container/handler/metrics/PrometheusV1HandlerTest.java (renamed from container-core/src/test/java/com/yahoo/container/handler/metrics/PrometheusHandlerTest.java)45
2 files changed, 17 insertions, 31 deletions
diff --git a/container-core/src/test/java/com/yahoo/container/handler/metrics/MetricsV2HandlerTest.java b/container-core/src/test/java/com/yahoo/container/handler/metrics/MetricsV2HandlerTest.java
index 1e8dccbcd26..3f406368f68 100644
--- a/container-core/src/test/java/com/yahoo/container/handler/metrics/MetricsV2HandlerTest.java
+++ b/container-core/src/test/java/com/yahoo/container/handler/metrics/MetricsV2HandlerTest.java
@@ -60,7 +60,6 @@ public class MetricsV2HandlerTest {
new MetricsProxyApiConfig.Builder()
.metricsPort(wireMockRule.port())
.metricsApiPath(MOCK_METRICS_PATH)
- .prometheusPort(0)
.prometheusApiPath("Not/In/Use")
.build());
testDriver = new RequestHandlerTestDriver(handler);
@@ -134,7 +133,7 @@ public class MetricsV2HandlerTest {
}
}
- private static String getFileContents(String filename) {
+ public static String getFileContents(String filename) {
InputStream in = MetricsV2HandlerTest.class.getClassLoader().getResourceAsStream(filename);
if (in == null) {
throw new RuntimeException("File not found: " + filename);
diff --git a/container-core/src/test/java/com/yahoo/container/handler/metrics/PrometheusHandlerTest.java b/container-core/src/test/java/com/yahoo/container/handler/metrics/PrometheusV1HandlerTest.java
index 31b21651fdc..4a94b4a1a7d 100644
--- a/container-core/src/test/java/com/yahoo/container/handler/metrics/PrometheusHandlerTest.java
+++ b/container-core/src/test/java/com/yahoo/container/handler/metrics/PrometheusV1HandlerTest.java
@@ -3,6 +3,10 @@ package com.yahoo.container.handler.metrics;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
import com.yahoo.container.jdisc.RequestHandlerTestDriver;
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.stream.Collectors;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -11,41 +15,35 @@ import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
import java.util.concurrent.Executors;
-import java.util.stream.Collectors;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
-import static com.yahoo.container.handler.metrics.MetricsV2Handler.V2_PATH;
-import static com.yahoo.container.handler.metrics.MetricsV2Handler.VALUES_PATH;
import static com.yahoo.container.handler.metrics.MetricsV2Handler.consumerQuery;
+import static com.yahoo.container.handler.metrics.MetricsV2HandlerTest.getFileContents;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
/**
* @author gjoranv
*/
-public class PrometheusHandlerTest {
+public class PrometheusV1HandlerTest {
private static final String URI_BASE = "http://localhost";
- private static final String V2_URI = URI_BASE + PrometheusHandler.V1_PATH;
- private static final String VALUES_URI = URI_BASE + PrometheusHandler.VALUES_PATH;
+ private static final String V1_URI = URI_BASE + PrometheusV1Handler.V1_PATH;
+ private static final String VALUES_URI = URI_BASE + PrometheusV1Handler.VALUES_PATH;
// Mock applicationmetrics api
private static final String MOCK_METRICS_PATH = "/node0";
- private static final String TEST_FILE = "application-metrics.json";
+ private static final String TEST_FILE = "application-prometheus.txt";
private static final String RESPONSE = getFileContents(TEST_FILE);
- private static final String CPU_METRIC = "cpu.util";
- private static final String REPLACED_CPU_METRIC = "replaced_cpu_util";
+ private static final String CPU_METRIC = "cpu";
+ private static final String REPLACED_CPU_METRIC = "replaced_cpu";
private static final String CUSTOM_CONSUMER = "custom-consumer";
private static RequestHandlerTestDriver testDriver;
@@ -56,11 +54,10 @@ public class PrometheusHandlerTest {
@Before
public void setup() {
setupWireMock();
- var handler = new PrometheusHandler(Executors.newSingleThreadExecutor(),
+ var handler = new PrometheusV1Handler(Executors.newSingleThreadExecutor(),
new MetricsProxyApiConfig.Builder()
- .prometheusPort(wireMockRule.port())
.prometheusApiPath(MOCK_METRICS_PATH)
- .metricsPort(0)
+ .metricsPort(wireMockRule.port())
.metricsApiPath("/Not/In/Use")
.build());
testDriver = new RequestHandlerTestDriver(handler);
@@ -80,7 +77,7 @@ public class PrometheusHandlerTest {
@Test
public void v2_response_contains_values_uri() throws Exception {
- String response = testDriver.sendRequest(V2_URI).readAll();
+ String response = testDriver.sendRequest(V1_URI).readAll();
JSONObject root = new JSONObject(response);
assertTrue(root.has("resources"));
@@ -91,6 +88,7 @@ public class PrometheusHandlerTest {
assertEquals(VALUES_URI, valuesUri.getString("url"));
}
+ @Ignore
@Test
public void visually_inspect_values_response() throws Exception {
String response = testDriver.sendRequest(VALUES_URI).readAll();
@@ -99,14 +97,12 @@ public class PrometheusHandlerTest {
@Test
public void invalid_path_yields_error_response() throws Exception {
- String response = testDriver.sendRequest(V2_URI + "/invalid").readAll();
+ String response = testDriver.sendRequest(V1_URI + "/invalid").readAll();
JSONObject root = new JSONObject(response);
assertTrue(root.has("error"));
assertTrue(root.getString("error" ).startsWith("No content"));
}
- //Currently broken as no way to convert to Prometheus format around here
- @Ignore
@Test
public void values_response_is_equal_to_test_file() {
String response = testDriver.sendRequest(VALUES_URI).readAll();
@@ -119,13 +115,4 @@ public class PrometheusHandlerTest {
assertTrue(response.contains(REPLACED_CPU_METRIC));
}
-
- private static String getFileContents(String filename) {
- InputStream in = PrometheusHandlerTest.class.getClassLoader().getResourceAsStream(filename);
- if (in == null) {
- throw new RuntimeException("File not found: " + filename);
- }
- return new BufferedReader(new InputStreamReader(in)).lines().collect(Collectors.joining("\n"));
- }
-
}