Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

condense iterations and streams #160

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import io.opentelemetry.api.metrics.DoubleCounter;
import io.opentelemetry.api.metrics.Meter;
import io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider;
import io.opentelemetry.sdk.metrics.data.DoublePointData;
import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.metrics.data.MetricDataType;
import jakarta.inject.Inject;
Expand All @@ -52,6 +51,9 @@ public class DoubleCounterTest extends Arquillian {
private static final String counterDescription = "Testing double counter";
private static final String counterUnit = "Metric Tonnes";

private static final double DOUBLE_WITH_ATTRIBUTES = 20.2;
private static final double DOUBLE_WITHOUT_ATTRIBUTES = 10.1;

@Deployment
public static WebArchive createTestArchive() {

Expand Down Expand Up @@ -89,28 +91,19 @@ void testDoubleCounter() throws InterruptedException {
.build();
Assert.assertNotNull(doubleCounter);

doubleCounter.add(20.2, Attributes.builder().put("K", "V").build());
doubleCounter.add(10.1, Attributes.empty());
doubleCounter.add(DOUBLE_WITH_ATTRIBUTES, Attributes.builder().put("K", "V").build());
doubleCounter.add(DOUBLE_WITHOUT_ATTRIBUTES, Attributes.empty());
List<MetricData> metrics = metricExporter.getMetricData((MetricDataType.DOUBLE_SUM));
Double value = 0.0;
Double valueWithoutAttributes = 0.0;
MetricData metric = metrics.get(0);

valueWithoutAttributes = metric.getDoubleSumData().getPoints().stream()
.filter(point -> point.getAttributes() == Attributes.empty())
.mapToDouble(DoublePointData::getValue)
.findFirst()
.getAsDouble();

value = metric.getDoubleSumData().getPoints().stream()
.filter(point -> ("V").equals(point.getAttributes().get(stringKey("K"))))
.mapToDouble(DoublePointData::getValue)
.findFirst()
.getAsDouble();

Assert.assertEquals(value, 20.2);
boolean result = metrics
.stream()
.flatMap(metricData -> metricData.getDoubleSumData().getPoints().stream())
.allMatch(point -> (point.getValue() == DOUBLE_WITHOUT_ATTRIBUTES
&& point.getAttributes() == Attributes.empty())
|| (point.getValue() == DOUBLE_WITH_ATTRIBUTES
&& point.getAttributes().get(stringKey("K")).equals("V")));

Assert.assertEquals(valueWithoutAttributes, 10.1);
Assert.assertTrue(result);
}

}