Skip to content

Commit 11f4960

Browse files
committed
removed 'typed' attributes
1 parent 10e8994 commit 11f4960

File tree

2 files changed

+22
-39
lines changed

2 files changed

+22
-39
lines changed

jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/assertions/MetricAssert.java

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@
1212
import io.opentelemetry.proto.metrics.v1.Metric;
1313
import io.opentelemetry.proto.metrics.v1.NumberDataPoint;
1414
import java.util.Arrays;
15-
import java.util.Collection;
16-
import java.util.HashSet;
1715
import java.util.List;
1816
import java.util.Map;
19-
import java.util.Set;
2017
import java.util.function.Consumer;
2118
import java.util.stream.Collectors;
2219
import org.assertj.core.api.AbstractAssert;
@@ -199,31 +196,6 @@ private MetricAssert checkDataPoints(Consumer<List<NumberDataPoint>> listConsume
199196
return this;
200197
}
201198

202-
// TODO: To be removed and calls will be replaced with hasDataPointsWithAttributes()
203-
@CanIgnoreReturnValue
204-
public MetricAssert hasTypedDataPoints(Collection<String> types) {
205-
return checkDataPoints(
206-
dataPoints -> {
207-
dataPointsCommonCheck(dataPoints);
208-
209-
Set<String> foundValues = new HashSet<>();
210-
for (NumberDataPoint dataPoint : dataPoints) {
211-
List<KeyValue> attributes = dataPoint.getAttributesList();
212-
213-
info.description(
214-
"expected exactly one 'name' attribute for typed data point in metric '%s'",
215-
actual.getName());
216-
iterables.assertHasSize(info, attributes, 1);
217-
218-
objects.assertEqual(info, attributes.get(0).getKey(), "name");
219-
foundValues.add(attributes.get(0).getValue().getStringValue());
220-
}
221-
info.description(
222-
"missing or unexpected type attribute for metric '%s'", actual.getName());
223-
iterables.assertContainsExactlyInAnyOrder(info, foundValues, types.toArray());
224-
});
225-
}
226-
227199
private void dataPointsCommonCheck(List<NumberDataPoint> dataPoints) {
228200
info.description("unable to retrieve data points from metric '%s'", actual.getName());
229201
objects.assertNotNull(info, dataPoints);

jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JvmIntegrationTest.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55

66
package io.opentelemetry.contrib.jmxscraper.target_systems;
77

8+
import static io.opentelemetry.contrib.jmxscraper.assertions.DataPointAttributes.attribute;
9+
import static io.opentelemetry.contrib.jmxscraper.assertions.DataPointAttributes.attributeGroup;
10+
811
import io.opentelemetry.contrib.jmxscraper.JmxScraperContainer;
912
import io.opentelemetry.contrib.jmxscraper.TestAppContainer;
13+
import io.opentelemetry.contrib.jmxscraper.assertions.AttributeMatcherGroup;
1014
import java.nio.file.Path;
11-
import java.util.Arrays;
12-
import java.util.List;
1315
import org.testcontainers.containers.GenericContainer;
1416
import org.testcontainers.containers.wait.strategy.Wait;
1517

@@ -34,15 +36,16 @@ protected JmxScraperContainer customizeScraperContainer(
3436
@Override
3537
protected MetricsVerifier createMetricsVerifier() {
3638
// those values depend on the JVM GC configured
37-
List<String> gcLabels =
38-
Arrays.asList(
39+
AttributeMatcherGroup[] memoryAttributes =
40+
nameAttributeMatchers(
3941
"Code Cache",
4042
"PS Eden Space",
4143
"PS Old Gen",
4244
"Metaspace",
4345
"Compressed Class Space",
4446
"PS Survivor Space");
45-
List<String> gcCollectionLabels = Arrays.asList("PS MarkSweep", "PS Scavenge");
47+
AttributeMatcherGroup[] gcAlgorithmAttributes =
48+
nameAttributeMatchers("PS MarkSweep", "PS Scavenge");
4649

4750
return MetricsVerifier.create()
4851
.add(
@@ -60,7 +63,7 @@ protected MetricsVerifier createMetricsVerifier() {
6063
.hasDescription("total number of collections that have occurred")
6164
.hasUnit("1")
6265
.isCounter()
63-
.hasTypedDataPoints(gcCollectionLabels))
66+
.hasDataPointsWithAttributes(gcAlgorithmAttributes))
6467
.add(
6568
"jvm.gc.collections.elapsed",
6669
metric ->
@@ -69,7 +72,7 @@ protected MetricsVerifier createMetricsVerifier() {
6972
"the approximate accumulated collection elapsed time in milliseconds")
7073
.hasUnit("ms")
7174
.isCounter()
72-
.hasTypedDataPoints(gcCollectionLabels))
75+
.hasDataPointsWithAttributes(gcAlgorithmAttributes))
7376
.add(
7477
"jvm.memory.heap.committed",
7578
metric ->
@@ -141,31 +144,31 @@ protected MetricsVerifier createMetricsVerifier() {
141144
.hasDescription("current memory pool usage")
142145
.hasUnit("by")
143146
.isGauge()
144-
.hasTypedDataPoints(gcLabels))
147+
.hasDataPointsWithAttributes(memoryAttributes))
145148
.add(
146149
"jvm.memory.pool.init",
147150
metric ->
148151
metric
149152
.hasDescription("current memory pool usage")
150153
.hasUnit("by")
151154
.isGauge()
152-
.hasTypedDataPoints(gcLabels))
155+
.hasDataPointsWithAttributes(memoryAttributes))
153156
.add(
154157
"jvm.memory.pool.max",
155158
metric ->
156159
metric
157160
.hasDescription("current memory pool usage")
158161
.hasUnit("by")
159162
.isGauge()
160-
.hasTypedDataPoints(gcLabels))
163+
.hasDataPointsWithAttributes(memoryAttributes))
161164
.add(
162165
"jvm.memory.pool.used",
163166
metric ->
164167
metric
165168
.hasDescription("current memory pool usage")
166169
.hasUnit("by")
167170
.isGauge()
168-
.hasTypedDataPoints(gcLabels))
171+
.hasDataPointsWithAttributes(memoryAttributes))
169172
.add(
170173
"jvm.threads.count",
171174
metric ->
@@ -175,4 +178,12 @@ protected MetricsVerifier createMetricsVerifier() {
175178
.isGauge()
176179
.hasDataPointsWithoutAttributes());
177180
}
181+
182+
private static AttributeMatcherGroup[] nameAttributeMatchers(String... values) {
183+
AttributeMatcherGroup[] groups = new AttributeMatcherGroup[values.length];
184+
for (int i = 0; i < values.length; i++) {
185+
groups[i] = attributeGroup(attribute("name", values[i]));
186+
}
187+
return groups;
188+
}
178189
}

0 commit comments

Comments
 (0)