Fix registration of RocksDB metrics categories (#7879)

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
pull/7840/merge
Fabio Di Fabio 1 week ago committed by GitHub
parent c15afb915b
commit f156a17d3f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 24
      besu/src/test/java/org/hyperledger/besu/cli/options/MetricsOptionsTest.java
  2. 3
      metrics/core/src/main/java/org/hyperledger/besu/metrics/MetricCategoryRegistryImpl.java

@ -14,12 +14,18 @@
*/ */
package org.hyperledger.besu.cli.options; 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.BesuMetricCategory;
import org.hyperledger.besu.metrics.MetricCategoryRegistryImpl; import org.hyperledger.besu.metrics.MetricCategoryRegistryImpl;
import org.hyperledger.besu.metrics.StandardMetricCategory; import org.hyperledger.besu.metrics.StandardMetricCategory;
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration; 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.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
@ -64,4 +70,22 @@ public class MetricsOptionsTest
protected String[] getNonOptionFields() { protected String[] getNonOptionFields() {
return new String[] {"metricCategoryRegistry"}; 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(",")));
}
} }

@ -40,7 +40,8 @@ public class MetricCategoryRegistryImpl implements MetricCategoryRegistry {
* @param categoryEnum the category enum * @param categoryEnum the category enum
*/ */
public <T extends Enum<T> & MetricCategory> void addCategories(final Class<T> categoryEnum) { public <T extends Enum<T> & MetricCategory> void addCategories(final Class<T> categoryEnum) {
EnumSet.allOf(categoryEnum).forEach(this::addMetricCategory); EnumSet.allOf(categoryEnum)
.forEach(category -> metricCategories.put(category.name(), category));
} }
/** /**

Loading…
Cancel
Save