diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsOptionsTest.java index 39e77cbad7..f68a87643b 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsOptionsTest.java @@ -14,12 +14,18 @@ */ package org.hyperledger.besu.cli.options; +import static org.assertj.core.api.Assertions.assertThat; + import org.hyperledger.besu.metrics.BesuMetricCategory; import org.hyperledger.besu.metrics.MetricCategoryRegistryImpl; import org.hyperledger.besu.metrics.StandardMetricCategory; import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; +import java.util.EnumSet; +import java.util.stream.Collectors; + import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; @@ -64,4 +70,22 @@ public class MetricsOptionsTest protected String[] getNonOptionFields() { return new String[] {"metricCategoryRegistry"}; } + + @Test + public void enableRocksDbCategories() { + final var rocksDbMetricsCategories = + EnumSet.of( + BesuMetricCategory.KVSTORE_ROCKSDB, + BesuMetricCategory.KVSTORE_ROCKSDB_STATS, + BesuMetricCategory.KVSTORE_PRIVATE_ROCKSDB, + BesuMetricCategory.KVSTORE_PRIVATE_ROCKSDB_STATS); + + internalTestSuccess( + metricsConfBuilder -> { + assertThat(metricsConfBuilder.build().getMetricCategories()) + .containsExactlyInAnyOrderElementsOf(rocksDbMetricsCategories); + }, + "--metrics-categories", + rocksDbMetricsCategories.stream().map(Enum::name).collect(Collectors.joining(","))); + } } diff --git a/metrics/core/src/main/java/org/hyperledger/besu/metrics/MetricCategoryRegistryImpl.java b/metrics/core/src/main/java/org/hyperledger/besu/metrics/MetricCategoryRegistryImpl.java index 6596268acb..43feef12ac 100644 --- a/metrics/core/src/main/java/org/hyperledger/besu/metrics/MetricCategoryRegistryImpl.java +++ b/metrics/core/src/main/java/org/hyperledger/besu/metrics/MetricCategoryRegistryImpl.java @@ -40,7 +40,8 @@ public class MetricCategoryRegistryImpl implements MetricCategoryRegistry { * @param categoryEnum the category enum */ public & MetricCategory> void addCategories(final Class categoryEnum) { - EnumSet.allOf(categoryEnum).forEach(this::addMetricCategory); + EnumSet.allOf(categoryEnum) + .forEach(category -> metricCategories.put(category.name(), category)); } /**