summaryrefslogtreecommitdiffstats
path: root/metrics-proxy/src/test/java/ai
diff options
context:
space:
mode:
authorgjoranv <gv@verizonmedia.com>2020-01-03 00:13:21 +0100
committergjoranv <gv@verizonmedia.com>2020-01-03 11:25:32 +0100
commit0c301c98d930a5e0a48b62bf8a5eda6abfc58257 (patch)
tree4d6e6788104441cddd8fbc2373a7db24432e7b72 /metrics-proxy/src/test/java/ai
parent869e9e83274e037cae548ac5eb3c72881e90859a (diff)
Properly support multiple consumers when caching metrics.
Diffstat (limited to 'metrics-proxy/src/test/java/ai')
-rw-r--r--metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/application/NodeMetricsClientTest.java32
1 files changed, 32 insertions, 0 deletions
diff --git a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/application/NodeMetricsClientTest.java b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/application/NodeMetricsClientTest.java
index d028db93d43..6c319a4d74c 100644
--- a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/application/NodeMetricsClientTest.java
+++ b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/application/NodeMetricsClientTest.java
@@ -20,11 +20,15 @@ import java.util.List;
import static ai.vespa.metricsproxy.TestUtil.getFileContents;
import static ai.vespa.metricsproxy.http.ValuesFetcher.DEFAULT_PUBLIC_CONSUMER_ID;
+import static ai.vespa.metricsproxy.metric.model.ConsumerId.toConsumerId;
+import static ai.vespa.metricsproxy.metric.model.MetricId.toMetricId;
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 org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
/**
* Two optimizations worth noting:
@@ -40,6 +44,10 @@ public class NodeMetricsClientTest {
private static final String RESPONSE = getFileContents(TEST_FILE);
private static final CloseableHttpClient httpClient = HttpClients.createDefault();
+ private static final String CPU_METRIC = "cpu.util";
+ private static final String REPLACED_CPU_METRIC = "replaced_cpu_util";
+ private static final String CUSTOM_CONSUMER = "custom-consumer";
+
private static Node node;
private ManualClock clock;
@@ -54,6 +62,17 @@ public class NodeMetricsClientTest {
URI metricsUri = node.metricsUri(DEFAULT_PUBLIC_CONSUMER_ID);
wireMockRule.stubFor(get(urlPathEqualTo(metricsUri.getPath()))
.willReturn(aResponse().withBody(RESPONSE)));
+
+ wireMockRule.stubFor(get(urlPathEqualTo(metricsUri.getPath()))
+ .withQueryParam("consumer", equalTo(DEFAULT_PUBLIC_CONSUMER_ID.id))
+ .willReturn(aResponse().withBody(RESPONSE)));
+
+ // Add a slightly different response for a custom consumer.
+ String myConsumerResponse = RESPONSE.replaceAll(CPU_METRIC, REPLACED_CPU_METRIC);
+ wireMockRule.stubFor(get(urlPathEqualTo(metricsUri.getPath()))
+ .withQueryParam("consumer", equalTo(CUSTOM_CONSUMER))
+ .willReturn(aResponse().withBody(myConsumerResponse)));
+
}
@Before
@@ -94,4 +113,17 @@ public class NodeMetricsClientTest {
assertEquals(2, nodeMetricsClient.snapshotsRetrieved());
}
+ @Test
+ public void metrics_for_different_consumers_are_cached_separately() {
+ List<MetricsPacket.Builder> defaultMetrics = nodeMetricsClient.getMetrics(DEFAULT_PUBLIC_CONSUMER_ID);
+ assertEquals(1, nodeMetricsClient.snapshotsRetrieved());
+ assertEquals(4, defaultMetrics.size());
+
+ List<MetricsPacket.Builder> customMetrics = nodeMetricsClient.getMetrics(toConsumerId(CUSTOM_CONSUMER));
+ assertEquals(2, nodeMetricsClient.snapshotsRetrieved());
+ assertEquals(4, customMetrics.size());
+
+ MetricsPacket replacedCpuMetric = customMetrics.get(0).build();
+ assertTrue(replacedCpuMetric.metrics().containsKey(toMetricId(REPLACED_CPU_METRIC)));
+ }
}