Search in sources :

Example 1 with OperationTimer

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");
}
Also used : MockExecutorService(org.hyperledger.besu.testutil.MockExecutorService) Arrays(java.util.Arrays) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) LabelledMetric(org.hyperledger.besu.plugin.services.metrics.LabelledMetric) Mockito.verify(org.mockito.Mockito.verify) List(java.util.List) Lists(com.google.common.collect.Lists) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MetricsSystem(org.hyperledger.besu.plugin.services.MetricsSystem) MetricCategory(org.hyperledger.besu.plugin.services.metrics.MetricCategory) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) OperationTimer(org.hyperledger.besu.plugin.services.metrics.OperationTimer) OperationTimer(org.hyperledger.besu.plugin.services.metrics.OperationTimer) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) MetricsSystem(org.hyperledger.besu.plugin.services.MetricsSystem) MetricCategory(org.hyperledger.besu.plugin.services.metrics.MetricCategory) Test(org.junit.Test)

Example 2 with OperationTimer

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")));
}
Also used : OperationTimer(org.hyperledger.besu.plugin.services.metrics.OperationTimer) Observation(org.hyperledger.besu.metrics.Observation) Test(org.junit.Test)

Example 3 with OperationTimer

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()));
}
Also used : OperationTimer(org.hyperledger.besu.plugin.services.metrics.OperationTimer) Observation(org.hyperledger.besu.metrics.Observation) Test(org.junit.Test)

Example 4 with OperationTimer

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")));
}
Also used : OperationTimer(org.hyperledger.besu.plugin.services.metrics.OperationTimer) Observation(org.hyperledger.besu.metrics.Observation) Test(org.junit.Test)

Example 5 with OperationTimer

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")));
}
Also used : OperationTimer(org.hyperledger.besu.plugin.services.metrics.OperationTimer) Observation(org.hyperledger.besu.metrics.Observation) Test(org.junit.Test)

Aggregations

OperationTimer (org.hyperledger.besu.plugin.services.metrics.OperationTimer)9 Test (org.junit.Test)7 Observation (org.hyperledger.besu.metrics.Observation)4 ObservableMetricsSystem (org.hyperledger.besu.metrics.ObservableMetricsSystem)2 PrometheusMetricsSystem (org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem)2 Counter (org.hyperledger.besu.plugin.services.metrics.Counter)2 RocksDBException (org.rocksdb.RocksDBException)2 Lists (com.google.common.collect.Lists)1 Arrays (java.util.Arrays)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 NoOpMetricsSystem (org.hyperledger.besu.metrics.noop.NoOpMetricsSystem)1 MetricsSystem (org.hyperledger.besu.plugin.services.MetricsSystem)1 LabelledMetric (org.hyperledger.besu.plugin.services.metrics.LabelledMetric)1 MetricCategory (org.hyperledger.besu.plugin.services.metrics.MetricCategory)1 MockExecutorService (org.hyperledger.besu.testutil.MockExecutorService)1 RunWith (org.junit.runner.RunWith)1