From 29e722b8d3a8ef088f3e302ceeb88a1736e13f25 Mon Sep 17 00:00:00 2001 From: Bjørn Christian Seime Date: Tue, 23 Nov 2021 15:58:21 +0100 Subject: Add status code as dimension to response metrics --- .../jetty/HttpResponseStatisticsCollectorTest.java | 48 ++++++++++++---------- 1 file changed, 27 insertions(+), 21 deletions(-) (limited to 'container-core/src/test') diff --git a/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpResponseStatisticsCollectorTest.java b/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpResponseStatisticsCollectorTest.java index eecab11d9fe..3187ea510d4 100644 --- a/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpResponseStatisticsCollectorTest.java +++ b/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpResponseStatisticsCollectorTest.java @@ -31,6 +31,7 @@ import static org.hamcrest.Matchers.equalTo; /** * @author ollivir + * @author bjorncs */ public class HttpResponseStatisticsCollectorTest { @@ -47,8 +48,9 @@ public class HttpResponseStatisticsCollectorTest { testRequest("http", 200, "GET"); var stats = collector.takeStatistics(); - assertStatisticsEntry(stats, "http", "GET", MetricDefinitions.RESPONSES_2XX, "read", 1L); - assertStatisticsEntry(stats, "http", "GET", MetricDefinitions.RESPONSES_3XX, "read", 2L); + assertStatisticsEntry(stats, "http", "GET", MetricDefinitions.RESPONSES_2XX, "read", 200, 1L); + assertStatisticsEntry(stats, "http", "GET", MetricDefinitions.RESPONSES_3XX, "read", 301, 1L); + assertStatisticsEntry(stats, "http", "GET", MetricDefinitions.RESPONSES_3XX, "read", 300, 1L); } @Test @@ -65,12 +67,12 @@ public class HttpResponseStatisticsCollectorTest { testRequest("https", 200, "POST"); var stats = collector.takeStatistics(); - assertStatisticsEntry(stats, "http", "GET", MetricDefinitions.RESPONSES_2XX, "read", 1L); - assertStatisticsEntry(stats, "http", "GET", MetricDefinitions.RESPONSES_4XX, "read", 1L); - assertStatisticsEntry(stats, "http", "PUT", MetricDefinitions.RESPONSES_2XX, "write", 1L); - assertStatisticsEntry(stats, "http", "POST", MetricDefinitions.RESPONSES_2XX, "write", 2L); - assertStatisticsEntry(stats, "https", "GET", MetricDefinitions.RESPONSES_4XX, "read", 1L); - assertStatisticsEntry(stats, "https", "POST", MetricDefinitions.RESPONSES_2XX, "write", 4L); + assertStatisticsEntry(stats, "http", "GET", MetricDefinitions.RESPONSES_2XX, "read", 200, 1L); + assertStatisticsEntry(stats, "http", "GET", MetricDefinitions.RESPONSES_4XX, "read", 404, 1L); + assertStatisticsEntry(stats, "http", "PUT", MetricDefinitions.RESPONSES_2XX, "write", 200, 1L); + assertStatisticsEntry(stats, "http", "POST", MetricDefinitions.RESPONSES_2XX, "write", 200, 2L); + assertStatisticsEntry(stats, "https", "GET", MetricDefinitions.RESPONSES_4XX, "read", 404, 1L); + assertStatisticsEntry(stats, "https", "POST", MetricDefinitions.RESPONSES_2XX, "write", 200, 4L); } @Test @@ -80,9 +82,11 @@ public class HttpResponseStatisticsCollectorTest { testRequest("http", 403, "GET"); var stats = collector.takeStatistics(); - assertStatisticsEntry(stats, "http", "GET", MetricDefinitions.RESPONSES_4XX, "read", 3L); - assertStatisticsEntry(stats, "http", "GET", MetricDefinitions.RESPONSES_401, "read", 1L); - assertStatisticsEntry(stats, "http", "GET", MetricDefinitions.RESPONSES_403, "read", 1L); + assertStatisticsEntry(stats, "http", "GET", MetricDefinitions.RESPONSES_4XX, "read", 401, 1L); + assertStatisticsEntry(stats, "http", "GET", MetricDefinitions.RESPONSES_4XX, "read", 403, 1L); + assertStatisticsEntry(stats, "http", "GET", MetricDefinitions.RESPONSES_4XX, "read", 404, 1L); + assertStatisticsEntry(stats, "http", "GET", MetricDefinitions.RESPONSES_401, "read", 401, 1L); + assertStatisticsEntry(stats, "http", "GET", MetricDefinitions.RESPONSES_403, "read", 403, 1L); } @@ -92,12 +96,12 @@ public class HttpResponseStatisticsCollectorTest { testRequest("http", 200, "GET"); var stats = collector.takeStatistics(); - assertStatisticsEntry(stats, "http", "GET", MetricDefinitions.RESPONSES_2XX, "read", 2L); + assertStatisticsEntry(stats, "http", "GET", MetricDefinitions.RESPONSES_2XX, "read", 200, 2L); testRequest("http", 200, "GET"); stats = collector.takeStatistics(); - assertStatisticsEntry(stats, "http", "GET", MetricDefinitions.RESPONSES_2XX, "read", 1L); + assertStatisticsEntry(stats, "http", "GET", MetricDefinitions.RESPONSES_2XX, "read", 200, 1L); } @Test @@ -108,15 +112,15 @@ public class HttpResponseStatisticsCollectorTest { testRequest("http", 200, "GET", "/status.html?foo=bar"); var stats = collector.takeStatistics(); - assertStatisticsEntry(stats, "http", "GET", MetricDefinitions.RESPONSES_2XX, "monitoring", 1L); - assertStatisticsEntry(stats, "http", "GET", MetricDefinitions.RESPONSES_2XX, "read", 1L); - assertStatisticsEntry(stats, "http", "POST", MetricDefinitions.RESPONSES_2XX, "read", 1L); - assertStatisticsEntry(stats, "http", "POST", MetricDefinitions.RESPONSES_2XX, "write", 1L); + assertStatisticsEntry(stats, "http", "GET", MetricDefinitions.RESPONSES_2XX, "monitoring", 200, 1L); + assertStatisticsEntry(stats, "http", "GET", MetricDefinitions.RESPONSES_2XX, "read", 200, 1L); + assertStatisticsEntry(stats, "http", "POST", MetricDefinitions.RESPONSES_2XX, "read", 200, 1L); + assertStatisticsEntry(stats, "http", "POST", MetricDefinitions.RESPONSES_2XX, "write", 200, 1L); testRequest("http", 200, "GET"); stats = collector.takeStatistics(); - assertStatisticsEntry(stats, "http", "GET", MetricDefinitions.RESPONSES_2XX, "read", 1L); + assertStatisticsEntry(stats, "http", "GET", MetricDefinitions.RESPONSES_2XX, "read", 200, 1L); } @Test @@ -124,7 +128,7 @@ public class HttpResponseStatisticsCollectorTest { testRequest("http", 200, "GET", "/search", com.yahoo.jdisc.Request.RequestType.WRITE); var stats = collector.takeStatistics(); - assertStatisticsEntry(stats, "http", "GET", MetricDefinitions.RESPONSES_2XX, "write", 1L); + assertStatisticsEntry(stats, "http", "GET", MetricDefinitions.RESPONSES_2XX, "write", 200, 1L); } @Before @@ -172,12 +176,14 @@ public class HttpResponseStatisticsCollectorTest { return req; } - private static void assertStatisticsEntry(List result, String scheme, String method, String name, String requestType, long expectedValue) { + private static void assertStatisticsEntry(List result, String scheme, String method, String name, + String requestType, int statusCode, long expectedValue) { long value = result.stream() .filter(entry -> entry.dimensions.method.equals(method) && entry.dimensions.scheme.equals(scheme) && entry.name.equals(name) - && entry.dimensions.requestType.equals(requestType)) + && entry.dimensions.requestType.equals(requestType) + && entry.dimensions.statusCode == statusCode) .mapToLong(entry -> entry.value) .reduce(Long::sum) .orElseThrow(() -> new AssertionError(String.format("Not matching entry in result (scheme=%s, method=%s, name=%s, type=%s)", scheme, method, name, requestType))); -- cgit v1.2.3