Skip to content

Commit 902a0c3

Browse files
committed
Log the hbase attributes for one failing data point
1 parent 3a16d30 commit 902a0c3

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

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

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.List;
1616
import java.util.Map;
1717
import java.util.function.Consumer;
18+
import java.util.logging.Logger;
1819
import java.util.stream.Collectors;
1920
import org.assertj.core.api.AbstractAssert;
2021
import org.assertj.core.internal.Integers;
@@ -178,6 +179,17 @@ public MetricAssert hasDataPointsWithoutAttributes() {
178179
private MetricAssert checkDataPoints(Consumer<List<NumberDataPoint>> listConsumer) {
179180
// in practice usually one set of data points is provided but the
180181
// protobuf does not enforce that, so we have to ensure checking at least one
182+
int count = consumeNumberDataPoints(listConsumer);
183+
info.description("at least one set of data points expected for metric '%s'", actual.getName());
184+
integers.assertGreaterThan(info, count, 0);
185+
186+
strictCheck(
187+
"data point attributes", /* expectedCheckStatus= */ false, dataPointAttributesChecked);
188+
dataPointAttributesChecked = true;
189+
return this;
190+
}
191+
192+
private int consumeNumberDataPoints(Consumer<List<NumberDataPoint>> listConsumer) {
181193
int count = 0;
182194
if (actual.hasGauge()) {
183195
count++;
@@ -187,13 +199,7 @@ private MetricAssert checkDataPoints(Consumer<List<NumberDataPoint>> listConsume
187199
count++;
188200
listConsumer.accept(actual.getSum().getDataPointsList());
189201
}
190-
info.description("at least one set of data points expected for metric '%s'", actual.getName());
191-
integers.assertGreaterThan(info, count, 0);
192-
193-
strictCheck(
194-
"data point attributes", /* expectedCheckStatus= */ false, dataPointAttributesChecked);
195-
dataPointAttributesChecked = true;
196-
return this;
202+
return count;
197203
}
198204

199205
private void dataPointsCommonCheck(List<NumberDataPoint> dataPoints) {
@@ -263,4 +269,35 @@ public final MetricAssert hasDataPointsWithAttributes(AttributeMatcherGroup... m
263269
}
264270
});
265271
}
272+
273+
/**
274+
* Call this to have the metric data points for this metric name get logged. Care should be used,
275+
* because it might be verbose. Can be used for sporadic/occasional test failures.
276+
*
277+
* @return this
278+
*/
279+
@CanIgnoreReturnValue
280+
public MetricAssert logAttributes() {
281+
Logger logger = Logger.getLogger(getClass().getName());
282+
consumeNumberDataPoints(
283+
points ->
284+
points.forEach(
285+
point -> {
286+
StringBuilder sb = new StringBuilder(actual.getName() + " -> attrs = [");
287+
List<String> attrStrings =
288+
point.getAttributesList().stream()
289+
.map(
290+
kv ->
291+
("{"
292+
+ kv.getKey()
293+
+ "=> "
294+
+ String.valueOf(kv.getValue()).trim()
295+
+ "}"))
296+
.collect(Collectors.toList());
297+
sb.append(String.join(",", attrStrings));
298+
sb.append("]");
299+
logger.info(sb.toString());
300+
}));
301+
return this;
302+
}
266303
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ protected MetricsVerifier createMetricsVerifier() {
120120
"hbase.region_server.queue.length",
121121
metric ->
122122
metric
123+
.logAttributes()
123124
.isUpDownCounter()
124125
.hasDescription("The number of RPC handlers actively servicing requests.")
125126
.hasUnit("{handler}")

0 commit comments

Comments
 (0)