use of org.hyperledger.besu.plugin.services.metrics.OperationTimer in project besu by hyperledger.
the class AbstractEthTaskTest method shouldHaveSpecificMetricsLabels.
@Test
public void shouldHaveSpecificMetricsLabels() {
// seed with a failing value so that a no-op also trips the failure.
final String[] lastLabelNames = { "AbstractEthTask" };
final MetricsSystem instrumentedLabeler = new NoOpMetricsSystem() {
@Override
public LabelledMetric<OperationTimer> createLabelledTimer(final MetricCategory category, final String name, final String help, final String... labelNames) {
return names -> {
lastLabelNames[0] = names[0];
return null;
};
}
};
new AbstractEthTask<>(instrumentedLabeler) {
@Override
protected void executeTask() {
// no-op
}
};
assertThat(lastLabelNames[0]).isNotEqualTo("AbstractEthTask");
}
use of org.hyperledger.besu.plugin.services.metrics.OperationTimer in project besu by hyperledger.
the class OpenTelemetryMetricsSystemTest method shouldCreateObservationsFromTimerWithLabels.
@Test
public void shouldCreateObservationsFromTimerWithLabels() {
final LabelledMetric<OperationTimer> timer = metricsSystem.createLabelledTimer(RPC, "request", "Some help", "methodName");
// noinspection EmptyTryBlock
try (final OperationTimer.TimingContext ignored = timer.labels("method").startTimer()) {
}
// noinspection EmptyTryBlock
try (final OperationTimer.TimingContext ignored = timer.labels("method").startTimer()) {
}
// noinspection EmptyTryBlock
try (final OperationTimer.TimingContext ignored = timer.labels("method").startTimer()) {
}
// noinspection EmptyTryBlock
try (final OperationTimer.TimingContext ignored = timer.labels("method").startTimer()) {
}
assertThat(metricsSystem.streamObservations()).usingElementComparator(// We don't know how long it will actually take.
IGNORE_VALUES).containsExactlyInAnyOrder(new Observation(RPC, "request", null, singletonList("method")));
}
use of org.hyperledger.besu.plugin.services.metrics.OperationTimer in project besu by hyperledger.
the class OpenTelemetryMetricsSystemTest method shouldCreateObservationsFromTimer.
@Test
public void shouldCreateObservationsFromTimer() {
final OperationTimer timer = metricsSystem.createTimer(RPC, "request", "Some help");
final OperationTimer.TimingContext context = timer.startTimer();
context.stopTimer();
assertThat(metricsSystem.streamObservations()).usingElementComparator(IGNORE_VALUES).containsExactlyInAnyOrder(new Observation(RPC, "request", null, Collections.emptyList()));
}
use of org.hyperledger.besu.plugin.services.metrics.OperationTimer in project besu by hyperledger.
the class PrometheusMetricsSystemTest method shouldCreateObservationsFromTimer.
@Test
public void shouldCreateObservationsFromTimer() {
final OperationTimer timer = metricsSystem.createTimer(RPC, "request", "Some help");
final OperationTimer.TimingContext context = timer.startTimer();
context.stopTimer();
assertThat(metricsSystem.streamObservations()).usingElementComparator(IGNORE_VALUES).containsExactlyInAnyOrder(new Observation(RPC, "request", null, asList("quantile", "0.2")), new Observation(RPC, "request", null, asList("quantile", "0.5")), new Observation(RPC, "request", null, asList("quantile", "0.8")), new Observation(RPC, "request", null, asList("quantile", "0.95")), new Observation(RPC, "request", null, asList("quantile", "0.99")), new Observation(RPC, "request", null, asList("quantile", "1.0")), new Observation(RPC, "request", null, singletonList("sum")), new Observation(RPC, "request", null, singletonList("count")));
}
use of org.hyperledger.besu.plugin.services.metrics.OperationTimer in project besu by hyperledger.
the class PrometheusMetricsSystemTest method shouldCreateObservationsFromTimerWithLabels.
@Test
public void shouldCreateObservationsFromTimerWithLabels() {
final LabelledMetric<OperationTimer> timer = metricsSystem.createLabelledTimer(RPC, "request", "Some help", "methodName");
// noinspection EmptyTryBlock
try (final OperationTimer.TimingContext ignored = timer.labels("method").startTimer()) {
}
assertThat(metricsSystem.streamObservations()).usingElementComparator(// We don't know how long it will actually take.
IGNORE_VALUES).containsExactlyInAnyOrder(new Observation(RPC, "request", null, asList("method", "quantile", "0.2")), new Observation(RPC, "request", null, asList("method", "quantile", "0.5")), new Observation(RPC, "request", null, asList("method", "quantile", "0.8")), new Observation(RPC, "request", null, asList("method", "quantile", "0.95")), new Observation(RPC, "request", null, asList("method", "quantile", "0.99")), new Observation(RPC, "request", null, asList("method", "quantile", "1.0")), new Observation(RPC, "request", null, asList("method", "sum")), new Observation(RPC, "request", null, asList("method", "count")));
}
Aggregations