Skip to content

Commit

Permalink
spotless apply
Browse files Browse the repository at this point in the history
  • Loading branch information
thugrock7 committed Sep 3, 2024
1 parent 637d83f commit 71e4c78
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExportMetricsServiceRequest> metricRequests) {
String metricName,
String attributeName,
Collection<ExportMetricsServiceRequest> 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<KeyValue> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 71e4c78

Please sign in to comment.