use of org.hyperledger.besu.metrics.Observation 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.metrics.Observation in project besu by hyperledger.
the class PrometheusMetricsSystemTest method shouldOnlyObserveEnabledMetrics.
@Test
public void shouldOnlyObserveEnabledMetrics() {
final MetricsConfiguration metricsConfiguration = MetricsConfiguration.builder().metricCategories(ImmutableSet.of(BesuMetricCategory.RPC)).enabled(true).build();
final ObservableMetricsSystem localMetricSystem = MetricsSystemFactory.create(metricsConfiguration);
// do a category we are not watching
final LabelledMetric<Counter> counterN = localMetricSystem.createLabelledCounter(NETWORK, "ABC", "Not that kind of network", "show");
assertThat(counterN).isSameAs(NoOpMetricsSystem.NO_OP_LABELLED_1_COUNTER);
counterN.labels("show").inc();
assertThat(localMetricSystem.streamObservations()).isEmpty();
// do a category we are watching
final LabelledMetric<Counter> counterR = localMetricSystem.createLabelledCounter(RPC, "name", "Not useful", "method");
assertThat(counterR).isNotSameAs(NoOpMetricsSystem.NO_OP_LABELLED_1_COUNTER);
counterR.labels("op").inc();
assertThat(localMetricSystem.streamObservations()).containsExactly(new Observation(RPC, "name", 1.0, singletonList("op")));
}
use of org.hyperledger.besu.metrics.Observation 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")));
}
use of org.hyperledger.besu.metrics.Observation in project besu by hyperledger.
the class OpenTelemetrySystem method convertToObservations.
private Stream<Observation> convertToObservations(final MetricData metricData) {
List<Observation> observations = new ArrayList<>();
MetricCategory category = categoryNameToMetricCategory(metricData.getInstrumentationLibraryInfo().getName());
Collection<?> points;
switch(metricData.getType()) {
case DOUBLE_GAUGE:
points = metricData.getDoubleGaugeData().getPoints();
break;
case DOUBLE_SUM:
points = metricData.getDoubleSumData().getPoints();
break;
case SUMMARY:
points = metricData.getDoubleSummaryData().getPoints();
break;
case LONG_SUM:
points = metricData.getLongSumData().getPoints();
break;
case HISTOGRAM:
points = metricData.getDoubleHistogramData().getPoints();
break;
case LONG_GAUGE:
points = metricData.getLongGaugeData().getPoints();
break;
default:
throw new UnsupportedOperationException("Unsupported type " + metricData.getType().name());
}
for (Object ptObj : points) {
PointData point = (PointData) ptObj;
List<String> labels = new ArrayList<>();
point.getAttributes().forEach((k, v) -> labels.add(v.toString()));
observations.add(new Observation(category, metricData.getName(), extractValue(metricData.getType(), point), labels));
}
return observations.stream();
}
use of org.hyperledger.besu.metrics.Observation in project besu by hyperledger.
the class OpenTelemetryMetricsSystemTest method shouldCreateSeparateObservationsForEachCounterLabelValue.
@Test
public void shouldCreateSeparateObservationsForEachCounterLabelValue() {
final LabelledMetric<Counter> counter = metricsSystem.createLabelledCounter(PEERS, "connected", "Some help string", "labelName");
counter.labels("value1").inc();
counter.labels("value2").inc();
counter.labels("value1").inc();
assertThat(metricsSystem.streamObservations()).containsExactlyInAnyOrder(new Observation(PEERS, "connected", 2L, singletonList("value1")), new Observation(PEERS, "connected", 1L, singletonList("value2")));
}
Aggregations