diff --git a/smoke-tests/src/test/java/org/hypertrace/agent/smoketest/AbstractSmokeTest.java b/smoke-tests/src/test/java/org/hypertrace/agent/smoketest/AbstractSmokeTest.java index 671edf4a..19693b8b 100644 --- a/smoke-tests/src/test/java/org/hypertrace/agent/smoketest/AbstractSmokeTest.java +++ b/smoke-tests/src/test/java/org/hypertrace/agent/smoketest/AbstractSmokeTest.java @@ -249,36 +249,42 @@ protected boolean hasMetricNamed( // Checks if a metric with the given name contains the specified attribute protected boolean hasMetricWithAttribute( - String metricName, String attributeName, Collection metricRequests) { + String metricName, + String attributeName, + Collection metricRequests) { return metricRequests.stream() - .flatMap(metricRequest -> metricRequest.getResourceMetricsList().stream()) - .flatMap(resourceMetrics -> resourceMetrics.getScopeMetricsList().stream()) - .flatMap(scopeMetrics -> scopeMetrics.getMetricsList().stream()) - .filter(metric -> metric.getName().equals(metricName)) - .anyMatch(metric -> metricHasAttribute(metric, attributeName)); + .flatMap(metricRequest -> metricRequest.getResourceMetricsList().stream()) + .flatMap(resourceMetrics -> resourceMetrics.getScopeMetricsList().stream()) + .flatMap(scopeMetrics -> scopeMetrics.getMetricsList().stream()) + .filter(metric -> metric.getName().equals(metricName)) + .anyMatch(metric -> metricHasAttribute(metric, attributeName)); } private boolean metricHasAttribute(Metric metric, String attributeName) { switch (metric.getDataCase()) { case GAUGE: - return metric.getGauge().getDataPointsList().stream().anyMatch(dataPoint -> hasAttribute(dataPoint.getAttributesList(), attributeName)); + return metric.getGauge().getDataPointsList().stream() + .anyMatch(dataPoint -> hasAttribute(dataPoint.getAttributesList(), attributeName)); case SUM: - return metric.getSum().getDataPointsList().stream().anyMatch(dataPoint -> hasAttribute(dataPoint.getAttributesList(), attributeName)); + return metric.getSum().getDataPointsList().stream() + .anyMatch(dataPoint -> hasAttribute(dataPoint.getAttributesList(), attributeName)); case HISTOGRAM: - return metric.getHistogram().getDataPointsList().stream().anyMatch(dataPoint -> hasAttribute(dataPoint.getAttributesList(), attributeName)); + return metric.getHistogram().getDataPointsList().stream() + .anyMatch(dataPoint -> hasAttribute(dataPoint.getAttributesList(), attributeName)); case EXPONENTIAL_HISTOGRAM: - return metric.getExponentialHistogram().getDataPointsList().stream().anyMatch(dataPoint -> hasAttribute(dataPoint.getAttributesList(), attributeName)); + return metric.getExponentialHistogram().getDataPointsList().stream() + .anyMatch(dataPoint -> hasAttribute(dataPoint.getAttributesList(), attributeName)); case SUMMARY: - return metric.getSummary().getDataPointsList().stream().anyMatch(dataPoint -> hasAttribute(dataPoint.getAttributesList(), attributeName)); + return metric.getSummary().getDataPointsList().stream() + .anyMatch(dataPoint -> hasAttribute(dataPoint.getAttributesList(), attributeName)); default: return false; } } private boolean hasAttribute(List attributes, String attributeName) { - return attributes.stream() - .anyMatch(attribute -> attribute.getKey().equals(attributeName)); + return attributes.stream().anyMatch(attribute -> attribute.getKey().equals(attributeName)); } public static String getPropertyOrEnv(String propName) { diff --git a/smoke-tests/src/test/java/org/hypertrace/agent/smoketest/SpringBootSmokeTest.java b/smoke-tests/src/test/java/org/hypertrace/agent/smoketest/SpringBootSmokeTest.java index c462864b..dc76f878 100644 --- a/smoke-tests/src/test/java/org/hypertrace/agent/smoketest/SpringBootSmokeTest.java +++ b/smoke-tests/src/test/java/org/hypertrace/agent/smoketest/SpringBootSmokeTest.java @@ -177,9 +177,12 @@ public void postJson() throws IOException, InterruptedException { Assertions.assertTrue(hasMetricWithAttribute("http.server.duration", "http.method", metrics)); Assertions.assertTrue(hasMetricWithAttribute("http.server.duration", "http.route", metrics)); - Assertions.assertFalse(hasMetricWithAttribute("http.server.duration", "net.sock.peer.addr", metrics)); - Assertions.assertFalse(hasMetricWithAttribute("http.server.duration", "http.request_content_length", metrics)); - Assertions.assertFalse(hasMetricWithAttribute("http.server.duration", "http.response_content_length", metrics)); + Assertions.assertFalse( + hasMetricWithAttribute("http.server.duration", "net.sock.peer.addr", metrics)); + Assertions.assertFalse( + hasMetricWithAttribute("http.server.duration", "http.request_content_length", metrics)); + Assertions.assertFalse( + hasMetricWithAttribute("http.server.duration", "http.response_content_length", metrics)); } @Test