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

Log the hbase attributes for one failing data point #1610

Closed
Show file tree
Hide file tree
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 @@ -15,6 +15,7 @@
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import org.assertj.core.api.AbstractAssert;
import org.assertj.core.internal.Integers;
Expand Down Expand Up @@ -178,6 +179,17 @@ public MetricAssert hasDataPointsWithoutAttributes() {
private MetricAssert checkDataPoints(Consumer<List<NumberDataPoint>> listConsumer) {
// in practice usually one set of data points is provided but the
// protobuf does not enforce that, so we have to ensure checking at least one
int count = consumeNumberDataPoints(listConsumer);
info.description("at least one set of data points expected for metric '%s'", actual.getName());
integers.assertGreaterThan(info, count, 0);

strictCheck(
"data point attributes", /* expectedCheckStatus= */ false, dataPointAttributesChecked);
dataPointAttributesChecked = true;
return this;
}

private int consumeNumberDataPoints(Consumer<List<NumberDataPoint>> listConsumer) {
int count = 0;
if (actual.hasGauge()) {
count++;
Expand All @@ -187,13 +199,7 @@ private MetricAssert checkDataPoints(Consumer<List<NumberDataPoint>> listConsume
count++;
listConsumer.accept(actual.getSum().getDataPointsList());
}
info.description("at least one set of data points expected for metric '%s'", actual.getName());
integers.assertGreaterThan(info, count, 0);

strictCheck(
"data point attributes", /* expectedCheckStatus= */ false, dataPointAttributesChecked);
dataPointAttributesChecked = true;
return this;
return count;
}

private void dataPointsCommonCheck(List<NumberDataPoint> dataPoints) {
Expand Down Expand Up @@ -263,4 +269,35 @@ public final MetricAssert hasDataPointsWithAttributes(AttributeMatcherGroup... m
}
});
}

/**
* Call this to have the metric data points for this metric name get logged. Care should be used,
* because it might be verbose. Can be used for sporadic/occasional test failures.
*
* @return this
*/
@CanIgnoreReturnValue
public MetricAssert logAttributes() {
Logger logger = Logger.getLogger(getClass().getName());
consumeNumberDataPoints(
points ->
points.forEach(
point -> {
StringBuilder sb = new StringBuilder(actual.getName() + " -> attrs = [");
List<String> attrStrings =
point.getAttributesList().stream()
.map(
kv ->
("{"
+ kv.getKey()
+ "=> "
+ String.valueOf(kv.getValue()).trim()
+ "}"))
.collect(Collectors.toList());
sb.append(String.join(",", attrStrings));
sb.append("]");
logger.info(sb.toString());
}));
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ protected MetricsVerifier createMetricsVerifier() {
"hbase.region_server.queue.length",
metric ->
metric
.logAttributes()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something that should be done automatically. Maybe just call it inside hasDataPointsWithAttributes() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, this design assumed that you'd only want to turn this on in specific cases for certain metrics or whatever. Doing this automatically for every metric assertion would be too verbose.

.isUpDownCounter()
.hasDescription("The number of RPC handlers actively servicing requests.")
.hasUnit("{handler}")
Expand Down
Loading