diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/noop/NoOpMetricsSystem.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/noop/NoOpMetricsSystem.java index 870c2ab92df..0f0745fcbfa 100644 --- a/metrics/core/src/main/java/org/hyperledger/besu/metrics/noop/NoOpMetricsSystem.java +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/noop/NoOpMetricsSystem.java @@ -17,11 +17,11 @@ import org.hyperledger.besu.metrics.ObservableMetricsSystem; import org.hyperledger.besu.metrics.Observation; import org.hyperledger.besu.plugin.services.metrics.Counter; +import org.hyperledger.besu.plugin.services.metrics.Histogram; import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; import org.hyperledger.besu.plugin.services.metrics.MetricCategory; import org.hyperledger.besu.plugin.services.metrics.OperationTimer; -import org.hyperledger.besu.plugin.services.metrics.Summary; import java.util.ArrayList; import java.util.Collections; @@ -46,7 +46,8 @@ public class NoOpMetricsSystem implements ObservableMetricsSystem { /** The constant NO_OP_OPERATION_TIMER. */ public static final OperationTimer NO_OP_OPERATION_TIMER = () -> NO_OP_TIMING_CONTEXT; - public static final Summary NO_OP_SUMMARY = d -> {}; + /** The constant NO_OP_HISTOGRAM. */ + public static final Histogram NO_OP_HISTOGRAM = d -> {}; /** The constant NO_OP_LABELLED_1_COUNTER. */ public static final LabelledMetric NO_OP_LABELLED_1_COUNTER = @@ -64,8 +65,9 @@ public class NoOpMetricsSystem implements ObservableMetricsSystem { public static final LabelledMetric NO_OP_LABELLED_1_OPERATION_TIMER = new LabelCountingNoOpMetric<>(1, NO_OP_OPERATION_TIMER); - public static final LabelledMetric NO_OP_LABELLED_1_SUMMARY = - new LabelCountingNoOpMetric<>(1, NO_OP_SUMMARY); + /** The constant NO_OP_LABELLED_1_HISTOGRAM. */ + public static final LabelledMetric NO_OP_LABELLED_1_HISTOGRAM = + new LabelCountingNoOpMetric<>(1, NO_OP_HISTOGRAM); /** The constant NO_OP_LABELLED_1_GAUGE. */ public static final LabelledGauge NO_OP_LABELLED_1_GAUGE = @@ -149,11 +151,11 @@ public static LabelledMetric getOperationTimerLabelledMetric( * @param labelCount the label count * @return the operation timer labelled metric */ - public static LabelledMetric getSummaryLabelledMetric(final int labelCount) { + public static LabelledMetric getSummaryLabelledMetric(final int labelCount) { if (labelCount == 1) { - return NO_OP_LABELLED_1_SUMMARY; + return NO_OP_LABELLED_1_HISTOGRAM; } else { - return new LabelCountingNoOpMetric<>(labelCount, NO_OP_SUMMARY); + return new LabelCountingNoOpMetric<>(labelCount, NO_OP_HISTOGRAM); } } @@ -165,10 +167,11 @@ public void createGauge( final DoubleSupplier valueSupplier) {} @Override - public LabelledMetric createLabelledSummary( + public LabelledMetric createLabelledHistogram( final MetricCategory category, final String name, final String help, + final double[] buckets, final String... labelNames) { return null; } diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetrySystem.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetrySystem.java index 75457884fa3..e12edbc5e53 100644 --- a/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetrySystem.java +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/OpenTelemetrySystem.java @@ -20,11 +20,11 @@ import org.hyperledger.besu.metrics.StandardMetricCategory; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; +import org.hyperledger.besu.plugin.services.metrics.Histogram; import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; import org.hyperledger.besu.plugin.services.metrics.MetricCategory; import org.hyperledger.besu.plugin.services.metrics.OperationTimer; -import org.hyperledger.besu.plugin.services.metrics.Summary; import java.lang.management.GarbageCollectorMXBean; import java.lang.management.ManagementFactory; @@ -279,10 +279,11 @@ public void createGauge( } @Override - public LabelledMetric createLabelledSummary( + public LabelledMetric createLabelledHistogram( final MetricCategory category, final String name, final String help, + final double[] buckets, final String... labelNames) { return null; } diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusSummary.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusHistogram.java similarity index 59% rename from metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusSummary.java rename to metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusHistogram.java index 7f439c0f118..825f967a64d 100644 --- a/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusSummary.java +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusHistogram.java @@ -14,26 +14,26 @@ */ package org.hyperledger.besu.metrics.prometheus; +import org.hyperledger.besu.plugin.services.metrics.Histogram; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; -import org.hyperledger.besu.plugin.services.metrics.Summary; -class PrometheusSummary implements LabelledMetric { +class PrometheusHistogram implements LabelledMetric { - private final io.prometheus.client.Summary summary; + private final io.prometheus.client.Histogram histogram; - public PrometheusSummary(final io.prometheus.client.Summary summary) { - this.summary = summary; + public PrometheusHistogram(final io.prometheus.client.Histogram histogram) { + this.histogram = histogram; } @Override - public Summary labels(final String... labels) { - return new UnlabelledSummary(summary.labels(labels)); + public Histogram labels(final String... labels) { + return new UnlabelledHistogram(histogram.labels(labels)); } - private static class UnlabelledSummary implements Summary { - private final io.prometheus.client.Summary.Child amount; + private static class UnlabelledHistogram implements Histogram { + private final io.prometheus.client.Histogram.Child amount; - private UnlabelledSummary(final io.prometheus.client.Summary.Child amount) { + private UnlabelledHistogram(final io.prometheus.client.Histogram.Child amount) { this.amount = amount; } diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusMetricsSystem.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusMetricsSystem.java index aa1b80348ac..6ff6555f550 100644 --- a/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusMetricsSystem.java +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusMetricsSystem.java @@ -59,8 +59,8 @@ public class PrometheusMetricsSystem implements ObservableMetricsSystem { cachedCounters = new ConcurrentHashMap<>(); private final Map> cachedTimers = new ConcurrentHashMap<>(); - private final Map> - cachedSummaries = new ConcurrentHashMap<>(); + private final Map> + cachedHistograms = new ConcurrentHashMap<>(); private final Set totalSuffixedCounters = new ConcurrentHashSet<>(); private final Set enabledCategories; @@ -114,31 +114,22 @@ public LabelledMetric crea } @Override - public LabelledMetric createLabelledSummary( - final MetricCategory category, - final String name, - final String help, - final String... labelNames) { + public LabelledMetric + createLabelledHistogram( + final MetricCategory category, + final String name, + final String help, + final double[] buckets, + final String... labelNames) { final String metricName = convertToPrometheusName(category, name); - return cachedSummaries.computeIfAbsent( + return cachedHistograms.computeIfAbsent( metricName, k -> { if (isCategoryEnabled(category)) { - final Summary summary = - Summary.build(metricName, help) - .quantile(0.0, 0) - .quantile(0.2, 0.02) - .quantile(0.5, 0.05) - .quantile(0.8, 0.02) - .quantile(0.95, 0.005) - .quantile(0.99, 0.001) - .quantile(1.0, 0) - .labelNames(labelNames) - .ageBuckets(5) - .maxAgeSeconds(2) - .create(); - addCollectorUnchecked(category, summary); - return new PrometheusSummary(summary); + final Histogram histogram = + Histogram.build(metricName, help).labelNames(labelNames).buckets(buckets).create(); + addCollectorUnchecked(category, histogram); + return new PrometheusHistogram(histogram); } else { return NoOpMetricsSystem.getSummaryLabelledMetric(labelNames.length); } diff --git a/metrics/core/src/test-support/java/org/hyperledger/besu/metrics/StubMetricsSystem.java b/metrics/core/src/test-support/java/org/hyperledger/besu/metrics/StubMetricsSystem.java index 0ac6cbfa1e6..3794481f6a5 100644 --- a/metrics/core/src/test-support/java/org/hyperledger/besu/metrics/StubMetricsSystem.java +++ b/metrics/core/src/test-support/java/org/hyperledger/besu/metrics/StubMetricsSystem.java @@ -18,11 +18,11 @@ import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; +import org.hyperledger.besu.plugin.services.metrics.Histogram; import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; import org.hyperledger.besu.plugin.services.metrics.MetricCategory; import org.hyperledger.besu.plugin.services.metrics.OperationTimer; -import org.hyperledger.besu.plugin.services.metrics.Summary; import java.util.Collections; import java.util.HashMap; @@ -95,7 +95,7 @@ public void createGauge( } @Override - public LabelledMetric createLabelledSummary( + public LabelledMetric createLabelledSummary( final MetricCategory category, final String name, final String help, diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index 24a57773fa2..47e4d658b93 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -71,7 +71,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = '1VIGlJuGiaEVUksIjTTHDt7SIjjJE9+DU8rYk/ze3XM=' + knownHash = 'y0LCW10NiQfggaDirEwo8x9DlfbvN21dPajj+pqBy7Q=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/MetricsSystem.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/MetricsSystem.java index bf6505476f6..de2477d3924 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/MetricsSystem.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/MetricsSystem.java @@ -15,11 +15,11 @@ package org.hyperledger.besu.plugin.services; import org.hyperledger.besu.plugin.services.metrics.Counter; +import org.hyperledger.besu.plugin.services.metrics.Histogram; import org.hyperledger.besu.plugin.services.metrics.LabelledGauge; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; import org.hyperledger.besu.plugin.services.metrics.MetricCategory; import org.hyperledger.besu.plugin.services.metrics.OperationTimer; -import org.hyperledger.besu.plugin.services.metrics.Summary; import java.util.function.DoubleSupplier; import java.util.function.IntSupplier; @@ -161,6 +161,6 @@ default void createLongGauge( createGauge(category, name, help, () -> (double) valueSupplier.getAsLong()); } - LabelledMetric createLabelledSummary( - MetricCategory category, String name, String help, String... labelNames); + LabelledMetric createLabelledHistogram( + MetricCategory category, String name, String help, double[] buckets, String... labelNames); } diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/Summary.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/Histogram.java similarity index 96% rename from plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/Summary.java rename to plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/Histogram.java index 774d01be276..b52b280106a 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/Summary.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/metrics/Histogram.java @@ -14,7 +14,7 @@ */ package org.hyperledger.besu.plugin.services.metrics; -public interface Summary { +public interface Histogram { void observe(double amount); }