From eefbfdf546595021a0c3bce6a050e5444a3338ef Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Tue, 11 Jun 2019 10:03:22 +1000 Subject: [PATCH 01/11] Convert MetricsConfiguration to an immutable class with a builder. --- .../JsonRpcHttpServiceRpcApisTest.java | 4 +- .../prometheus/MetricsConfiguration.java | 177 ++++++++++++------ .../prometheus/MetricsHttpServiceTest.java | 17 +- .../PrometheusMetricsSystemTest.java | 23 ++- .../pegasys/pantheon/cli/PantheonCommand.java | 25 ++- .../tech/pegasys/pantheon/RunnerTest.java | 5 +- .../pantheon/cli/PantheonCommandTest.java | 6 +- 7 files changed, 151 insertions(+), 106 deletions(-) diff --git a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceRpcApisTest.java b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceRpcApisTest.java index b017c70799..030c221052 100644 --- a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceRpcApisTest.java +++ b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceRpcApisTest.java @@ -250,9 +250,7 @@ private P2PNetwork createP2pNetwork() { } private MetricsConfiguration createMetricsConfiguration() { - final MetricsConfiguration config = MetricsConfiguration.createDefault(); - config.setEnabled(true); - return config; + return MetricsConfiguration.builder().enabled(true).port(0).build(); } private JsonRpcHttpService createJsonRpcHttpService( diff --git a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsConfiguration.java b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsConfiguration.java index 7e9b4a0dc5..3e38c2302e 100644 --- a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsConfiguration.java +++ b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsConfiguration.java @@ -30,114 +30,88 @@ public class MetricsConfiguration { private static final String DEFAULT_METRICS_PUSH_HOST = "127.0.0.1"; public static final int DEFAULT_METRICS_PUSH_PORT = 9001; - private boolean enabled; - private int port; - private String host; - private Set metricCategories; - private boolean pushEnabled; - private int pushPort; - private String pushHost; - private int pushInterval; - private String prometheusJob; - private List hostsWhitelist = Arrays.asList("localhost", "127.0.0.1"); + private final boolean enabled; + private final int port; + private final String host; + private final Set metricCategories; + private final boolean pushEnabled; + private final int pushPort; + private final String pushHost; + private final int pushInterval; + private final String prometheusJob; + private final List hostsWhitelist; public static MetricsConfiguration createDefault() { - final MetricsConfiguration metricsConfiguration = new MetricsConfiguration(); - metricsConfiguration.setEnabled(false); - metricsConfiguration.setPort(DEFAULT_METRICS_PORT); - metricsConfiguration.setHost(DEFAULT_METRICS_HOST); - metricsConfiguration.setMetricCategories(DEFAULT_METRIC_CATEGORIES); - metricsConfiguration.setPushEnabled(false); - metricsConfiguration.setPushPort(DEFAULT_METRICS_PUSH_PORT); - metricsConfiguration.setPushHost(DEFAULT_METRICS_PUSH_HOST); - metricsConfiguration.setPushInterval(15); - metricsConfiguration.setPrometheusJob("pantheon-client"); + return builder().build(); + } - return metricsConfiguration; + public static Builder builder() { + return new Builder(); } - private MetricsConfiguration() {} + private MetricsConfiguration( + final boolean enabled, + final int port, + final String host, + final Set metricCategories, + final boolean pushEnabled, + final int pushPort, + final String pushHost, + final int pushInterval, + final String prometheusJob, + final List hostsWhitelist) { + this.enabled = enabled; + this.port = port; + this.host = host; + this.metricCategories = metricCategories; + this.pushEnabled = pushEnabled; + this.pushPort = pushPort; + this.pushHost = pushHost; + this.pushInterval = pushInterval; + this.prometheusJob = prometheusJob; + this.hostsWhitelist = hostsWhitelist; + } public boolean isEnabled() { return enabled; } - public void setEnabled(final boolean enabled) { - this.enabled = enabled; - } - public int getPort() { return port; } - public void setPort(final int port) { - this.port = port; - } - public String getHost() { return host; } - public void setHost(final String host) { - this.host = host; - } - public Set getMetricCategories() { return metricCategories; } - public void setMetricCategories(final Set metricCategories) { - this.metricCategories = metricCategories; - } - public int getPushPort() { return pushPort; } - public void setPushPort(final int pushPort) { - this.pushPort = pushPort; - } - public String getPushHost() { return pushHost; } - public void setPushHost(final String pushHost) { - this.pushHost = pushHost; - } - public boolean isPushEnabled() { return pushEnabled; } - public void setPushEnabled(final boolean pushEnabled) { - this.pushEnabled = pushEnabled; - } - public int getPushInterval() { return pushInterval; } - public void setPushInterval(final int pushInterval) { - this.pushInterval = pushInterval; - } - public String getPrometheusJob() { return prometheusJob; } - public void setPrometheusJob(final String prometheusJob) { - this.prometheusJob = prometheusJob; - } - Collection getHostsWhitelist() { return Collections.unmodifiableCollection(this.hostsWhitelist); } - public void setHostsWhitelist(final List hostsWhitelist) { - this.hostsWhitelist = hostsWhitelist; - } - @Override public String toString() { return "MetricsConfiguration{" @@ -198,4 +172,83 @@ public int hashCode() { prometheusJob, hostsWhitelist); } + + public static class Builder { + private boolean enabled = false; + private int port = DEFAULT_METRICS_PORT; + private String host = DEFAULT_METRICS_HOST; + private Set metricCategories = DEFAULT_METRIC_CATEGORIES; + private boolean pushEnabled = false; + private int pushPort = DEFAULT_METRICS_PUSH_PORT; + private String pushHost = DEFAULT_METRICS_PUSH_HOST; + private int pushInterval = 15; + private String prometheusJob = "pantheon-client"; + private List hostsWhitelist = Arrays.asList("localhost", "127.0.0.1"); + + private Builder() {} + + public Builder enabled(final boolean enabled) { + this.enabled = enabled; + return this; + } + + public Builder port(final int port) { + this.port = port; + return this; + } + + public Builder host(final String host) { + this.host = host; + return this; + } + + public Builder metricCategories(final Set metricCategories) { + this.metricCategories = metricCategories; + return this; + } + + public Builder pushEnabled(final boolean pushEnabled) { + this.pushEnabled = pushEnabled; + return this; + } + + public Builder pushPort(final int pushPort) { + this.pushPort = pushPort; + return this; + } + + public Builder pushHost(final String pushHost) { + this.pushHost = pushHost; + return this; + } + + public Builder pushInterval(final int pushInterval) { + this.pushInterval = pushInterval; + return this; + } + + public Builder prometheusJob(final String prometheusJob) { + this.prometheusJob = prometheusJob; + return this; + } + + public Builder hostsWhitelist(final List hostsWhitelist) { + this.hostsWhitelist = hostsWhitelist; + return this; + } + + public MetricsConfiguration build() { + return new MetricsConfiguration( + enabled, + port, + host, + metricCategories, + pushEnabled, + pushPort, + pushHost, + pushInterval, + prometheusJob, + hostsWhitelist); + } + } } diff --git a/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/prometheus/MetricsHttpServiceTest.java b/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/prometheus/MetricsHttpServiceTest.java index 98f7fbdf4d..189cb8b825 100644 --- a/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/prometheus/MetricsHttpServiceTest.java +++ b/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/prometheus/MetricsHttpServiceTest.java @@ -54,17 +54,19 @@ private static MetricsHttpService createMetricsHttpService(final MetricsConfigur private static MetricsHttpService createMetricsHttpService() { final MetricsConfiguration metricsConfiguration = createMetricsConfig(); - metricsConfiguration.setEnabled(true); return new MetricsHttpService( vertx, metricsConfiguration, PrometheusMetricsSystem.init(metricsConfiguration)); } private static MetricsConfiguration createMetricsConfig() { - final MetricsConfiguration config = MetricsConfiguration.createDefault(); - config.setEnabled(true); - config.setPort(0); - config.setHostsWhitelist(Collections.singletonList("*")); - return config; + return createMetricsConfigBuilder().build(); + } + + private static MetricsConfiguration.Builder createMetricsConfigBuilder() { + return MetricsConfiguration.builder() + .enabled(true) + .port(0) + .hostsWhitelist(Collections.singletonList("*")); } /** Tears down the HTTP server. */ @@ -114,8 +116,7 @@ public void getSocketAddressWhenStoppedIsEmpty() { @Test public void getSocketAddressWhenBindingToAllInterfaces() { - final MetricsConfiguration config = createMetricsConfig(); - config.setHost("0.0.0.0"); + final MetricsConfiguration config = createMetricsConfigBuilder().host("0.0.0.0").build(); final MetricsHttpService service = createMetricsHttpService(config); service.start().join(); diff --git a/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystemTest.java b/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystemTest.java index cf4f57c211..57e264f9bb 100644 --- a/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystemTest.java +++ b/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystemTest.java @@ -173,9 +173,11 @@ public void shouldNotAllowDuplicateGaugeCreation() { @Test public void shouldOnlyObserveEnabledMetrics() { - final MetricsConfiguration metricsConfiguration = MetricsConfiguration.createDefault(); - metricsConfiguration.setMetricCategories(EnumSet.of(MetricCategory.RPC)); - metricsConfiguration.setEnabled(true); + final MetricsConfiguration metricsConfiguration = + MetricsConfiguration.builder() + .metricCategories(EnumSet.of(MetricCategory.RPC)) + .enabled(true) + .build(); final MetricsSystem localMetricSystem = PrometheusMetricsSystem.init(metricsConfiguration); // do a category we are not watching @@ -198,9 +200,8 @@ public void shouldOnlyObserveEnabledMetrics() { @Test public void returnsNoOpMetricsWhenAllDisabled() { - final MetricsConfiguration metricsConfiguration = MetricsConfiguration.createDefault(); - metricsConfiguration.setEnabled(false); - metricsConfiguration.setPushEnabled(false); + final MetricsConfiguration metricsConfiguration = + MetricsConfiguration.builder().enabled(false).pushEnabled(false).build(); final MetricsSystem localMetricSystem = PrometheusMetricsSystem.init(metricsConfiguration); assertThat(localMetricSystem).isInstanceOf(NoOpMetricsSystem.class); @@ -208,9 +209,8 @@ public void returnsNoOpMetricsWhenAllDisabled() { @Test public void returnsPrometheusMetricsWhenEnabled() { - final MetricsConfiguration metricsConfiguration = MetricsConfiguration.createDefault(); - metricsConfiguration.setEnabled(true); - metricsConfiguration.setPushEnabled(false); + final MetricsConfiguration metricsConfiguration = + MetricsConfiguration.builder().enabled(true).pushEnabled(false).build(); final MetricsSystem localMetricSystem = PrometheusMetricsSystem.init(metricsConfiguration); assertThat(localMetricSystem).isInstanceOf(PrometheusMetricsSystem.class); @@ -218,9 +218,8 @@ public void returnsPrometheusMetricsWhenEnabled() { @Test public void returnsNoOpMetricsWhenPushEnabled() { - final MetricsConfiguration metricsConfiguration = MetricsConfiguration.createDefault(); - metricsConfiguration.setEnabled(false); - metricsConfiguration.setPushEnabled(true); + final MetricsConfiguration metricsConfiguration = + MetricsConfiguration.builder().enabled(false).pushEnabled(true).build(); final MetricsSystem localMetricSystem = PrometheusMetricsSystem.init(metricsConfiguration); assertThat(localMetricSystem).isInstanceOf(PrometheusMetricsSystem.class); diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java index 84c218b0b1..18e2f17121 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -27,7 +27,6 @@ import static tech.pegasys.pantheon.metrics.MetricCategory.DEFAULT_METRIC_CATEGORIES; import static tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration.DEFAULT_METRICS_PORT; import static tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration.DEFAULT_METRICS_PUSH_PORT; -import static tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration.createDefault; import tech.pegasys.pantheon.Runner; import tech.pegasys.pantheon.RunnerBuilder; @@ -990,18 +989,18 @@ MetricsConfiguration metricsConfiguration() { "--metrics-push-interval", "--metrics-push-prometheus-job")); - final MetricsConfiguration metricsConfiguration = createDefault(); - metricsConfiguration.setEnabled(isMetricsEnabled); - metricsConfiguration.setHost(metricsHost); - metricsConfiguration.setPort(metricsPort); - metricsConfiguration.setMetricCategories(metricCategories); - metricsConfiguration.setPushEnabled(isMetricsPushEnabled); - metricsConfiguration.setPushHost(metricsPushHost); - metricsConfiguration.setPushPort(metricsPushPort); - metricsConfiguration.setPushInterval(metricsPushInterval); - metricsConfiguration.setPrometheusJob(metricsPrometheusJob); - metricsConfiguration.setHostsWhitelist(hostsWhitelist); - return metricsConfiguration; + return MetricsConfiguration.builder() + .enabled(isMetricsEnabled) + .host(metricsHost) + .port(metricsPort) + .metricCategories(metricCategories) + .pushEnabled(isMetricsPushEnabled) + .pushHost(metricsPushHost) + .pushPort(metricsPushPort) + .pushInterval(metricsPushInterval) + .hostsWhitelist(hostsWhitelist) + .prometheusJob(metricsPrometheusJob) + .build(); } private Optional permissioningConfiguration() throws Exception { diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java index d190d254b9..d78826e767 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java @@ -360,10 +360,7 @@ private WebSocketConfiguration wsRpcConfiguration() { } private MetricsConfiguration metricsConfiguration() { - final MetricsConfiguration configuration = MetricsConfiguration.createDefault(); - configuration.setPort(0); - configuration.setEnabled(false); - return configuration; + return MetricsConfiguration.builder().port(0).enabled(false).build(); } private static void setupState( diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java index d0a427c079..3d377cf485 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java @@ -299,10 +299,8 @@ public void overrideDefaultValuesIfKeyIsPresentInConfigFile() throws IOException webSocketConfiguration.setPort(9101); webSocketConfiguration.setRpcApis(expectedApis); - final MetricsConfiguration metricsConfiguration = MetricsConfiguration.createDefault(); - metricsConfiguration.setEnabled(false); - metricsConfiguration.setHost("8.6.7.5"); - metricsConfiguration.setPort(309); + final MetricsConfiguration metricsConfiguration = + MetricsConfiguration.builder().enabled(false).host("8.6.7.5").port(309).build(); parseCommand("--config-file", toml.toString()); From ef3291e711da35e5e03f34503f461b9febaf25cc Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Tue, 11 Jun 2019 10:08:50 +1000 Subject: [PATCH 02/11] Remove BIG_QUEUE metric category as nothing uses it. --- .../java/tech/pegasys/pantheon/metrics/MetricCategory.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/MetricCategory.java b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/MetricCategory.java index f203b0b03c..d2802656c7 100644 --- a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/MetricCategory.java +++ b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/MetricCategory.java @@ -16,7 +16,6 @@ import java.util.Set; public enum MetricCategory { - BIG_QUEUE("big_queue"), BLOCKCHAIN("blockchain"), EXECUTORS("executors"), JVM("jvm", false), @@ -30,9 +29,9 @@ public enum MetricCategory { SYNCHRONIZER("synchronizer"), TRANSACTION_POOL("transaction_pool"); - // Why not BIG_QUEUE and ROCKSDB? They hurt performance under load. + // Why not ROCKSDB and KVSTORE_ROCKSDB_STATS? They hurt performance under load. public static final Set DEFAULT_METRIC_CATEGORIES = - EnumSet.complementOf(EnumSet.of(BIG_QUEUE, KVSTORE_ROCKSDB, KVSTORE_ROCKSDB_STATS)); + EnumSet.complementOf(EnumSet.of(KVSTORE_ROCKSDB, KVSTORE_ROCKSDB_STATS)); private final String name; private final boolean pantheonSpecific; From d8ba38d33c61e3c0cb46c8f2b27bf1a88a631c27 Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Tue, 11 Jun 2019 10:54:27 +1000 Subject: [PATCH 03/11] Tidy up checking if a category is enabled. --- .../prometheus/PrometheusMetricsSystem.java | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystem.java b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystem.java index d4f58dc5f0..aa77463249 100644 --- a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystem.java +++ b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystem.java @@ -25,13 +25,14 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.EnumSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.function.DoubleSupplier; import java.util.stream.Stream; +import com.google.common.collect.ImmutableSet; import io.prometheus.client.Collector; import io.prometheus.client.Collector.MetricFamilySamples; import io.prometheus.client.Collector.MetricFamilySamples.Sample; @@ -56,22 +57,24 @@ public class PrometheusMetricsSystem implements MetricsSystem { private final Map> cachedTimers = new ConcurrentHashMap<>(); - private final EnumSet enabledCategories = EnumSet.allOf(MetricCategory.class); + private final Set enabledCategories; - PrometheusMetricsSystem() {} + PrometheusMetricsSystem(final Set enabledCategories) { + this.enabledCategories = ImmutableSet.copyOf(enabledCategories); + } public static MetricsSystem init(final MetricsConfiguration metricsConfiguration) { if (!metricsConfiguration.isEnabled() && !metricsConfiguration.isPushEnabled()) { return new NoOpMetricsSystem(); } - final PrometheusMetricsSystem metricsSystem = new PrometheusMetricsSystem(); - metricsSystem.enabledCategories.retainAll(metricsConfiguration.getMetricCategories()); - if (metricsSystem.enabledCategories.contains(MetricCategory.PROCESS)) { + final PrometheusMetricsSystem metricsSystem = + new PrometheusMetricsSystem(metricsConfiguration.getMetricCategories()); + if (metricsSystem.isCategoryEnabled(MetricCategory.PROCESS)) { metricsSystem.collectors.put( MetricCategory.PROCESS, singleton(new StandardExports().register(metricsSystem.registry))); } - if (metricsSystem.enabledCategories.contains(MetricCategory.JVM)) { + if (metricsSystem.isCategoryEnabled(MetricCategory.JVM)) { metricsSystem.collectors.put( MetricCategory.JVM, asList( @@ -94,7 +97,7 @@ public LabelledMetric createLabelledCount return cachedCounters.computeIfAbsent( metricName, (k) -> { - if (enabledCategories.contains(category)) { + if (isCategoryEnabled(category)) { final Counter counter = Counter.build(metricName, help).labelNames(labelNames).create(); addCollectorUnchecked(category, counter); return new PrometheusCounter(counter); @@ -114,7 +117,7 @@ public LabelledMetric createLabelledTimer( return cachedTimers.computeIfAbsent( metricName, (k) -> { - if (enabledCategories.contains(category)) { + if (isCategoryEnabled(category)) { final Summary summary = Summary.build(metricName, help) .quantile(0.2, 0.02) @@ -140,14 +143,18 @@ public void createGauge( final String help, final DoubleSupplier valueSupplier) { final String metricName = convertToPrometheusName(category, name); - if (enabledCategories.contains(category)) { + if (isCategoryEnabled(category)) { final Collector collector = new CurrentValueCollector(metricName, help, valueSupplier); addCollectorUnchecked(category, collector); } } + private boolean isCategoryEnabled(final MetricCategory category) { + return enabledCategories.contains(category); + } + public void addCollector(final MetricCategory category, final Collector metric) { - if (enabledCategories.contains(category)) { + if (isCategoryEnabled(category)) { addCollectorUnchecked(category, metric); } } From 45e604d33d362d045c453d404afb23ee32d87af5 Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Tue, 11 Jun 2019 13:29:24 +1000 Subject: [PATCH 04/11] Make MetricCategory an interface so it isn't locked into the pantheon specific categories. --- .../chain/DefaultMutableBlockchain.java | 8 +- .../ethereum/eth/manager/EthPeers.java | 4 +- .../eth/manager/MonitoredExecutors.java | 14 ++-- .../eth/manager/task/AbstractEthTask.java | 4 +- .../eth/sync/DefaultSynchronizer.java | 6 +- .../eth/sync/PipelineChainDownloader.java | 4 +- .../sync/fastsync/FastDownloaderFactory.java | 6 +- .../eth/sync/fastsync/FastSyncActions.java | 6 +- .../FastSyncDownloadPipelineFactory.java | 6 +- .../FullSyncDownloadPipelineFactory.java | 4 +- .../eth/sync/worldstate/CompleteTaskStep.java | 6 +- .../sync/worldstate/LoadLocalDataStep.java | 4 +- .../worldstate/WorldStateDownloadProcess.java | 4 +- .../sync/worldstate/WorldStateDownloader.java | 6 +- .../eth/transactions/PendingTransactions.java | 6 +- .../ethereum/jsonrpc/JsonRpcHttpService.java | 4 +- .../subscription/SubscriptionManager.java | 6 +- .../internal/methods/DebugMetricsTest.java | 4 +- .../pantheon/ethereum/p2p/NetworkRunner.java | 4 +- .../discovery/VertxPeerDiscoveryAgent.java | 4 +- .../internal/DiscoveryProtocolLogger.java | 6 +- .../internal/PeerDiscoveryController.java | 8 +- .../p2p/network/DefaultP2PNetwork.java | 10 +-- .../network/netty/PeerConnectionRegistry.java | 8 +- ...untLocalConfigPermissioningController.java | 8 +- ...odeLocalConfigPermissioningController.java | 8 +- ...eSmartContractPermissioningController.java | 8 +- ...nSmartContractPermissioningController.java | 8 +- .../SyncStatusNodePermissioningProvider.java | 10 +-- ...ocalConfigPermissioningControllerTest.java | 8 +- ...ocalConfigPermissioningControllerTest.java | 8 +- ...rtContractPermissioningControllerTest.java | 8 +- ...rtContractPermissioningControllerTest.java | 8 +- ...ncStatusNodePermissioningProviderTest.java | 10 +-- .../pantheon/metrics/MetricCategory.java | 43 +---------- .../pantheon/metrics/MetricsSystem.java | 4 +- .../metrics/PantheonMetricCategories.java | 67 ++++++++++++++++ .../metrics/StandardMetricCategories.java | 34 +++++++++ .../prometheus/MetricsConfiguration.java | 76 +++++++++++-------- .../prometheus/PrometheusMetricsSystem.java | 32 +++++--- .../metrics/vertx/PoolMetricsAdapter.java | 8 +- .../pantheon/metrics/StubMetricsSystem.java | 5 ++ .../metrics/noop/NoOpMetricsSystemTest.java | 12 +-- .../PrometheusMetricsSystemTest.java | 20 ++--- .../metrics/rocksdb/RocksDBStats.java | 5 +- .../pegasys/pantheon/cli/PantheonCommand.java | 14 +++- .../pantheon/cli/PantheonCommandTest.java | 22 ++++-- .../kvstore/RocksDbKeyValueStorage.java | 14 ++-- 48 files changed, 348 insertions(+), 234 deletions(-) create mode 100644 metrics/core/src/main/java/tech/pegasys/pantheon/metrics/PantheonMetricCategories.java create mode 100644 metrics/core/src/main/java/tech/pegasys/pantheon/metrics/StandardMetricCategories.java diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/chain/DefaultMutableBlockchain.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/chain/DefaultMutableBlockchain.java index 521a999dea..88f4b2f764 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/chain/DefaultMutableBlockchain.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/chain/DefaultMutableBlockchain.java @@ -23,8 +23,8 @@ import tech.pegasys.pantheon.ethereum.core.Hash; import tech.pegasys.pantheon.ethereum.core.Transaction; import tech.pegasys.pantheon.ethereum.core.TransactionReceipt; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import tech.pegasys.pantheon.util.InvalidConfigurationException; import tech.pegasys.pantheon.util.Subscribers; import tech.pegasys.pantheon.util.bytes.BytesValues; @@ -64,12 +64,12 @@ public DefaultMutableBlockchain( totalDifficulty = blockchainStorage.getTotalDifficulty(chainHead).get(); metricsSystem.createLongGauge( - MetricCategory.BLOCKCHAIN, + PantheonMetricCategories.BLOCKCHAIN, "height", "Height of the chainhead", this::getChainHeadBlockNumber); metricsSystem.createLongGauge( - MetricCategory.BLOCKCHAIN, + PantheonMetricCategories.BLOCKCHAIN, "difficulty_total", "Total difficulty of the chainhead", () -> @@ -77,7 +77,7 @@ public DefaultMutableBlockchain( .longValue()); metricsSystem.createLongGauge( - MetricCategory.BLOCKCHAIN, + PantheonMetricCategories.BLOCKCHAIN, "chain_head_timestamp", "Timestamp from the current chain head", () -> getChainHeadHeader().getTimestamp()); diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/EthPeers.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/EthPeers.java index c5f77eafd5..a2aa978226 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/EthPeers.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/EthPeers.java @@ -14,8 +14,8 @@ import tech.pegasys.pantheon.ethereum.eth.manager.EthPeer.DisconnectCallback; import tech.pegasys.pantheon.ethereum.p2p.api.PeerConnection; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import tech.pegasys.pantheon.util.Subscribers; import java.time.Clock; @@ -53,7 +53,7 @@ public EthPeers(final String protocolName, final Clock clock, final MetricsSyste this.protocolName = protocolName; this.clock = clock; metricsSystem.createIntegerGauge( - MetricCategory.PEERS, + PantheonMetricCategories.PEERS, "pending_peer_requests_current", "Number of peer requests currently pending because peers are busy", pendingRequests::size); diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/MonitoredExecutors.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/MonitoredExecutors.java index b13deea9b3..49e58c677f 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/MonitoredExecutors.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/MonitoredExecutors.java @@ -13,8 +13,8 @@ package tech.pegasys.pantheon.ethereum.eth.manager; import tech.pegasys.pantheon.metrics.Counter; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import java.util.Locale; import java.util.concurrent.ExecutorService; @@ -87,31 +87,31 @@ private static T newMonitoredExecutor( new ThreadFactoryBuilder().setNameFormat(name + "-%d").build()); metricsSystem.createIntegerGauge( - MetricCategory.EXECUTORS, + PantheonMetricCategories.EXECUTORS, metricName + "_queue_length_current", "Current number of tasks awaiting execution", executor.getQueue()::size); metricsSystem.createIntegerGauge( - MetricCategory.EXECUTORS, + PantheonMetricCategories.EXECUTORS, metricName + "_active_threads_current", "Current number of threads executing tasks", executor::getActiveCount); metricsSystem.createIntegerGauge( - MetricCategory.EXECUTORS, + PantheonMetricCategories.EXECUTORS, metricName + "_pool_size_current", "Current number of threads in the thread pool", executor::getPoolSize); metricsSystem.createLongGauge( - MetricCategory.EXECUTORS, + PantheonMetricCategories.EXECUTORS, metricName + "_completed_tasks_total", "Total number of tasks executed", executor::getCompletedTaskCount); metricsSystem.createLongGauge( - MetricCategory.EXECUTORS, + PantheonMetricCategories.EXECUTORS, metricName + "_submitted_tasks_total", "Total number of tasks executed", executor::getTaskCount); @@ -126,7 +126,7 @@ private static class CountingAbortPolicy extends AbortPolicy { public CountingAbortPolicy(final String metricName, final MetricsSystem metricsSystem) { this.rejectedTaskCounter = metricsSystem.createCounter( - MetricCategory.EXECUTORS, + PantheonMetricCategories.EXECUTORS, metricName + "_rejected_tasks_total", "Total number of tasks rejected by this executor"); } diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/task/AbstractEthTask.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/task/AbstractEthTask.java index 27ceb21d55..0eb87d189e 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/task/AbstractEthTask.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/task/AbstractEthTask.java @@ -16,9 +16,9 @@ import tech.pegasys.pantheon.ethereum.eth.manager.EthScheduler; import tech.pegasys.pantheon.metrics.LabelledMetric; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; import tech.pegasys.pantheon.metrics.OperationTimer; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; import java.util.Collection; @@ -50,7 +50,7 @@ protected AbstractEthTask(final OperationTimer taskTimer) { private static OperationTimer buildOperationTimer(final MetricsSystem metricsSystem) { final LabelledMetric ethTasksTimer = metricsSystem.createLabelledTimer( - MetricCategory.SYNCHRONIZER, "task", "Internal processing tasks", "taskName"); + PantheonMetricCategories.SYNCHRONIZER, "task", "Internal processing tasks", "taskName"); if (ethTasksTimer == NoOpMetricsSystem.NO_OP_LABELLED_1_OPERATION_TIMER) { return () -> new OperationTimer.TimingContext() { diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java index d340e93e19..65c3c17fd3 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java @@ -27,8 +27,8 @@ import tech.pegasys.pantheon.ethereum.eth.sync.state.SyncState; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; import tech.pegasys.pantheon.ethereum.worldstate.WorldStateStorage; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import tech.pegasys.pantheon.util.ExceptionUtils; import tech.pegasys.pantheon.util.Subscribers; @@ -98,12 +98,12 @@ public DefaultSynchronizer( clock); metricsSystem.createLongGauge( - MetricCategory.SYNCHRONIZER, + PantheonMetricCategories.SYNCHRONIZER, "best_known_block", "Height of best known block from any connected peer", () -> syncState.syncStatus().getHighestBlock()); metricsSystem.createIntegerGauge( - MetricCategory.SYNCHRONIZER, + PantheonMetricCategories.SYNCHRONIZER, "in_sync", "Whether or not the local node has caught up to the best known peer", () -> getSyncStatus().isPresent() ? 0 : 1); diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/PipelineChainDownloader.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/PipelineChainDownloader.java index 5036097e00..e00deb24b3 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/PipelineChainDownloader.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/PipelineChainDownloader.java @@ -23,8 +23,8 @@ import tech.pegasys.pantheon.ethereum.eth.sync.tasks.exceptions.InvalidBlockException; import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.LabelledMetric; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import tech.pegasys.pantheon.services.pipeline.Pipeline; import tech.pegasys.pantheon.util.ExceptionUtils; @@ -65,7 +65,7 @@ public PipelineChainDownloader( final LabelledMetric labelledCounter = metricsSystem.createLabelledCounter( - MetricCategory.SYNCHRONIZER, + PantheonMetricCategories.SYNCHRONIZER, "chain_download_pipeline_restarts", "Number of times the chain download pipeline has been restarted", "reason"); diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastDownloaderFactory.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastDownloaderFactory.java index 054972f6b6..8aa6c7e9c2 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastDownloaderFactory.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastDownloaderFactory.java @@ -23,8 +23,8 @@ import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; import tech.pegasys.pantheon.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions; import tech.pegasys.pantheon.ethereum.worldstate.WorldStateStorage; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import tech.pegasys.pantheon.services.tasks.CachingTaskCollection; import tech.pegasys.pantheon.services.tasks.FlatFileTaskCollection; @@ -123,13 +123,13 @@ private static CachingTaskCollection createWorldStateDownloader dataDirectory, NodeDataRequest::serialize, NodeDataRequest::deserialize)); metricsSystem.createLongGauge( - MetricCategory.SYNCHRONIZER, + PantheonMetricCategories.SYNCHRONIZER, "world_state_pending_requests_current", "Number of pending requests for fast sync world state download", taskCollection::size); metricsSystem.createIntegerGauge( - MetricCategory.SYNCHRONIZER, + PantheonMetricCategories.SYNCHRONIZER, "world_state_pending_requests_cache_size", "Pending request cache size for fast sync world state download", taskCollection::cacheSize); diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncActions.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncActions.java index 2bd3971f83..9e0c2d5fd4 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncActions.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncActions.java @@ -26,8 +26,8 @@ import tech.pegasys.pantheon.ethereum.eth.sync.state.SyncState; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; import tech.pegasys.pantheon.metrics.Counter; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import tech.pegasys.pantheon.util.ExceptionUtils; import java.time.Duration; @@ -66,11 +66,11 @@ public FastSyncActions( pivotBlockSelectionCounter = metricsSystem.createCounter( - MetricCategory.SYNCHRONIZER, + PantheonMetricCategories.SYNCHRONIZER, "fast_sync_pivot_block_selected_count", "Number of times a fast sync pivot block has been selected"); metricsSystem.createLongGauge( - MetricCategory.SYNCHRONIZER, + PantheonMetricCategories.SYNCHRONIZER, "fast_sync_pivot_block_current", "The current fast sync pivot block", pivotBlockGauge::get); diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java index 81a3b7a54e..b134b25266 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java @@ -34,8 +34,8 @@ import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.LabelledMetric; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import tech.pegasys.pantheon.services.pipeline.Pipeline; import tech.pegasys.pantheon.services.pipeline.PipelineBuilder; @@ -67,7 +67,7 @@ public FastSyncDownloadPipelineFactory( this.metricsSystem = metricsSystem; final LabelledMetric fastSyncValidationCounter = metricsSystem.createLabelledCounter( - MetricCategory.SYNCHRONIZER, + PantheonMetricCategories.SYNCHRONIZER, "fast_sync_validation_mode", "Number of blocks validated using light vs full validation during fast sync", "validationMode"); @@ -130,7 +130,7 @@ public Pipeline createDownloadPipelineForSyncTarget(final SyncTarget target) checkpointRangeSource, downloaderParallelism, metricsSystem.createLabelledCounter( - MetricCategory.SYNCHRONIZER, + PantheonMetricCategories.SYNCHRONIZER, "chain_download_pipeline_processed_total", "Number of entries process by each chain download pipeline stage", "step", diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fullsync/FullSyncDownloadPipelineFactory.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fullsync/FullSyncDownloadPipelineFactory.java index 8f047e4c10..265fa98fb5 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fullsync/FullSyncDownloadPipelineFactory.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fullsync/FullSyncDownloadPipelineFactory.java @@ -27,8 +27,8 @@ import tech.pegasys.pantheon.ethereum.eth.sync.state.SyncTarget; import tech.pegasys.pantheon.ethereum.mainnet.HeaderValidationMode; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import tech.pegasys.pantheon.services.pipeline.Pipeline; import tech.pegasys.pantheon.services.pipeline.PipelineBuilder; @@ -95,7 +95,7 @@ public Pipeline createDownloadPipelineForSyncTarget(final SyncTarget target) checkpointRangeSource, downloaderParallelism, metricsSystem.createLabelledCounter( - MetricCategory.SYNCHRONIZER, + PantheonMetricCategories.SYNCHRONIZER, "chain_download_pipeline_processed_total", "Number of entries process by each chain download pipeline stage", "step", diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/CompleteTaskStep.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/CompleteTaskStep.java index 0ec1635d59..4e644f939a 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/CompleteTaskStep.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/CompleteTaskStep.java @@ -15,8 +15,8 @@ import tech.pegasys.pantheon.ethereum.core.BlockHeader; import tech.pegasys.pantheon.ethereum.worldstate.WorldStateStorage; import tech.pegasys.pantheon.metrics.Counter; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import tech.pegasys.pantheon.services.tasks.Task; public class CompleteTaskStep { @@ -31,12 +31,12 @@ public CompleteTaskStep( completedRequestsCounter = metricsSystem.createCounter( - MetricCategory.SYNCHRONIZER, + PantheonMetricCategories.SYNCHRONIZER, "world_state_completed_requests_total", "Total number of node data requests completed as part of fast sync world state download"); retriedRequestsCounter = metricsSystem.createCounter( - MetricCategory.SYNCHRONIZER, + PantheonMetricCategories.SYNCHRONIZER, "world_state_retried_requests_total", "Total number of node data requests repeated as part of fast sync world state download"); } diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/LoadLocalDataStep.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/LoadLocalDataStep.java index 7c7651f0b9..d5f8518401 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/LoadLocalDataStep.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/LoadLocalDataStep.java @@ -14,8 +14,8 @@ import tech.pegasys.pantheon.ethereum.worldstate.WorldStateStorage; import tech.pegasys.pantheon.metrics.Counter; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import tech.pegasys.pantheon.services.pipeline.Pipe; import tech.pegasys.pantheon.services.tasks.Task; import tech.pegasys.pantheon.util.bytes.BytesValue; @@ -33,7 +33,7 @@ public LoadLocalDataStep( this.worldStateStorage = worldStateStorage; existingNodeCounter = metricsSystem.createCounter( - MetricCategory.SYNCHRONIZER, + PantheonMetricCategories.SYNCHRONIZER, "world_state_existing_nodes_total", "Total number of node data requests completed using existing data"); } diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloadProcess.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloadProcess.java index 52da694bc9..e0facef3ea 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloadProcess.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloadProcess.java @@ -19,8 +19,8 @@ import tech.pegasys.pantheon.ethereum.eth.manager.EthScheduler; import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.LabelledMetric; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import tech.pegasys.pantheon.services.pipeline.Pipe; import tech.pegasys.pantheon.services.pipeline.Pipeline; import tech.pegasys.pantheon.services.pipeline.PipelineBuilder; @@ -196,7 +196,7 @@ public WorldStateDownloadProcess build() { final int bufferCapacity = hashCountPerRequest * 2; final LabelledMetric outputCounter = metricsSystem.createLabelledCounter( - MetricCategory.SYNCHRONIZER, + PantheonMetricCategories.SYNCHRONIZER, "world_state_pipeline_processed_total", "Number of entries processed by each world state download pipeline stage", "step", diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloader.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloader.java index 21186e723f..9c3e03c008 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloader.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloader.java @@ -16,8 +16,8 @@ import tech.pegasys.pantheon.ethereum.core.Hash; import tech.pegasys.pantheon.ethereum.eth.manager.EthContext; import tech.pegasys.pantheon.ethereum.worldstate.WorldStateStorage; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import tech.pegasys.pantheon.services.tasks.CachingTaskCollection; import java.time.Clock; @@ -66,13 +66,13 @@ public WorldStateDownloader( this.metricsSystem = metricsSystem; metricsSystem.createIntegerGauge( - MetricCategory.SYNCHRONIZER, + PantheonMetricCategories.SYNCHRONIZER, "world_state_node_requests_since_last_progress_current", "Number of world state requests made since the last time new data was returned", downloadStateValue(WorldDownloadState::getRequestsSinceLastProgress)); metricsSystem.createIntegerGauge( - MetricCategory.SYNCHRONIZER, + PantheonMetricCategories.SYNCHRONIZER, "world_state_inflight_requests_current", "Number of in progress requests for world state data", downloadStateValue(WorldDownloadState::getOutstandingTaskCount)); diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/PendingTransactions.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/PendingTransactions.java index 71638709de..bf1103ed8d 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/PendingTransactions.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/PendingTransactions.java @@ -20,8 +20,8 @@ import tech.pegasys.pantheon.ethereum.core.Transaction; import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.LabelledMetric; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import tech.pegasys.pantheon.util.Subscribers; import java.time.Clock; @@ -87,7 +87,7 @@ public PendingTransactions( this.clock = clock; final LabelledMetric transactionAddedCounter = metricsSystem.createLabelledCounter( - MetricCategory.TRANSACTION_POOL, + PantheonMetricCategories.TRANSACTION_POOL, "transactions_added_total", "Count of transactions added to the transaction pool", "source"); @@ -96,7 +96,7 @@ public PendingTransactions( transactionRemovedCounter = metricsSystem.createLabelledCounter( - MetricCategory.TRANSACTION_POOL, + PantheonMetricCategories.TRANSACTION_POOL, "transactions_removed_total", "Count of transactions removed from the transaction pool", "source", diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpService.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpService.java index c05c091373..5d2f82ec72 100755 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpService.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpService.java @@ -30,10 +30,10 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponseType; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcUnauthorizedResponse; import tech.pegasys.pantheon.metrics.LabelledMetric; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; import tech.pegasys.pantheon.metrics.OperationTimer; import tech.pegasys.pantheon.metrics.OperationTimer.TimingContext; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import tech.pegasys.pantheon.util.NetworkUtility; import java.net.InetSocketAddress; @@ -122,7 +122,7 @@ private JsonRpcHttpService( this.dataDir = dataDir; requestTimer = metricsSystem.createLabelledTimer( - MetricCategory.RPC, + PantheonMetricCategories.RPC, "request_time", "Time taken to process a JSON-RPC request", "methodName"); diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/SubscriptionManager.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/SubscriptionManager.java index 879672eb31..8c60999d2a 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/SubscriptionManager.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/SubscriptionManager.java @@ -19,8 +19,8 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.subscription.response.SubscriptionResponse; import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.LabelledMetric; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import java.util.List; import java.util.Map; @@ -55,13 +55,13 @@ public class SubscriptionManager extends AbstractVerticle { public SubscriptionManager(final MetricsSystem metricsSystem) { subscribeCounter = metricsSystem.createLabelledCounter( - MetricCategory.RPC, + PantheonMetricCategories.RPC, "subscription_subscribe_total", "Total number of subscriptions", "type"); unsubscribeCounter = metricsSystem.createLabelledCounter( - MetricCategory.RPC, + PantheonMetricCategories.RPC, "subscription_unsubscribe_total", "Total number of unsubscriptions", "type"); diff --git a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/DebugMetricsTest.java b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/DebugMetricsTest.java index ed4f209349..5b7cd4fe71 100644 --- a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/DebugMetricsTest.java +++ b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/DebugMetricsTest.java @@ -16,8 +16,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static tech.pegasys.pantheon.metrics.MetricCategory.PEERS; -import static tech.pegasys.pantheon.metrics.MetricCategory.RPC; +import static tech.pegasys.pantheon.metrics.PantheonMetricCategories.PEERS; +import static tech.pegasys.pantheon.metrics.PantheonMetricCategories.RPC; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse; diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/NetworkRunner.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/NetworkRunner.java index 8646f58d4f..f10f324285 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/NetworkRunner.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/NetworkRunner.java @@ -19,8 +19,8 @@ import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage.DisconnectReason; import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.LabelledMetric; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import java.util.ArrayList; import java.util.Arrays; @@ -57,7 +57,7 @@ private NetworkRunner( this.subProtocols = subProtocols; inboundMessageCounter = metricsSystem.createLabelledCounter( - MetricCategory.NETWORK, + PantheonMetricCategories.NETWORK, "p2p_messages_inbound", "Count of each P2P message received inbound.", "protocol", diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/VertxPeerDiscoveryAgent.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/VertxPeerDiscoveryAgent.java index 200e27c9b0..65568d6263 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/VertxPeerDiscoveryAgent.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/VertxPeerDiscoveryAgent.java @@ -22,8 +22,8 @@ import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.TimerUtil; import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.VertxTimerUtil; import tech.pegasys.pantheon.ethereum.p2p.permissions.PeerPermissions; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import tech.pegasys.pantheon.util.NetworkUtility; import java.io.IOException; @@ -64,7 +64,7 @@ public VertxPeerDiscoveryAgent( this.vertx = vertx; metricsSystem.createIntegerGauge( - MetricCategory.NETWORK, + PantheonMetricCategories.NETWORK, "vertx_eventloop_pending_tasks", "The number of pending tasks in the Vertx event loop", pendingTaskCounter(vertx.nettyEventLoopGroup())); diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/DiscoveryProtocolLogger.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/DiscoveryProtocolLogger.java index e7e0e087b7..d33550f065 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/DiscoveryProtocolLogger.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/DiscoveryProtocolLogger.java @@ -15,8 +15,8 @@ import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.LabelledMetric; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -30,13 +30,13 @@ public class DiscoveryProtocolLogger { public DiscoveryProtocolLogger(final MetricsSystem metricsSystem) { outgoingMessageCounter = metricsSystem.createLabelledCounter( - MetricCategory.NETWORK, + PantheonMetricCategories.NETWORK, "discovery_messages_outbound", "Total number of P2P discovery messages sent", "name"); incomingMessageCounter = metricsSystem.createLabelledCounter( - MetricCategory.NETWORK, + PantheonMetricCategories.NETWORK, "discovery_messages_inbound", "Total number of P2P discovery messages received", "name"); diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/PeerDiscoveryController.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/PeerDiscoveryController.java index fea22f3a5a..cac5876c47 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/PeerDiscoveryController.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/PeerDiscoveryController.java @@ -30,8 +30,8 @@ import tech.pegasys.pantheon.ethereum.p2p.permissions.PeerPermissions; import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.LabelledMetric; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import tech.pegasys.pantheon.util.Subscribers; import tech.pegasys.pantheon.util.bytes.BytesValue; @@ -172,21 +172,21 @@ private PeerDiscoveryController( this.peerPermissions = new PeerDiscoveryPermissions(localPeer, peerPermissions); metricsSystem.createIntegerGauge( - MetricCategory.NETWORK, + PantheonMetricCategories.NETWORK, "discovery_inflight_interactions_current", "Current number of inflight discovery interactions", inflightInteractions::size); interactionCounter = metricsSystem.createLabelledCounter( - MetricCategory.NETWORK, + PantheonMetricCategories.NETWORK, "discovery_interaction_count", "Total number of discovery interactions initiated", "type"); interactionRetryCounter = metricsSystem.createLabelledCounter( - MetricCategory.NETWORK, + PantheonMetricCategories.NETWORK, "discovery_interaction_retry_count", "Total number of interaction retries performed", "type"); diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetwork.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetwork.java index be9736771d..35325815d7 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetwork.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetwork.java @@ -45,8 +45,8 @@ import tech.pegasys.pantheon.ethereum.permissioning.node.NodePermissioningController; import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.LabelledMetric; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import tech.pegasys.pantheon.util.Subscribers; import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.enode.EnodeURL; @@ -219,7 +219,7 @@ public class DefaultP2PNetwork implements P2PNetwork { outboundMessagesCounter = metricsSystem.createLabelledCounter( - MetricCategory.NETWORK, + PantheonMetricCategories.NETWORK, "p2p_messages_outbound", "Count of each P2P message sent outbound.", "protocol", @@ -227,19 +227,19 @@ public class DefaultP2PNetwork implements P2PNetwork { "code"); metricsSystem.createIntegerGauge( - MetricCategory.NETWORK, + PantheonMetricCategories.NETWORK, "netty_workers_pending_tasks", "The number of pending tasks in the Netty workers event loop", pendingTaskCounter(workers)); metricsSystem.createIntegerGauge( - MetricCategory.NETWORK, + PantheonMetricCategories.NETWORK, "netty_boss_pending_tasks", "The number of pending tasks in the Netty boss event loop", pendingTaskCounter(boss)); metricsSystem.createIntegerGauge( - MetricCategory.NETWORK, + PantheonMetricCategories.NETWORK, "peers_limit", "Maximum P2P peer connections that can be established", () -> maxPeers); diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/netty/PeerConnectionRegistry.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/netty/PeerConnectionRegistry.java index dcd165e371..bf046a3788 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/netty/PeerConnectionRegistry.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/netty/PeerConnectionRegistry.java @@ -19,8 +19,8 @@ import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage.DisconnectReason; import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.LabelledMetric; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import tech.pegasys.pantheon.util.bytes.BytesValue; import java.util.Collection; @@ -38,16 +38,16 @@ public class PeerConnectionRegistry implements DisconnectCallback { public PeerConnectionRegistry(final MetricsSystem metricsSystem) { disconnectCounter = metricsSystem.createLabelledCounter( - MetricCategory.PEERS, + PantheonMetricCategories.PEERS, "disconnected_total", "Total number of peers disconnected", "initiator", "disconnectReason"); connectedPeersCounter = metricsSystem.createCounter( - MetricCategory.PEERS, "connected_total", "Total number of peers connected"); + PantheonMetricCategories.PEERS, "connected_total", "Total number of peers connected"); metricsSystem.createGauge( - MetricCategory.PEERS, + PantheonMetricCategories.PEERS, "peer_count_current", "Number of peers currently connected", () -> (double) connections.size()); diff --git a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/AccountLocalConfigPermissioningController.java b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/AccountLocalConfigPermissioningController.java index 6a3657877d..cd90a49537 100644 --- a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/AccountLocalConfigPermissioningController.java +++ b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/AccountLocalConfigPermissioningController.java @@ -17,8 +17,8 @@ import tech.pegasys.pantheon.ethereum.core.Transaction; import tech.pegasys.pantheon.ethereum.permissioning.account.TransactionPermissioningProvider; import tech.pegasys.pantheon.metrics.Counter; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import tech.pegasys.pantheon.util.bytes.BytesValue; import java.io.IOException; @@ -62,17 +62,17 @@ public AccountLocalConfigPermissioningController( readAccountsFromConfig(configuration); this.checkCounter = metricsSystem.createCounter( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "account_local_check_count", "Number of times the account local permissioning provider has been checked"); this.checkCounterPermitted = metricsSystem.createCounter( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "account_local_check_count_permitted", "Number of times the account local permissioning provider has been checked and returned permitted"); this.checkCounterUnpermitted = metricsSystem.createCounter( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "account_local_check_count_unpermitted", "Number of times the account local permissioning provider has been checked and returned unpermitted"); } diff --git a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/NodeLocalConfigPermissioningController.java b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/NodeLocalConfigPermissioningController.java index 608cc7853d..48cba716ef 100644 --- a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/NodeLocalConfigPermissioningController.java +++ b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/NodeLocalConfigPermissioningController.java @@ -15,8 +15,8 @@ import tech.pegasys.pantheon.ethereum.permissioning.node.NodePermissioningProvider; import tech.pegasys.pantheon.ethereum.permissioning.node.NodeWhitelistUpdatedEvent; import tech.pegasys.pantheon.metrics.Counter; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import tech.pegasys.pantheon.util.Subscribers; import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.enode.EnodeURL; @@ -80,17 +80,17 @@ public NodeLocalConfigPermissioningController( this.checkCounter = metricsSystem.createCounter( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "node_local_check_count", "Number of times the node local permissioning provider has been checked"); this.checkCounterPermitted = metricsSystem.createCounter( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "node_local_check_count_permitted", "Number of times the node local permissioning provider has been checked and returned permitted"); this.checkCounterUnpermitted = metricsSystem.createCounter( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "node_local_check_count_unpermitted", "Number of times the node local permissioning provider has been checked and returned unpermitted"); } diff --git a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/NodeSmartContractPermissioningController.java b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/NodeSmartContractPermissioningController.java index 34187d88b2..ad960dad18 100644 --- a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/NodeSmartContractPermissioningController.java +++ b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/NodeSmartContractPermissioningController.java @@ -21,8 +21,8 @@ import tech.pegasys.pantheon.ethereum.transaction.TransactionSimulator; import tech.pegasys.pantheon.ethereum.transaction.TransactionSimulatorResult; import tech.pegasys.pantheon.metrics.Counter; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.bytes.BytesValues; import tech.pegasys.pantheon.util.enode.EnodeURL; @@ -77,17 +77,17 @@ public NodeSmartContractPermissioningController( this.checkCounter = metricsSystem.createCounter( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "node_smart_contract_check_count", "Number of times the node smart contract permissioning provider has been checked"); this.checkCounterPermitted = metricsSystem.createCounter( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "node_smart_contract_check_count_permitted", "Number of times the node smart contract permissioning provider has been checked and returned permitted"); this.checkCounterUnpermitted = metricsSystem.createCounter( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "node_smart_contract_check_count_unpermitted", "Number of times the node smart contract permissioning provider has been checked and returned unpermitted"); } diff --git a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/TransactionSmartContractPermissioningController.java b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/TransactionSmartContractPermissioningController.java index 9aca2d3e31..f9b69052ca 100644 --- a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/TransactionSmartContractPermissioningController.java +++ b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/TransactionSmartContractPermissioningController.java @@ -23,8 +23,8 @@ import tech.pegasys.pantheon.ethereum.transaction.TransactionSimulator; import tech.pegasys.pantheon.ethereum.transaction.TransactionSimulatorResult; import tech.pegasys.pantheon.metrics.Counter; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.bytes.BytesValues; @@ -84,17 +84,17 @@ public TransactionSmartContractPermissioningController( this.checkCounter = metricsSystem.createCounter( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "transaction_smart_contract_check_count", "Number of times the transaction smart contract permissioning provider has been checked"); this.checkCounterPermitted = metricsSystem.createCounter( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "transaction_smart_contract_check_count_permitted", "Number of times the transaction smart contract permissioning provider has been checked and returned permitted"); this.checkCounterUnpermitted = metricsSystem.createCounter( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "transaction_smart_contract_check_count_unpermitted", "Number of times the transaction smart contract permissioning provider has been checked and returned unpermitted"); } diff --git a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProvider.java b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProvider.java index 8019aa8392..b7152bf975 100644 --- a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProvider.java +++ b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProvider.java @@ -18,8 +18,8 @@ import tech.pegasys.pantheon.ethereum.core.Synchronizer; import tech.pegasys.pantheon.ethereum.permissioning.node.NodePermissioningProvider; import tech.pegasys.pantheon.metrics.Counter; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import tech.pegasys.pantheon.util.enode.EnodeURL; import java.util.Collection; @@ -47,23 +47,23 @@ public SyncStatusNodePermissioningProvider( this.fixedNodes.addAll(fixedNodes); metricsSystem.createIntegerGauge( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "sync_status_node_sync_reached", "Whether the sync status permissioning provider has realised sync yet", () -> hasReachedSync ? 1 : 0); this.checkCounter = metricsSystem.createCounter( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "sync_status_node_check_count", "Number of times the sync status permissioning provider has been checked"); this.checkCounterPermitted = metricsSystem.createCounter( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "sync_status_node_check_count_permitted", "Number of times the sync status permissioning provider has been checked and returned permitted"); this.checkCounterUnpermitted = metricsSystem.createCounter( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "sync_status_node_check_count_unpermitted", "Number of times the sync status permissioning provider has been checked and returned unpermitted"); } diff --git a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/AccountLocalConfigPermissioningControllerTest.java b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/AccountLocalConfigPermissioningControllerTest.java index c0bfb7154c..5ed08c594d 100644 --- a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/AccountLocalConfigPermissioningControllerTest.java +++ b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/AccountLocalConfigPermissioningControllerTest.java @@ -26,8 +26,8 @@ import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.core.Transaction; import tech.pegasys.pantheon.metrics.Counter; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -58,19 +58,19 @@ public class AccountLocalConfigPermissioningControllerTest { public void before() { when(metricsSystem.createCounter( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "account_local_check_count", "Number of times the account local permissioning provider has been checked")) .thenReturn(checkCounter); when(metricsSystem.createCounter( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "account_local_check_count_permitted", "Number of times the account local permissioning provider has been checked and returned permitted")) .thenReturn(checkPermittedCounter); when(metricsSystem.createCounter( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "account_local_check_count_unpermitted", "Number of times the account local permissioning provider has been checked and returned unpermitted")) .thenReturn(checkUnpermittedCounter); diff --git a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/NodeLocalConfigPermissioningControllerTest.java b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/NodeLocalConfigPermissioningControllerTest.java index 568d762a2b..52e4ce0da3 100644 --- a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/NodeLocalConfigPermissioningControllerTest.java +++ b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/NodeLocalConfigPermissioningControllerTest.java @@ -28,8 +28,8 @@ import tech.pegasys.pantheon.ethereum.permissioning.node.NodeWhitelistUpdatedEvent; import tech.pegasys.pantheon.metrics.Counter; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import tech.pegasys.pantheon.util.enode.EnodeURL; import java.io.IOException; @@ -74,19 +74,19 @@ public void setUp() { bootnodesList.clear(); when(metricsSystem.createCounter( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "node_local_check_count", "Number of times the node local permissioning provider has been checked")) .thenReturn(checkCounter); when(metricsSystem.createCounter( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "node_local_check_count_permitted", "Number of times the node local permissioning provider has been checked and returned permitted")) .thenReturn(checkPermittedCounter); when(metricsSystem.createCounter( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "node_local_check_count_unpermitted", "Number of times the node local permissioning provider has been checked and returned unpermitted")) .thenReturn(checkUnpermittedCounter); diff --git a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/NodeSmartContractPermissioningControllerTest.java b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/NodeSmartContractPermissioningControllerTest.java index 2883c4022c..91cf1519ec 100644 --- a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/NodeSmartContractPermissioningControllerTest.java +++ b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/NodeSmartContractPermissioningControllerTest.java @@ -30,8 +30,8 @@ import tech.pegasys.pantheon.ethereum.transaction.TransactionSimulator; import tech.pegasys.pantheon.ethereum.worldstate.WorldStateArchive; import tech.pegasys.pantheon.metrics.Counter; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import tech.pegasys.pantheon.util.enode.EnodeURL; import java.io.IOException; @@ -68,19 +68,19 @@ private NodeSmartContractPermissioningController setupController( final Address contractAddress = Address.fromHexString(contractAddressString); when(metricsSystem.createCounter( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "node_smart_contract_check_count", "Number of times the node smart contract permissioning provider has been checked")) .thenReturn(checkCounter); when(metricsSystem.createCounter( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "node_smart_contract_check_count_permitted", "Number of times the node smart contract permissioning provider has been checked and returned permitted")) .thenReturn(checkPermittedCounter); when(metricsSystem.createCounter( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "node_smart_contract_check_count_unpermitted", "Number of times the node smart contract permissioning provider has been checked and returned unpermitted")) .thenReturn(checkUnpermittedCounter); diff --git a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/TransactionSmartContractPermissioningControllerTest.java b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/TransactionSmartContractPermissioningControllerTest.java index 878f253f56..f3d8c28e47 100644 --- a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/TransactionSmartContractPermissioningControllerTest.java +++ b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/TransactionSmartContractPermissioningControllerTest.java @@ -33,8 +33,8 @@ import tech.pegasys.pantheon.ethereum.transaction.TransactionSimulator; import tech.pegasys.pantheon.ethereum.worldstate.WorldStateArchive; import tech.pegasys.pantheon.metrics.Counter; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import tech.pegasys.pantheon.util.bytes.BytesValue; import java.io.IOException; @@ -72,19 +72,19 @@ private TransactionSmartContractPermissioningController setupController( final Address contractAddress = Address.fromHexString(contractAddressString); when(metricsSystem.createCounter( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "transaction_smart_contract_check_count", "Number of times the transaction smart contract permissioning provider has been checked")) .thenReturn(checkCounter); when(metricsSystem.createCounter( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "transaction_smart_contract_check_count_permitted", "Number of times the transaction smart contract permissioning provider has been checked and returned permitted")) .thenReturn(checkPermittedCounter); when(metricsSystem.createCounter( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "transaction_smart_contract_check_count_unpermitted", "Number of times the transaction smart contract permissioning provider has been checked and returned unpermitted")) .thenReturn(checkUnpermittedCounter); diff --git a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProviderTest.java b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProviderTest.java index 07aa00b16c..b8a551b1b6 100644 --- a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProviderTest.java +++ b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProviderTest.java @@ -23,8 +23,8 @@ import tech.pegasys.pantheon.ethereum.core.Synchronizer; import tech.pegasys.pantheon.ethereum.core.Synchronizer.SyncStatusListener; import tech.pegasys.pantheon.metrics.Counter; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import tech.pegasys.pantheon.util.enode.EnodeURL; import java.util.ArrayList; @@ -74,17 +74,17 @@ public void before() { ArgumentCaptor.forClass(IntSupplier.class); when(metricsSystem.createCounter( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "sync_status_node_check_count", "Number of times the sync status permissioning provider has been checked")) .thenReturn(checkCounter); when(metricsSystem.createCounter( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "sync_status_node_check_count_permitted", "Number of times the sync status permissioning provider has been checked and returned permitted")) .thenReturn(checkPermittedCounter); when(metricsSystem.createCounter( - MetricCategory.PERMISSIONING, + PantheonMetricCategories.PERMISSIONING, "sync_status_node_check_count_unpermitted", "Number of times the sync status permissioning provider has been checked and returned unpermitted")) .thenReturn(checkUnpermittedCounter); @@ -92,7 +92,7 @@ public void before() { this.syncStatusListener = captor.getValue(); verify(metricsSystem) .createIntegerGauge( - eq(MetricCategory.PERMISSIONING), + eq(PantheonMetricCategories.PERMISSIONING), eq("sync_status_node_sync_reached"), eq("Whether the sync status permissioning provider has realised sync yet"), syncGaugeCallbackCaptor.capture()); diff --git a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/MetricCategory.java b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/MetricCategory.java index d2802656c7..868aff7ac3 100644 --- a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/MetricCategory.java +++ b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/MetricCategory.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 ConsenSys AG. + * Copyright 2019 ConsenSys AG. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at @@ -12,44 +12,9 @@ */ package tech.pegasys.pantheon.metrics; -import java.util.EnumSet; -import java.util.Set; +public interface MetricCategory { -public enum MetricCategory { - BLOCKCHAIN("blockchain"), - EXECUTORS("executors"), - JVM("jvm", false), - NETWORK("network"), - PEERS("peers"), - PROCESS("process", false), - PERMISSIONING("permissioning"), - KVSTORE_ROCKSDB("rocksdb"), - KVSTORE_ROCKSDB_STATS("rocksdb", false), - RPC("rpc"), - SYNCHRONIZER("synchronizer"), - TRANSACTION_POOL("transaction_pool"); + String getName(); - // Why not ROCKSDB and KVSTORE_ROCKSDB_STATS? They hurt performance under load. - public static final Set DEFAULT_METRIC_CATEGORIES = - EnumSet.complementOf(EnumSet.of(KVSTORE_ROCKSDB, KVSTORE_ROCKSDB_STATS)); - - private final String name; - private final boolean pantheonSpecific; - - MetricCategory(final String name) { - this(name, true); - } - - MetricCategory(final String name, final boolean pantheonSpecific) { - this.name = name; - this.pantheonSpecific = pantheonSpecific; - } - - public String getName() { - return name; - } - - public boolean isPantheonSpecific() { - return pantheonSpecific; - } + boolean isApplicationSpecific(); } diff --git a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/MetricsSystem.java b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/MetricsSystem.java index b444af6a32..d4364daa3c 100644 --- a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/MetricsSystem.java +++ b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/MetricsSystem.java @@ -55,7 +55,5 @@ default void createLongGauge( Stream streamObservations(MetricCategory category); - default Stream streamObservations() { - return Stream.of(MetricCategory.values()).flatMap(this::streamObservations); - } + Stream streamObservations(); } diff --git a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/PantheonMetricCategories.java b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/PantheonMetricCategories.java new file mode 100644 index 0000000000..7d2fec7e6b --- /dev/null +++ b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/PantheonMetricCategories.java @@ -0,0 +1,67 @@ +/* + * Copyright 2018 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.metrics; + +import java.util.EnumSet; +import java.util.Set; + +import com.google.common.collect.ImmutableSet; + +public enum PantheonMetricCategories implements MetricCategory { + BLOCKCHAIN("blockchain"), + EXECUTORS("executors"), + NETWORK("network"), + PEERS("peers"), + PERMISSIONING("permissioning"), + KVSTORE_ROCKSDB("rocksdb"), + KVSTORE_ROCKSDB_STATS("rocksdb", false), + RPC("rpc"), + SYNCHRONIZER("synchronizer"), + TRANSACTION_POOL("transaction_pool"); + + public static final Set DEFAULT_METRIC_CATEGORIES; + + static { + // Why not ROCKSDB and KVSTORE_ROCKSDB_STATS? They hurt performance under load. + final EnumSet pantheonCategories = + EnumSet.complementOf(EnumSet.of(KVSTORE_ROCKSDB, KVSTORE_ROCKSDB_STATS)); + + DEFAULT_METRIC_CATEGORIES = + ImmutableSet.builder() + .addAll(pantheonCategories) + .addAll(EnumSet.allOf(StandardMetricCategories.class)) + .build(); + } + + private final String name; + private final boolean pantheonSpecific; + + PantheonMetricCategories(final String name) { + this(name, true); + } + + PantheonMetricCategories(final String name, final boolean pantheonSpecific) { + this.name = name; + this.pantheonSpecific = pantheonSpecific; + } + + @Override + public String getName() { + return name; + } + + @Override + public boolean isApplicationSpecific() { + return pantheonSpecific; + } +} diff --git a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/StandardMetricCategories.java b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/StandardMetricCategories.java new file mode 100644 index 0000000000..0df0ddd586 --- /dev/null +++ b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/StandardMetricCategories.java @@ -0,0 +1,34 @@ +/* + * Copyright 2019 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.metrics; + +public enum StandardMetricCategories implements MetricCategory { + JVM("jvm"), + PROCESS("process"); + + private final String name; + + StandardMetricCategories(final String name) { + this.name = name; + } + + @Override + public String getName() { + return name; + } + + @Override + public boolean isApplicationSpecific() { + return false; + } +} diff --git a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsConfiguration.java b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsConfiguration.java index 3e38c2302e..5467032362 100644 --- a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsConfiguration.java +++ b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsConfiguration.java @@ -12,7 +12,7 @@ */ package tech.pegasys.pantheon.metrics.prometheus; -import static tech.pegasys.pantheon.metrics.MetricCategory.DEFAULT_METRIC_CATEGORIES; +import static tech.pegasys.pantheon.metrics.PantheonMetricCategories.DEFAULT_METRIC_CATEGORIES; import tech.pegasys.pantheon.metrics.MetricCategory; @@ -23,6 +23,8 @@ import java.util.Objects; import java.util.Set; +import com.google.common.base.MoreObjects; + public class MetricsConfiguration { private static final String DEFAULT_METRICS_HOST = "127.0.0.1"; public static final int DEFAULT_METRICS_PORT = 9545; @@ -40,6 +42,7 @@ public class MetricsConfiguration { private final int pushInterval; private final String prometheusJob; private final List hostsWhitelist; + private final String applicationPrefix; public static MetricsConfiguration createDefault() { return builder().build(); @@ -59,7 +62,8 @@ private MetricsConfiguration( final String pushHost, final int pushInterval, final String prometheusJob, - final List hostsWhitelist) { + final List hostsWhitelist, + final String applicationPrefix) { this.enabled = enabled; this.port = port; this.host = host; @@ -70,6 +74,7 @@ private MetricsConfiguration( this.pushInterval = pushInterval; this.prometheusJob = prometheusJob; this.hostsWhitelist = hostsWhitelist; + this.applicationPrefix = applicationPrefix; } public boolean isEnabled() { @@ -112,50 +117,47 @@ Collection getHostsWhitelist() { return Collections.unmodifiableCollection(this.hostsWhitelist); } + public String getApplicationPrefix() { + return applicationPrefix; + } + @Override public String toString() { - return "MetricsConfiguration{" - + "enabled=" - + enabled - + ", port=" - + port - + ", host='" - + host - + '\'' - + ", categories=" - + metricCategories.toString() - + ", pushEnabled=" - + pushEnabled - + ", pushPort=" - + pushPort - + ", pushHost='" - + pushHost - + '\'' - + ", pushInterval=" - + pushInterval - + ", prometheusJob='" - + prometheusJob - + '\'' - + ", hostsWhitelist=" - + hostsWhitelist - + '}'; + return MoreObjects.toStringHelper(this) + .add("enabled", enabled) + .add("port", port) + .add("host", host) + .add("metricCategories", metricCategories) + .add("pushEnabled", pushEnabled) + .add("pushPort", pushPort) + .add("pushHost", pushHost) + .add("pushInterval", pushInterval) + .add("prometheusJob", prometheusJob) + .add("hostsWhitelist", hostsWhitelist) + .add("applicationPrefix", applicationPrefix) + .toString(); } @Override public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } final MetricsConfiguration that = (MetricsConfiguration) o; return enabled == that.enabled && port == that.port - && Objects.equals(metricCategories, that.metricCategories) && pushEnabled == that.pushEnabled && pushPort == that.pushPort && pushInterval == that.pushInterval && Objects.equals(host, that.host) + && Objects.equals(metricCategories, that.metricCategories) && Objects.equals(pushHost, that.pushHost) && Objects.equals(prometheusJob, that.prometheusJob) - && Objects.equals(hostsWhitelist, that.hostsWhitelist); + && Objects.equals(hostsWhitelist, that.hostsWhitelist) + && Objects.equals(applicationPrefix, that.applicationPrefix); } @Override @@ -170,7 +172,8 @@ public int hashCode() { pushHost, pushInterval, prometheusJob, - hostsWhitelist); + hostsWhitelist, + applicationPrefix); } public static class Builder { @@ -184,6 +187,7 @@ public static class Builder { private int pushInterval = 15; private String prometheusJob = "pantheon-client"; private List hostsWhitelist = Arrays.asList("localhost", "127.0.0.1"); + private String applicationPrefix = ""; private Builder() {} @@ -237,6 +241,11 @@ public Builder hostsWhitelist(final List hostsWhitelist) { return this; } + public Builder applicationPrefix(final String applicationPrefix) { + this.applicationPrefix = applicationPrefix; + return this; + } + public MetricsConfiguration build() { return new MetricsConfiguration( enabled, @@ -248,7 +257,8 @@ public MetricsConfiguration build() { pushHost, pushInterval, prometheusJob, - hostsWhitelist); + hostsWhitelist, + applicationPrefix); } } } diff --git a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystem.java b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystem.java index aa77463249..e2ba5c98d8 100644 --- a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystem.java +++ b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystem.java @@ -20,6 +20,7 @@ import tech.pegasys.pantheon.metrics.MetricsSystem; import tech.pegasys.pantheon.metrics.Observation; import tech.pegasys.pantheon.metrics.OperationTimer; +import tech.pegasys.pantheon.metrics.StandardMetricCategories; import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; import java.util.ArrayList; @@ -49,7 +50,6 @@ public class PrometheusMetricsSystem implements MetricsSystem { - private static final String PANTHEON_PREFIX = "pantheon_"; private final Map> collectors = new ConcurrentHashMap<>(); private final CollectorRegistry registry = new CollectorRegistry(true); private final Map> cachedCounters = @@ -58,9 +58,12 @@ public class PrometheusMetricsSystem implements MetricsSystem { cachedTimers = new ConcurrentHashMap<>(); private final Set enabledCategories; + private final String applicationPrefix; - PrometheusMetricsSystem(final Set enabledCategories) { + PrometheusMetricsSystem( + final Set enabledCategories, final String applicationPrefix) { this.enabledCategories = ImmutableSet.copyOf(enabledCategories); + this.applicationPrefix = applicationPrefix; } public static MetricsSystem init(final MetricsConfiguration metricsConfiguration) { @@ -68,15 +71,17 @@ public static MetricsSystem init(final MetricsConfiguration metricsConfiguration return new NoOpMetricsSystem(); } final PrometheusMetricsSystem metricsSystem = - new PrometheusMetricsSystem(metricsConfiguration.getMetricCategories()); - if (metricsSystem.isCategoryEnabled(MetricCategory.PROCESS)) { + new PrometheusMetricsSystem( + metricsConfiguration.getMetricCategories(), + metricsConfiguration.getApplicationPrefix()); + if (metricsSystem.isCategoryEnabled(StandardMetricCategories.PROCESS)) { metricsSystem.collectors.put( - MetricCategory.PROCESS, + StandardMetricCategories.PROCESS, singleton(new StandardExports().register(metricsSystem.registry))); } - if (metricsSystem.isCategoryEnabled(MetricCategory.JVM)) { + if (metricsSystem.isCategoryEnabled(StandardMetricCategories.JVM)) { metricsSystem.collectors.put( - MetricCategory.JVM, + StandardMetricCategories.JVM, asList( new MemoryPoolsExports().register(metricsSystem.registry), new BufferPoolsExports().register(metricsSystem.registry), @@ -173,6 +178,11 @@ public Stream streamObservations(final MetricCategory category) { .flatMap(familySamples -> convertSamplesToObservations(category, familySamples)); } + @Override + public Stream streamObservations() { + return collectors.keySet().stream().flatMap(this::streamObservations); + } + private Stream convertSamplesToObservations( final MetricCategory category, final MetricFamilySamples familySamples) { return familySamples.samples.stream() @@ -226,7 +236,7 @@ private Observation convertSummarySampleNamesToLabels( labelValues); } - public static String convertToPrometheusName(final MetricCategory category, final String name) { + public String convertToPrometheusName(final MetricCategory category, final String name) { return prometheusPrefix(category) + name; } @@ -235,9 +245,9 @@ private String convertFromPrometheusName(final MetricCategory category, final St return metricName.startsWith(prefix) ? metricName.substring(prefix.length()) : metricName; } - private static String prometheusPrefix(final MetricCategory category) { - return category.isPantheonSpecific() - ? PANTHEON_PREFIX + category.getName() + "_" + private String prometheusPrefix(final MetricCategory category) { + return category.isApplicationSpecific() + ? applicationPrefix + category.getName() + "_" : category.getName() + "_"; } diff --git a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/vertx/PoolMetricsAdapter.java b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/vertx/PoolMetricsAdapter.java index 9fb778da96..d9c6ff5474 100644 --- a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/vertx/PoolMetricsAdapter.java +++ b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/vertx/PoolMetricsAdapter.java @@ -13,8 +13,8 @@ package tech.pegasys.pantheon.metrics.vertx; import tech.pegasys.pantheon.metrics.Counter; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import io.vertx.core.spi.metrics.PoolMetrics; @@ -29,7 +29,7 @@ public PoolMetricsAdapter( submittedCounter = metricsSystem .createLabelledCounter( - MetricCategory.NETWORK, + PantheonMetricCategories.NETWORK, "vertx_worker_pool_submitted_total", "Total number of tasks submitted to the Vertx worker pool", "poolType", @@ -39,7 +39,7 @@ public PoolMetricsAdapter( completedCounter = metricsSystem .createLabelledCounter( - MetricCategory.NETWORK, + PantheonMetricCategories.NETWORK, "vertx_worker_pool_completed_total", "Total number of tasks completed by the Vertx worker pool", "poolType", @@ -49,7 +49,7 @@ public PoolMetricsAdapter( rejectedCounter = metricsSystem .createLabelledCounter( - MetricCategory.NETWORK, + PantheonMetricCategories.NETWORK, "vertx_worker_pool_rejected_total", "Total number of tasks rejected by the Vertx worker pool", "poolType", diff --git a/metrics/core/src/test-support/java/tech/pegasys/pantheon/metrics/StubMetricsSystem.java b/metrics/core/src/test-support/java/tech/pegasys/pantheon/metrics/StubMetricsSystem.java index 23b9fa8544..cd6c08ab5d 100644 --- a/metrics/core/src/test-support/java/tech/pegasys/pantheon/metrics/StubMetricsSystem.java +++ b/metrics/core/src/test-support/java/tech/pegasys/pantheon/metrics/StubMetricsSystem.java @@ -79,6 +79,11 @@ public Stream streamObservations(final MetricCategory category) { throw new UnsupportedOperationException("Observations aren't actually recorded"); } + @Override + public Stream streamObservations() { + throw new UnsupportedOperationException("Observations aren't actually recorded"); + } + public static class StubLabelledCounter implements LabelledMetric { private final Map, StubCounter> metrics = new HashMap<>(); diff --git a/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/noop/NoOpMetricsSystemTest.java b/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/noop/NoOpMetricsSystemTest.java index e35497ad23..77f526e406 100644 --- a/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/noop/NoOpMetricsSystemTest.java +++ b/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/noop/NoOpMetricsSystemTest.java @@ -17,9 +17,9 @@ import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.LabelledMetric; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; import tech.pegasys.pantheon.metrics.OperationTimer; +import tech.pegasys.pantheon.metrics.StandardMetricCategories; import org.junit.Test; @@ -30,7 +30,8 @@ public class NoOpMetricsSystemTest { @Test public void labelCountsMatchOnCounter() { final LabelledMetric labeledCounter = - metricsSystem.createLabelledCounter(MetricCategory.PROCESS, "name", "help", "label1"); + metricsSystem.createLabelledCounter( + StandardMetricCategories.PROCESS, "name", "help", "label1"); assertThat(labeledCounter.labels("one")).isSameAs(NoOpMetricsSystem.NO_OP_COUNTER); } @@ -38,7 +39,7 @@ public void labelCountsMatchOnCounter() { public void failsWheLabelCountsDoNotMatchOnCounter() { final LabelledMetric labeledCounter = metricsSystem.createLabelledCounter( - MetricCategory.PROCESS, "name", "help", "label1", "label2"); + StandardMetricCategories.PROCESS, "name", "help", "label1", "label2"); assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> labeledCounter.labels("one")) @@ -51,7 +52,8 @@ public void failsWheLabelCountsDoNotMatchOnCounter() { @Test public void labelCountsMatchOnTimer() { final LabelledMetric labeledTimer = - metricsSystem.createLabelledTimer(MetricCategory.PROCESS, "name", "help", "label1"); + metricsSystem.createLabelledTimer( + StandardMetricCategories.PROCESS, "name", "help", "label1"); assertThat(labeledTimer.labels("one")).isSameAs(NoOpMetricsSystem.NO_OP_OPERATION_TIMER); } @@ -59,7 +61,7 @@ public void labelCountsMatchOnTimer() { public void failsWheLabelCountsDoNotMatchOnTimer() { final LabelledMetric labeledTimer = metricsSystem.createLabelledTimer( - MetricCategory.PROCESS, "name", "help", "label1", "label2"); + StandardMetricCategories.PROCESS, "name", "help", "label1", "label2"); assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> labeledTimer.labels("one")) diff --git a/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystemTest.java b/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystemTest.java index 57e264f9bb..8630defa87 100644 --- a/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystemTest.java +++ b/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystemTest.java @@ -17,33 +17,35 @@ import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static tech.pegasys.pantheon.metrics.MetricCategory.JVM; -import static tech.pegasys.pantheon.metrics.MetricCategory.NETWORK; -import static tech.pegasys.pantheon.metrics.MetricCategory.PEERS; -import static tech.pegasys.pantheon.metrics.MetricCategory.RPC; +import static tech.pegasys.pantheon.metrics.PantheonMetricCategories.DEFAULT_METRIC_CATEGORIES; +import static tech.pegasys.pantheon.metrics.PantheonMetricCategories.NETWORK; +import static tech.pegasys.pantheon.metrics.PantheonMetricCategories.PEERS; +import static tech.pegasys.pantheon.metrics.PantheonMetricCategories.RPC; +import static tech.pegasys.pantheon.metrics.StandardMetricCategories.JVM; import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.LabelledMetric; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; import tech.pegasys.pantheon.metrics.Observation; import tech.pegasys.pantheon.metrics.OperationTimer; import tech.pegasys.pantheon.metrics.OperationTimer.TimingContext; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; import java.util.Comparator; -import java.util.EnumSet; +import com.google.common.collect.ImmutableSet; import org.junit.Test; public class PrometheusMetricsSystemTest { private static final Comparator IGNORE_VALUES = - Comparator.comparing(Observation::getCategory) + Comparator.comparing(observation -> observation.getCategory().getName()) .thenComparing(Observation::getMetricName) .thenComparing((o1, o2) -> o1.getLabels().equals(o2.getLabels()) ? 0 : 1); - private final MetricsSystem metricsSystem = new PrometheusMetricsSystem(); + private final MetricsSystem metricsSystem = + new PrometheusMetricsSystem(DEFAULT_METRIC_CATEGORIES, "pantheon_"); @Test public void shouldCreateObservationFromCounter() { @@ -175,7 +177,7 @@ public void shouldNotAllowDuplicateGaugeCreation() { public void shouldOnlyObserveEnabledMetrics() { final MetricsConfiguration metricsConfiguration = MetricsConfiguration.builder() - .metricCategories(EnumSet.of(MetricCategory.RPC)) + .metricCategories(ImmutableSet.of(PantheonMetricCategories.RPC)) .enabled(true) .build(); final MetricsSystem localMetricSystem = PrometheusMetricsSystem.init(metricsConfiguration); diff --git a/metrics/rocksdb/src/main/java/tech/pegasys/pantheon/metrics/rocksdb/RocksDBStats.java b/metrics/rocksdb/src/main/java/tech/pegasys/pantheon/metrics/rocksdb/RocksDBStats.java index 9853b366cd..344255090e 100644 --- a/metrics/rocksdb/src/main/java/tech/pegasys/pantheon/metrics/rocksdb/RocksDBStats.java +++ b/metrics/rocksdb/src/main/java/tech/pegasys/pantheon/metrics/rocksdb/RocksDBStats.java @@ -12,7 +12,7 @@ */ package tech.pegasys.pantheon.metrics.rocksdb; -import static tech.pegasys.pantheon.metrics.MetricCategory.KVSTORE_ROCKSDB_STATS; +import static tech.pegasys.pantheon.metrics.PantheonMetricCategories.KVSTORE_ROCKSDB_STATS; import tech.pegasys.pantheon.metrics.prometheus.PrometheusMetricsSystem; @@ -187,8 +187,7 @@ private static Collector histogramToCollector( final Statistics stats, final HistogramType histogram) { return new Collector() { final String metricName = - PrometheusMetricsSystem.convertToPrometheusName( - KVSTORE_ROCKSDB_STATS, histogram.name().toLowerCase()); + KVSTORE_ROCKSDB_STATS.getName() + "_" + histogram.name().toLowerCase(); @Override public List collect() { diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java index 18e2f17121..16a6c531bd 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -24,7 +24,7 @@ import static tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.DEFAULT_JSON_RPC_PORT; import static tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis.DEFAULT_JSON_RPC_APIS; import static tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration.DEFAULT_WEBSOCKET_PORT; -import static tech.pegasys.pantheon.metrics.MetricCategory.DEFAULT_METRIC_CATEGORIES; +import static tech.pegasys.pantheon.metrics.PantheonMetricCategories.DEFAULT_METRIC_CATEGORIES; import static tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration.DEFAULT_METRICS_PORT; import static tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration.DEFAULT_METRICS_PUSH_PORT; @@ -68,6 +68,8 @@ import tech.pegasys.pantheon.ethereum.transaction.TransactionSimulator; import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.StandardMetricCategories; import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration; import tech.pegasys.pantheon.metrics.prometheus.PrometheusMetricsSystem; import tech.pegasys.pantheon.metrics.vertx.VertxMetricsAdapterFactory; @@ -655,6 +657,15 @@ public void parse( commandLine.registerConverter(UInt256.class, (arg) -> UInt256.of(new BigInteger(arg))); commandLine.registerConverter(Wei.class, (arg) -> Wei.of(Long.parseUnsignedLong(arg))); commandLine.registerConverter(PositiveNumber.class, PositiveNumber::fromString); + commandLine.registerConverter( + MetricCategory.class, + arg -> { + try { + return PantheonMetricCategories.valueOf(arg); + } catch (final IllegalArgumentException e) { + return StandardMetricCategories.valueOf(arg); + } + }); // Add performance options UnstableOptionsSubCommand.createUnstableOptions( @@ -1000,6 +1011,7 @@ MetricsConfiguration metricsConfiguration() { .pushInterval(metricsPushInterval) .hostsWhitelist(hostsWhitelist) .prometheusJob(metricsPrometheusJob) + .applicationPrefix("pantheon_") .build(); } diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java index 3d377cf485..37a8ea90f4 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java @@ -50,7 +50,7 @@ import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; import tech.pegasys.pantheon.ethereum.permissioning.SmartContractPermissioningConfiguration; import tech.pegasys.pantheon.ethereum.permissioning.account.AccountPermissioningController; -import tech.pegasys.pantheon.metrics.MetricCategory; +import tech.pegasys.pantheon.metrics.StandardMetricCategories; import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration; import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.enode.EnodeURL; @@ -107,6 +107,8 @@ public class PantheonCommandTest extends CommandTestAbstract { "enode://" + VALID_NODE_ID + "@192.168.0.3:4567" }; + private static final String APPLICATION_PREFIX = "pantheon_"; + static { defaultJsonRpcConfiguration = JsonRpcConfiguration.createDefault(); @@ -114,7 +116,8 @@ public class PantheonCommandTest extends CommandTestAbstract { defaultWebSocketConfiguration = WebSocketConfiguration.createDefault(); - defaultMetricsConfiguration = MetricsConfiguration.createDefault(); + defaultMetricsConfiguration = + MetricsConfiguration.builder().applicationPrefix(APPLICATION_PREFIX).build(); } @Test @@ -300,7 +303,12 @@ public void overrideDefaultValuesIfKeyIsPresentInConfigFile() throws IOException webSocketConfiguration.setRpcApis(expectedApis); final MetricsConfiguration metricsConfiguration = - MetricsConfiguration.builder().enabled(false).host("8.6.7.5").port(309).build(); + MetricsConfiguration.builder() + .enabled(false) + .host("8.6.7.5") + .port(309) + .applicationPrefix(APPLICATION_PREFIX) + .build(); parseCommand("--config-file", toml.toString()); @@ -686,7 +694,8 @@ public void noOverrideDefaultValuesIfKeyIsNotPresentInConfigFile() throws IOExce final WebSocketConfiguration webSocketConfiguration = WebSocketConfiguration.createDefault(); - final MetricsConfiguration metricsConfiguration = MetricsConfiguration.createDefault(); + final MetricsConfiguration metricsConfiguration = + MetricsConfiguration.builder().applicationPrefix(APPLICATION_PREFIX).build(); verify(mockRunnerBuilder).discovery(eq(true)); verify(mockRunnerBuilder) @@ -2041,13 +2050,14 @@ public void metricsHostMayBeIPv6() { @Test public void metricsCategoryPropertyMustBeUsed() { - parseCommand("--metrics-enabled", "--metrics-category", MetricCategory.JVM.toString()); + parseCommand( + "--metrics-enabled", "--metrics-category", StandardMetricCategories.JVM.toString()); verify(mockRunnerBuilder).metricsConfiguration(metricsConfigArgumentCaptor.capture()); verify(mockRunnerBuilder).build(); assertThat(metricsConfigArgumentCaptor.getValue().getMetricCategories()) - .containsExactly(MetricCategory.JVM); + .containsExactly(StandardMetricCategories.JVM); assertThat(commandOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty(); diff --git a/services/kvstore/src/main/java/tech/pegasys/pantheon/services/kvstore/RocksDbKeyValueStorage.java b/services/kvstore/src/main/java/tech/pegasys/pantheon/services/kvstore/RocksDbKeyValueStorage.java index a16a1fb5cd..8275c51791 100644 --- a/services/kvstore/src/main/java/tech/pegasys/pantheon/services/kvstore/RocksDbKeyValueStorage.java +++ b/services/kvstore/src/main/java/tech/pegasys/pantheon/services/kvstore/RocksDbKeyValueStorage.java @@ -13,9 +13,9 @@ package tech.pegasys.pantheon.services.kvstore; import tech.pegasys.pantheon.metrics.Counter; -import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; import tech.pegasys.pantheon.metrics.OperationTimer; +import tech.pegasys.pantheon.metrics.PantheonMetricCategories; import tech.pegasys.pantheon.metrics.prometheus.PrometheusMetricsSystem; import tech.pegasys.pantheon.metrics.rocksdb.RocksDBStats; import tech.pegasys.pantheon.services.util.RocksDbUtil; @@ -76,7 +76,7 @@ private RocksDbKeyValueStorage( readLatency = metricsSystem .createLabelledTimer( - MetricCategory.KVSTORE_ROCKSDB, + PantheonMetricCategories.KVSTORE_ROCKSDB, "read_latency_seconds", "Latency for read from RocksDB.", "database") @@ -84,7 +84,7 @@ private RocksDbKeyValueStorage( removeLatency = metricsSystem .createLabelledTimer( - MetricCategory.KVSTORE_ROCKSDB, + PantheonMetricCategories.KVSTORE_ROCKSDB, "remove_latency_seconds", "Latency of remove requests from RocksDB.", "database") @@ -92,7 +92,7 @@ private RocksDbKeyValueStorage( writeLatency = metricsSystem .createLabelledTimer( - MetricCategory.KVSTORE_ROCKSDB, + PantheonMetricCategories.KVSTORE_ROCKSDB, "write_latency_seconds", "Latency for write to RocksDB.", "database") @@ -100,7 +100,7 @@ private RocksDbKeyValueStorage( commitLatency = metricsSystem .createLabelledTimer( - MetricCategory.KVSTORE_ROCKSDB, + PantheonMetricCategories.KVSTORE_ROCKSDB, "commit_latency_seconds", "Latency for commits to RocksDB.", "database") @@ -111,7 +111,7 @@ private RocksDbKeyValueStorage( } metricsSystem.createLongGauge( - MetricCategory.KVSTORE_ROCKSDB, + PantheonMetricCategories.KVSTORE_ROCKSDB, "rocks_db_table_readers_memory_bytes", "Estimated memory used for RocksDB index and filter blocks in bytes", () -> { @@ -126,7 +126,7 @@ private RocksDbKeyValueStorage( rollbackCount = metricsSystem .createLabelledCounter( - MetricCategory.KVSTORE_ROCKSDB, + PantheonMetricCategories.KVSTORE_ROCKSDB, "rollback_count", "Number of RocksDB transactions rolled back.", "database") From 0cc868c49bce60587eccc47b93cb27ae69d6838d Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Tue, 11 Jun 2019 14:07:10 +1000 Subject: [PATCH 05/11] Move to a map of valid metric categories for the command line. Sets things up so plugins can register their own metric categories in the future. --- .../chain/DefaultMutableBlockchain.java | 8 +++--- .../ethereum/eth/manager/EthPeers.java | 4 +-- .../eth/manager/MonitoredExecutors.java | 14 +++++----- .../eth/manager/task/AbstractEthTask.java | 4 +-- .../eth/sync/DefaultSynchronizer.java | 6 ++--- .../eth/sync/PipelineChainDownloader.java | 4 +-- .../sync/fastsync/FastDownloaderFactory.java | 6 ++--- .../eth/sync/fastsync/FastSyncActions.java | 6 ++--- .../FastSyncDownloadPipelineFactory.java | 6 ++--- .../FullSyncDownloadPipelineFactory.java | 4 +-- .../eth/sync/worldstate/CompleteTaskStep.java | 6 ++--- .../sync/worldstate/LoadLocalDataStep.java | 4 +-- .../worldstate/WorldStateDownloadProcess.java | 4 +-- .../sync/worldstate/WorldStateDownloader.java | 6 ++--- .../eth/transactions/PendingTransactions.java | 6 ++--- .../ethereum/jsonrpc/JsonRpcHttpService.java | 4 +-- .../subscription/SubscriptionManager.java | 6 ++--- .../internal/methods/DebugMetricsTest.java | 4 +-- .../pantheon/ethereum/p2p/NetworkRunner.java | 4 +-- .../discovery/VertxPeerDiscoveryAgent.java | 4 +-- .../internal/DiscoveryProtocolLogger.java | 6 ++--- .../internal/PeerDiscoveryController.java | 8 +++--- .../p2p/network/DefaultP2PNetwork.java | 10 +++---- .../network/netty/PeerConnectionRegistry.java | 8 +++--- ...untLocalConfigPermissioningController.java | 8 +++--- ...odeLocalConfigPermissioningController.java | 8 +++--- ...eSmartContractPermissioningController.java | 8 +++--- ...nSmartContractPermissioningController.java | 8 +++--- .../SyncStatusNodePermissioningProvider.java | 10 +++---- ...ocalConfigPermissioningControllerTest.java | 8 +++--- ...ocalConfigPermissioningControllerTest.java | 8 +++--- ...rtContractPermissioningControllerTest.java | 8 +++--- ...rtContractPermissioningControllerTest.java | 8 +++--- ...ncStatusNodePermissioningProviderTest.java | 10 +++---- ...ories.java => PantheonMetricCategory.java} | 10 +++---- ...ories.java => StandardMetricCategory.java} | 4 +-- .../prometheus/MetricsConfiguration.java | 2 +- .../prometheus/PrometheusMetricsSystem.java | 10 +++---- .../metrics/vertx/PoolMetricsAdapter.java | 8 +++--- .../metrics/noop/NoOpMetricsSystemTest.java | 11 ++++---- .../PrometheusMetricsSystemTest.java | 14 +++++----- .../metrics/rocksdb/RocksDBStats.java | 2 +- .../pegasys/pantheon/cli/PantheonCommand.java | 26 ++++++++++++++----- .../pantheon/cli/PantheonCommandTest.java | 7 +++-- .../kvstore/RocksDbKeyValueStorage.java | 14 +++++----- 45 files changed, 172 insertions(+), 162 deletions(-) rename metrics/core/src/main/java/tech/pegasys/pantheon/metrics/{PantheonMetricCategories.java => PantheonMetricCategory.java} (84%) rename metrics/core/src/main/java/tech/pegasys/pantheon/metrics/{StandardMetricCategories.java => StandardMetricCategory.java} (88%) diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/chain/DefaultMutableBlockchain.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/chain/DefaultMutableBlockchain.java index 88f4b2f764..c055a65596 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/chain/DefaultMutableBlockchain.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/chain/DefaultMutableBlockchain.java @@ -24,7 +24,7 @@ import tech.pegasys.pantheon.ethereum.core.Transaction; import tech.pegasys.pantheon.ethereum.core.TransactionReceipt; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.util.InvalidConfigurationException; import tech.pegasys.pantheon.util.Subscribers; import tech.pegasys.pantheon.util.bytes.BytesValues; @@ -64,12 +64,12 @@ public DefaultMutableBlockchain( totalDifficulty = blockchainStorage.getTotalDifficulty(chainHead).get(); metricsSystem.createLongGauge( - PantheonMetricCategories.BLOCKCHAIN, + PantheonMetricCategory.BLOCKCHAIN, "height", "Height of the chainhead", this::getChainHeadBlockNumber); metricsSystem.createLongGauge( - PantheonMetricCategories.BLOCKCHAIN, + PantheonMetricCategory.BLOCKCHAIN, "difficulty_total", "Total difficulty of the chainhead", () -> @@ -77,7 +77,7 @@ public DefaultMutableBlockchain( .longValue()); metricsSystem.createLongGauge( - PantheonMetricCategories.BLOCKCHAIN, + PantheonMetricCategory.BLOCKCHAIN, "chain_head_timestamp", "Timestamp from the current chain head", () -> getChainHeadHeader().getTimestamp()); diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/EthPeers.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/EthPeers.java index a2aa978226..46e9c7498d 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/EthPeers.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/EthPeers.java @@ -15,7 +15,7 @@ import tech.pegasys.pantheon.ethereum.eth.manager.EthPeer.DisconnectCallback; import tech.pegasys.pantheon.ethereum.p2p.api.PeerConnection; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.util.Subscribers; import java.time.Clock; @@ -53,7 +53,7 @@ public EthPeers(final String protocolName, final Clock clock, final MetricsSyste this.protocolName = protocolName; this.clock = clock; metricsSystem.createIntegerGauge( - PantheonMetricCategories.PEERS, + PantheonMetricCategory.PEERS, "pending_peer_requests_current", "Number of peer requests currently pending because peers are busy", pendingRequests::size); diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/MonitoredExecutors.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/MonitoredExecutors.java index 49e58c677f..8a5f0cf91b 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/MonitoredExecutors.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/MonitoredExecutors.java @@ -14,7 +14,7 @@ import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import java.util.Locale; import java.util.concurrent.ExecutorService; @@ -87,31 +87,31 @@ private static T newMonitoredExecutor( new ThreadFactoryBuilder().setNameFormat(name + "-%d").build()); metricsSystem.createIntegerGauge( - PantheonMetricCategories.EXECUTORS, + PantheonMetricCategory.EXECUTORS, metricName + "_queue_length_current", "Current number of tasks awaiting execution", executor.getQueue()::size); metricsSystem.createIntegerGauge( - PantheonMetricCategories.EXECUTORS, + PantheonMetricCategory.EXECUTORS, metricName + "_active_threads_current", "Current number of threads executing tasks", executor::getActiveCount); metricsSystem.createIntegerGauge( - PantheonMetricCategories.EXECUTORS, + PantheonMetricCategory.EXECUTORS, metricName + "_pool_size_current", "Current number of threads in the thread pool", executor::getPoolSize); metricsSystem.createLongGauge( - PantheonMetricCategories.EXECUTORS, + PantheonMetricCategory.EXECUTORS, metricName + "_completed_tasks_total", "Total number of tasks executed", executor::getCompletedTaskCount); metricsSystem.createLongGauge( - PantheonMetricCategories.EXECUTORS, + PantheonMetricCategory.EXECUTORS, metricName + "_submitted_tasks_total", "Total number of tasks executed", executor::getTaskCount); @@ -126,7 +126,7 @@ private static class CountingAbortPolicy extends AbortPolicy { public CountingAbortPolicy(final String metricName, final MetricsSystem metricsSystem) { this.rejectedTaskCounter = metricsSystem.createCounter( - PantheonMetricCategories.EXECUTORS, + PantheonMetricCategory.EXECUTORS, metricName + "_rejected_tasks_total", "Total number of tasks rejected by this executor"); } diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/task/AbstractEthTask.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/task/AbstractEthTask.java index 0eb87d189e..dc4315dc71 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/task/AbstractEthTask.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/task/AbstractEthTask.java @@ -18,7 +18,7 @@ import tech.pegasys.pantheon.metrics.LabelledMetric; import tech.pegasys.pantheon.metrics.MetricsSystem; import tech.pegasys.pantheon.metrics.OperationTimer; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; import java.util.Collection; @@ -50,7 +50,7 @@ protected AbstractEthTask(final OperationTimer taskTimer) { private static OperationTimer buildOperationTimer(final MetricsSystem metricsSystem) { final LabelledMetric ethTasksTimer = metricsSystem.createLabelledTimer( - PantheonMetricCategories.SYNCHRONIZER, "task", "Internal processing tasks", "taskName"); + PantheonMetricCategory.SYNCHRONIZER, "task", "Internal processing tasks", "taskName"); if (ethTasksTimer == NoOpMetricsSystem.NO_OP_LABELLED_1_OPERATION_TIMER) { return () -> new OperationTimer.TimingContext() { diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java index 65c3c17fd3..37a22bc4e4 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java @@ -28,7 +28,7 @@ import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; import tech.pegasys.pantheon.ethereum.worldstate.WorldStateStorage; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.util.ExceptionUtils; import tech.pegasys.pantheon.util.Subscribers; @@ -98,12 +98,12 @@ public DefaultSynchronizer( clock); metricsSystem.createLongGauge( - PantheonMetricCategories.SYNCHRONIZER, + PantheonMetricCategory.SYNCHRONIZER, "best_known_block", "Height of best known block from any connected peer", () -> syncState.syncStatus().getHighestBlock()); metricsSystem.createIntegerGauge( - PantheonMetricCategories.SYNCHRONIZER, + PantheonMetricCategory.SYNCHRONIZER, "in_sync", "Whether or not the local node has caught up to the best known peer", () -> getSyncStatus().isPresent() ? 0 : 1); diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/PipelineChainDownloader.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/PipelineChainDownloader.java index e00deb24b3..6e1cc4379c 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/PipelineChainDownloader.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/PipelineChainDownloader.java @@ -24,7 +24,7 @@ import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.LabelledMetric; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.services.pipeline.Pipeline; import tech.pegasys.pantheon.util.ExceptionUtils; @@ -65,7 +65,7 @@ public PipelineChainDownloader( final LabelledMetric labelledCounter = metricsSystem.createLabelledCounter( - PantheonMetricCategories.SYNCHRONIZER, + PantheonMetricCategory.SYNCHRONIZER, "chain_download_pipeline_restarts", "Number of times the chain download pipeline has been restarted", "reason"); diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastDownloaderFactory.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastDownloaderFactory.java index 8aa6c7e9c2..c4a32901f7 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastDownloaderFactory.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastDownloaderFactory.java @@ -24,7 +24,7 @@ import tech.pegasys.pantheon.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions; import tech.pegasys.pantheon.ethereum.worldstate.WorldStateStorage; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.services.tasks.CachingTaskCollection; import tech.pegasys.pantheon.services.tasks.FlatFileTaskCollection; @@ -123,13 +123,13 @@ private static CachingTaskCollection createWorldStateDownloader dataDirectory, NodeDataRequest::serialize, NodeDataRequest::deserialize)); metricsSystem.createLongGauge( - PantheonMetricCategories.SYNCHRONIZER, + PantheonMetricCategory.SYNCHRONIZER, "world_state_pending_requests_current", "Number of pending requests for fast sync world state download", taskCollection::size); metricsSystem.createIntegerGauge( - PantheonMetricCategories.SYNCHRONIZER, + PantheonMetricCategory.SYNCHRONIZER, "world_state_pending_requests_cache_size", "Pending request cache size for fast sync world state download", taskCollection::cacheSize); diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncActions.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncActions.java index 9e0c2d5fd4..1efd7550d6 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncActions.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncActions.java @@ -27,7 +27,7 @@ import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.util.ExceptionUtils; import java.time.Duration; @@ -66,11 +66,11 @@ public FastSyncActions( pivotBlockSelectionCounter = metricsSystem.createCounter( - PantheonMetricCategories.SYNCHRONIZER, + PantheonMetricCategory.SYNCHRONIZER, "fast_sync_pivot_block_selected_count", "Number of times a fast sync pivot block has been selected"); metricsSystem.createLongGauge( - PantheonMetricCategories.SYNCHRONIZER, + PantheonMetricCategory.SYNCHRONIZER, "fast_sync_pivot_block_current", "The current fast sync pivot block", pivotBlockGauge::get); diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java index b134b25266..3f119eb571 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java @@ -35,7 +35,7 @@ import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.LabelledMetric; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.services.pipeline.Pipeline; import tech.pegasys.pantheon.services.pipeline.PipelineBuilder; @@ -67,7 +67,7 @@ public FastSyncDownloadPipelineFactory( this.metricsSystem = metricsSystem; final LabelledMetric fastSyncValidationCounter = metricsSystem.createLabelledCounter( - PantheonMetricCategories.SYNCHRONIZER, + PantheonMetricCategory.SYNCHRONIZER, "fast_sync_validation_mode", "Number of blocks validated using light vs full validation during fast sync", "validationMode"); @@ -130,7 +130,7 @@ public Pipeline createDownloadPipelineForSyncTarget(final SyncTarget target) checkpointRangeSource, downloaderParallelism, metricsSystem.createLabelledCounter( - PantheonMetricCategories.SYNCHRONIZER, + PantheonMetricCategory.SYNCHRONIZER, "chain_download_pipeline_processed_total", "Number of entries process by each chain download pipeline stage", "step", diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fullsync/FullSyncDownloadPipelineFactory.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fullsync/FullSyncDownloadPipelineFactory.java index 265fa98fb5..fd93395e59 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fullsync/FullSyncDownloadPipelineFactory.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fullsync/FullSyncDownloadPipelineFactory.java @@ -28,7 +28,7 @@ import tech.pegasys.pantheon.ethereum.mainnet.HeaderValidationMode; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.services.pipeline.Pipeline; import tech.pegasys.pantheon.services.pipeline.PipelineBuilder; @@ -95,7 +95,7 @@ public Pipeline createDownloadPipelineForSyncTarget(final SyncTarget target) checkpointRangeSource, downloaderParallelism, metricsSystem.createLabelledCounter( - PantheonMetricCategories.SYNCHRONIZER, + PantheonMetricCategory.SYNCHRONIZER, "chain_download_pipeline_processed_total", "Number of entries process by each chain download pipeline stage", "step", diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/CompleteTaskStep.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/CompleteTaskStep.java index 4e644f939a..78edf25b9d 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/CompleteTaskStep.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/CompleteTaskStep.java @@ -16,7 +16,7 @@ import tech.pegasys.pantheon.ethereum.worldstate.WorldStateStorage; import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.services.tasks.Task; public class CompleteTaskStep { @@ -31,12 +31,12 @@ public CompleteTaskStep( completedRequestsCounter = metricsSystem.createCounter( - PantheonMetricCategories.SYNCHRONIZER, + PantheonMetricCategory.SYNCHRONIZER, "world_state_completed_requests_total", "Total number of node data requests completed as part of fast sync world state download"); retriedRequestsCounter = metricsSystem.createCounter( - PantheonMetricCategories.SYNCHRONIZER, + PantheonMetricCategory.SYNCHRONIZER, "world_state_retried_requests_total", "Total number of node data requests repeated as part of fast sync world state download"); } diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/LoadLocalDataStep.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/LoadLocalDataStep.java index d5f8518401..f89a6737b8 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/LoadLocalDataStep.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/LoadLocalDataStep.java @@ -15,7 +15,7 @@ import tech.pegasys.pantheon.ethereum.worldstate.WorldStateStorage; import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.services.pipeline.Pipe; import tech.pegasys.pantheon.services.tasks.Task; import tech.pegasys.pantheon.util.bytes.BytesValue; @@ -33,7 +33,7 @@ public LoadLocalDataStep( this.worldStateStorage = worldStateStorage; existingNodeCounter = metricsSystem.createCounter( - PantheonMetricCategories.SYNCHRONIZER, + PantheonMetricCategory.SYNCHRONIZER, "world_state_existing_nodes_total", "Total number of node data requests completed using existing data"); } diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloadProcess.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloadProcess.java index e0facef3ea..9aa49ea242 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloadProcess.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloadProcess.java @@ -20,7 +20,7 @@ import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.LabelledMetric; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.services.pipeline.Pipe; import tech.pegasys.pantheon.services.pipeline.Pipeline; import tech.pegasys.pantheon.services.pipeline.PipelineBuilder; @@ -196,7 +196,7 @@ public WorldStateDownloadProcess build() { final int bufferCapacity = hashCountPerRequest * 2; final LabelledMetric outputCounter = metricsSystem.createLabelledCounter( - PantheonMetricCategories.SYNCHRONIZER, + PantheonMetricCategory.SYNCHRONIZER, "world_state_pipeline_processed_total", "Number of entries processed by each world state download pipeline stage", "step", diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloader.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloader.java index 9c3e03c008..c0f171962b 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloader.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloader.java @@ -17,7 +17,7 @@ import tech.pegasys.pantheon.ethereum.eth.manager.EthContext; import tech.pegasys.pantheon.ethereum.worldstate.WorldStateStorage; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.services.tasks.CachingTaskCollection; import java.time.Clock; @@ -66,13 +66,13 @@ public WorldStateDownloader( this.metricsSystem = metricsSystem; metricsSystem.createIntegerGauge( - PantheonMetricCategories.SYNCHRONIZER, + PantheonMetricCategory.SYNCHRONIZER, "world_state_node_requests_since_last_progress_current", "Number of world state requests made since the last time new data was returned", downloadStateValue(WorldDownloadState::getRequestsSinceLastProgress)); metricsSystem.createIntegerGauge( - PantheonMetricCategories.SYNCHRONIZER, + PantheonMetricCategory.SYNCHRONIZER, "world_state_inflight_requests_current", "Number of in progress requests for world state data", downloadStateValue(WorldDownloadState::getOutstandingTaskCount)); diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/PendingTransactions.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/PendingTransactions.java index bf1103ed8d..4a419e063e 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/PendingTransactions.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/PendingTransactions.java @@ -21,7 +21,7 @@ import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.LabelledMetric; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.util.Subscribers; import java.time.Clock; @@ -87,7 +87,7 @@ public PendingTransactions( this.clock = clock; final LabelledMetric transactionAddedCounter = metricsSystem.createLabelledCounter( - PantheonMetricCategories.TRANSACTION_POOL, + PantheonMetricCategory.TRANSACTION_POOL, "transactions_added_total", "Count of transactions added to the transaction pool", "source"); @@ -96,7 +96,7 @@ public PendingTransactions( transactionRemovedCounter = metricsSystem.createLabelledCounter( - PantheonMetricCategories.TRANSACTION_POOL, + PantheonMetricCategory.TRANSACTION_POOL, "transactions_removed_total", "Count of transactions removed from the transaction pool", "source", diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpService.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpService.java index 5d2f82ec72..9e0f2ef408 100755 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpService.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpService.java @@ -33,7 +33,7 @@ import tech.pegasys.pantheon.metrics.MetricsSystem; import tech.pegasys.pantheon.metrics.OperationTimer; import tech.pegasys.pantheon.metrics.OperationTimer.TimingContext; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.util.NetworkUtility; import java.net.InetSocketAddress; @@ -122,7 +122,7 @@ private JsonRpcHttpService( this.dataDir = dataDir; requestTimer = metricsSystem.createLabelledTimer( - PantheonMetricCategories.RPC, + PantheonMetricCategory.RPC, "request_time", "Time taken to process a JSON-RPC request", "methodName"); diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/SubscriptionManager.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/SubscriptionManager.java index 8c60999d2a..debf7b690a 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/SubscriptionManager.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/subscription/SubscriptionManager.java @@ -20,7 +20,7 @@ import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.LabelledMetric; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import java.util.List; import java.util.Map; @@ -55,13 +55,13 @@ public class SubscriptionManager extends AbstractVerticle { public SubscriptionManager(final MetricsSystem metricsSystem) { subscribeCounter = metricsSystem.createLabelledCounter( - PantheonMetricCategories.RPC, + PantheonMetricCategory.RPC, "subscription_subscribe_total", "Total number of subscriptions", "type"); unsubscribeCounter = metricsSystem.createLabelledCounter( - PantheonMetricCategories.RPC, + PantheonMetricCategory.RPC, "subscription_unsubscribe_total", "Total number of unsubscriptions", "type"); diff --git a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/DebugMetricsTest.java b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/DebugMetricsTest.java index 5b7cd4fe71..474436e7a7 100644 --- a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/DebugMetricsTest.java +++ b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/DebugMetricsTest.java @@ -16,8 +16,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static tech.pegasys.pantheon.metrics.PantheonMetricCategories.PEERS; -import static tech.pegasys.pantheon.metrics.PantheonMetricCategories.RPC; +import static tech.pegasys.pantheon.metrics.PantheonMetricCategory.PEERS; +import static tech.pegasys.pantheon.metrics.PantheonMetricCategory.RPC; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse; diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/NetworkRunner.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/NetworkRunner.java index f10f324285..bc0639b772 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/NetworkRunner.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/NetworkRunner.java @@ -20,7 +20,7 @@ import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.LabelledMetric; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import java.util.ArrayList; import java.util.Arrays; @@ -57,7 +57,7 @@ private NetworkRunner( this.subProtocols = subProtocols; inboundMessageCounter = metricsSystem.createLabelledCounter( - PantheonMetricCategories.NETWORK, + PantheonMetricCategory.NETWORK, "p2p_messages_inbound", "Count of each P2P message received inbound.", "protocol", diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/VertxPeerDiscoveryAgent.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/VertxPeerDiscoveryAgent.java index 65568d6263..6562b6a28d 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/VertxPeerDiscoveryAgent.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/VertxPeerDiscoveryAgent.java @@ -23,7 +23,7 @@ import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.VertxTimerUtil; import tech.pegasys.pantheon.ethereum.p2p.permissions.PeerPermissions; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.util.NetworkUtility; import java.io.IOException; @@ -64,7 +64,7 @@ public VertxPeerDiscoveryAgent( this.vertx = vertx; metricsSystem.createIntegerGauge( - PantheonMetricCategories.NETWORK, + PantheonMetricCategory.NETWORK, "vertx_eventloop_pending_tasks", "The number of pending tasks in the Vertx event loop", pendingTaskCounter(vertx.nettyEventLoopGroup())); diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/DiscoveryProtocolLogger.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/DiscoveryProtocolLogger.java index d33550f065..4bd66b07c7 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/DiscoveryProtocolLogger.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/DiscoveryProtocolLogger.java @@ -16,7 +16,7 @@ import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.LabelledMetric; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -30,13 +30,13 @@ public class DiscoveryProtocolLogger { public DiscoveryProtocolLogger(final MetricsSystem metricsSystem) { outgoingMessageCounter = metricsSystem.createLabelledCounter( - PantheonMetricCategories.NETWORK, + PantheonMetricCategory.NETWORK, "discovery_messages_outbound", "Total number of P2P discovery messages sent", "name"); incomingMessageCounter = metricsSystem.createLabelledCounter( - PantheonMetricCategories.NETWORK, + PantheonMetricCategory.NETWORK, "discovery_messages_inbound", "Total number of P2P discovery messages received", "name"); diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/PeerDiscoveryController.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/PeerDiscoveryController.java index cac5876c47..6db23c57a7 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/PeerDiscoveryController.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/PeerDiscoveryController.java @@ -31,7 +31,7 @@ import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.LabelledMetric; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.util.Subscribers; import tech.pegasys.pantheon.util.bytes.BytesValue; @@ -172,21 +172,21 @@ private PeerDiscoveryController( this.peerPermissions = new PeerDiscoveryPermissions(localPeer, peerPermissions); metricsSystem.createIntegerGauge( - PantheonMetricCategories.NETWORK, + PantheonMetricCategory.NETWORK, "discovery_inflight_interactions_current", "Current number of inflight discovery interactions", inflightInteractions::size); interactionCounter = metricsSystem.createLabelledCounter( - PantheonMetricCategories.NETWORK, + PantheonMetricCategory.NETWORK, "discovery_interaction_count", "Total number of discovery interactions initiated", "type"); interactionRetryCounter = metricsSystem.createLabelledCounter( - PantheonMetricCategories.NETWORK, + PantheonMetricCategory.NETWORK, "discovery_interaction_retry_count", "Total number of interaction retries performed", "type"); diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetwork.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetwork.java index 35325815d7..9ff583903d 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetwork.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetwork.java @@ -46,7 +46,7 @@ import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.LabelledMetric; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.util.Subscribers; import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.enode.EnodeURL; @@ -219,7 +219,7 @@ public class DefaultP2PNetwork implements P2PNetwork { outboundMessagesCounter = metricsSystem.createLabelledCounter( - PantheonMetricCategories.NETWORK, + PantheonMetricCategory.NETWORK, "p2p_messages_outbound", "Count of each P2P message sent outbound.", "protocol", @@ -227,19 +227,19 @@ public class DefaultP2PNetwork implements P2PNetwork { "code"); metricsSystem.createIntegerGauge( - PantheonMetricCategories.NETWORK, + PantheonMetricCategory.NETWORK, "netty_workers_pending_tasks", "The number of pending tasks in the Netty workers event loop", pendingTaskCounter(workers)); metricsSystem.createIntegerGauge( - PantheonMetricCategories.NETWORK, + PantheonMetricCategory.NETWORK, "netty_boss_pending_tasks", "The number of pending tasks in the Netty boss event loop", pendingTaskCounter(boss)); metricsSystem.createIntegerGauge( - PantheonMetricCategories.NETWORK, + PantheonMetricCategory.NETWORK, "peers_limit", "Maximum P2P peer connections that can be established", () -> maxPeers); diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/netty/PeerConnectionRegistry.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/netty/PeerConnectionRegistry.java index bf046a3788..15eef04ce7 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/netty/PeerConnectionRegistry.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/netty/PeerConnectionRegistry.java @@ -20,7 +20,7 @@ import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.LabelledMetric; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.util.bytes.BytesValue; import java.util.Collection; @@ -38,16 +38,16 @@ public class PeerConnectionRegistry implements DisconnectCallback { public PeerConnectionRegistry(final MetricsSystem metricsSystem) { disconnectCounter = metricsSystem.createLabelledCounter( - PantheonMetricCategories.PEERS, + PantheonMetricCategory.PEERS, "disconnected_total", "Total number of peers disconnected", "initiator", "disconnectReason"); connectedPeersCounter = metricsSystem.createCounter( - PantheonMetricCategories.PEERS, "connected_total", "Total number of peers connected"); + PantheonMetricCategory.PEERS, "connected_total", "Total number of peers connected"); metricsSystem.createGauge( - PantheonMetricCategories.PEERS, + PantheonMetricCategory.PEERS, "peer_count_current", "Number of peers currently connected", () -> (double) connections.size()); diff --git a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/AccountLocalConfigPermissioningController.java b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/AccountLocalConfigPermissioningController.java index cd90a49537..deca839301 100644 --- a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/AccountLocalConfigPermissioningController.java +++ b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/AccountLocalConfigPermissioningController.java @@ -18,7 +18,7 @@ import tech.pegasys.pantheon.ethereum.permissioning.account.TransactionPermissioningProvider; import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.util.bytes.BytesValue; import java.io.IOException; @@ -62,17 +62,17 @@ public AccountLocalConfigPermissioningController( readAccountsFromConfig(configuration); this.checkCounter = metricsSystem.createCounter( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "account_local_check_count", "Number of times the account local permissioning provider has been checked"); this.checkCounterPermitted = metricsSystem.createCounter( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "account_local_check_count_permitted", "Number of times the account local permissioning provider has been checked and returned permitted"); this.checkCounterUnpermitted = metricsSystem.createCounter( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "account_local_check_count_unpermitted", "Number of times the account local permissioning provider has been checked and returned unpermitted"); } diff --git a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/NodeLocalConfigPermissioningController.java b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/NodeLocalConfigPermissioningController.java index 48cba716ef..d811a58e8d 100644 --- a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/NodeLocalConfigPermissioningController.java +++ b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/NodeLocalConfigPermissioningController.java @@ -16,7 +16,7 @@ import tech.pegasys.pantheon.ethereum.permissioning.node.NodeWhitelistUpdatedEvent; import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.util.Subscribers; import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.enode.EnodeURL; @@ -80,17 +80,17 @@ public NodeLocalConfigPermissioningController( this.checkCounter = metricsSystem.createCounter( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "node_local_check_count", "Number of times the node local permissioning provider has been checked"); this.checkCounterPermitted = metricsSystem.createCounter( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "node_local_check_count_permitted", "Number of times the node local permissioning provider has been checked and returned permitted"); this.checkCounterUnpermitted = metricsSystem.createCounter( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "node_local_check_count_unpermitted", "Number of times the node local permissioning provider has been checked and returned unpermitted"); } diff --git a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/NodeSmartContractPermissioningController.java b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/NodeSmartContractPermissioningController.java index ad960dad18..8be3f48a3d 100644 --- a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/NodeSmartContractPermissioningController.java +++ b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/NodeSmartContractPermissioningController.java @@ -22,7 +22,7 @@ import tech.pegasys.pantheon.ethereum.transaction.TransactionSimulatorResult; import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.bytes.BytesValues; import tech.pegasys.pantheon.util.enode.EnodeURL; @@ -77,17 +77,17 @@ public NodeSmartContractPermissioningController( this.checkCounter = metricsSystem.createCounter( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "node_smart_contract_check_count", "Number of times the node smart contract permissioning provider has been checked"); this.checkCounterPermitted = metricsSystem.createCounter( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "node_smart_contract_check_count_permitted", "Number of times the node smart contract permissioning provider has been checked and returned permitted"); this.checkCounterUnpermitted = metricsSystem.createCounter( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "node_smart_contract_check_count_unpermitted", "Number of times the node smart contract permissioning provider has been checked and returned unpermitted"); } diff --git a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/TransactionSmartContractPermissioningController.java b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/TransactionSmartContractPermissioningController.java index f9b69052ca..ab37b8819d 100644 --- a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/TransactionSmartContractPermissioningController.java +++ b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/TransactionSmartContractPermissioningController.java @@ -24,7 +24,7 @@ import tech.pegasys.pantheon.ethereum.transaction.TransactionSimulatorResult; import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.bytes.BytesValues; @@ -84,17 +84,17 @@ public TransactionSmartContractPermissioningController( this.checkCounter = metricsSystem.createCounter( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "transaction_smart_contract_check_count", "Number of times the transaction smart contract permissioning provider has been checked"); this.checkCounterPermitted = metricsSystem.createCounter( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "transaction_smart_contract_check_count_permitted", "Number of times the transaction smart contract permissioning provider has been checked and returned permitted"); this.checkCounterUnpermitted = metricsSystem.createCounter( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "transaction_smart_contract_check_count_unpermitted", "Number of times the transaction smart contract permissioning provider has been checked and returned unpermitted"); } diff --git a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProvider.java b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProvider.java index b7152bf975..b9a0621c3e 100644 --- a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProvider.java +++ b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProvider.java @@ -19,7 +19,7 @@ import tech.pegasys.pantheon.ethereum.permissioning.node.NodePermissioningProvider; import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.util.enode.EnodeURL; import java.util.Collection; @@ -47,23 +47,23 @@ public SyncStatusNodePermissioningProvider( this.fixedNodes.addAll(fixedNodes); metricsSystem.createIntegerGauge( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "sync_status_node_sync_reached", "Whether the sync status permissioning provider has realised sync yet", () -> hasReachedSync ? 1 : 0); this.checkCounter = metricsSystem.createCounter( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "sync_status_node_check_count", "Number of times the sync status permissioning provider has been checked"); this.checkCounterPermitted = metricsSystem.createCounter( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "sync_status_node_check_count_permitted", "Number of times the sync status permissioning provider has been checked and returned permitted"); this.checkCounterUnpermitted = metricsSystem.createCounter( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "sync_status_node_check_count_unpermitted", "Number of times the sync status permissioning provider has been checked and returned unpermitted"); } diff --git a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/AccountLocalConfigPermissioningControllerTest.java b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/AccountLocalConfigPermissioningControllerTest.java index 5ed08c594d..991ad85d92 100644 --- a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/AccountLocalConfigPermissioningControllerTest.java +++ b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/AccountLocalConfigPermissioningControllerTest.java @@ -27,7 +27,7 @@ import tech.pegasys.pantheon.ethereum.core.Transaction; import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -58,19 +58,19 @@ public class AccountLocalConfigPermissioningControllerTest { public void before() { when(metricsSystem.createCounter( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "account_local_check_count", "Number of times the account local permissioning provider has been checked")) .thenReturn(checkCounter); when(metricsSystem.createCounter( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "account_local_check_count_permitted", "Number of times the account local permissioning provider has been checked and returned permitted")) .thenReturn(checkPermittedCounter); when(metricsSystem.createCounter( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "account_local_check_count_unpermitted", "Number of times the account local permissioning provider has been checked and returned unpermitted")) .thenReturn(checkUnpermittedCounter); diff --git a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/NodeLocalConfigPermissioningControllerTest.java b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/NodeLocalConfigPermissioningControllerTest.java index 52e4ce0da3..f5f3c2f143 100644 --- a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/NodeLocalConfigPermissioningControllerTest.java +++ b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/NodeLocalConfigPermissioningControllerTest.java @@ -29,7 +29,7 @@ import tech.pegasys.pantheon.ethereum.permissioning.node.NodeWhitelistUpdatedEvent; import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.util.enode.EnodeURL; import java.io.IOException; @@ -74,19 +74,19 @@ public void setUp() { bootnodesList.clear(); when(metricsSystem.createCounter( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "node_local_check_count", "Number of times the node local permissioning provider has been checked")) .thenReturn(checkCounter); when(metricsSystem.createCounter( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "node_local_check_count_permitted", "Number of times the node local permissioning provider has been checked and returned permitted")) .thenReturn(checkPermittedCounter); when(metricsSystem.createCounter( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "node_local_check_count_unpermitted", "Number of times the node local permissioning provider has been checked and returned unpermitted")) .thenReturn(checkUnpermittedCounter); diff --git a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/NodeSmartContractPermissioningControllerTest.java b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/NodeSmartContractPermissioningControllerTest.java index 91cf1519ec..3f89d43cb4 100644 --- a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/NodeSmartContractPermissioningControllerTest.java +++ b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/NodeSmartContractPermissioningControllerTest.java @@ -31,7 +31,7 @@ import tech.pegasys.pantheon.ethereum.worldstate.WorldStateArchive; import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.util.enode.EnodeURL; import java.io.IOException; @@ -68,19 +68,19 @@ private NodeSmartContractPermissioningController setupController( final Address contractAddress = Address.fromHexString(contractAddressString); when(metricsSystem.createCounter( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "node_smart_contract_check_count", "Number of times the node smart contract permissioning provider has been checked")) .thenReturn(checkCounter); when(metricsSystem.createCounter( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "node_smart_contract_check_count_permitted", "Number of times the node smart contract permissioning provider has been checked and returned permitted")) .thenReturn(checkPermittedCounter); when(metricsSystem.createCounter( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "node_smart_contract_check_count_unpermitted", "Number of times the node smart contract permissioning provider has been checked and returned unpermitted")) .thenReturn(checkUnpermittedCounter); diff --git a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/TransactionSmartContractPermissioningControllerTest.java b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/TransactionSmartContractPermissioningControllerTest.java index f3d8c28e47..d908dac17a 100644 --- a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/TransactionSmartContractPermissioningControllerTest.java +++ b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/TransactionSmartContractPermissioningControllerTest.java @@ -34,7 +34,7 @@ import tech.pegasys.pantheon.ethereum.worldstate.WorldStateArchive; import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.util.bytes.BytesValue; import java.io.IOException; @@ -72,19 +72,19 @@ private TransactionSmartContractPermissioningController setupController( final Address contractAddress = Address.fromHexString(contractAddressString); when(metricsSystem.createCounter( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "transaction_smart_contract_check_count", "Number of times the transaction smart contract permissioning provider has been checked")) .thenReturn(checkCounter); when(metricsSystem.createCounter( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "transaction_smart_contract_check_count_permitted", "Number of times the transaction smart contract permissioning provider has been checked and returned permitted")) .thenReturn(checkPermittedCounter); when(metricsSystem.createCounter( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "transaction_smart_contract_check_count_unpermitted", "Number of times the transaction smart contract permissioning provider has been checked and returned unpermitted")) .thenReturn(checkUnpermittedCounter); diff --git a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProviderTest.java b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProviderTest.java index b8a551b1b6..8e75bd9c4d 100644 --- a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProviderTest.java +++ b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProviderTest.java @@ -24,7 +24,7 @@ import tech.pegasys.pantheon.ethereum.core.Synchronizer.SyncStatusListener; import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.util.enode.EnodeURL; import java.util.ArrayList; @@ -74,17 +74,17 @@ public void before() { ArgumentCaptor.forClass(IntSupplier.class); when(metricsSystem.createCounter( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "sync_status_node_check_count", "Number of times the sync status permissioning provider has been checked")) .thenReturn(checkCounter); when(metricsSystem.createCounter( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "sync_status_node_check_count_permitted", "Number of times the sync status permissioning provider has been checked and returned permitted")) .thenReturn(checkPermittedCounter); when(metricsSystem.createCounter( - PantheonMetricCategories.PERMISSIONING, + PantheonMetricCategory.PERMISSIONING, "sync_status_node_check_count_unpermitted", "Number of times the sync status permissioning provider has been checked and returned unpermitted")) .thenReturn(checkUnpermittedCounter); @@ -92,7 +92,7 @@ public void before() { this.syncStatusListener = captor.getValue(); verify(metricsSystem) .createIntegerGauge( - eq(PantheonMetricCategories.PERMISSIONING), + eq(PantheonMetricCategory.PERMISSIONING), eq("sync_status_node_sync_reached"), eq("Whether the sync status permissioning provider has realised sync yet"), syncGaugeCallbackCaptor.capture()); diff --git a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/PantheonMetricCategories.java b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/PantheonMetricCategory.java similarity index 84% rename from metrics/core/src/main/java/tech/pegasys/pantheon/metrics/PantheonMetricCategories.java rename to metrics/core/src/main/java/tech/pegasys/pantheon/metrics/PantheonMetricCategory.java index 7d2fec7e6b..49df78807b 100644 --- a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/PantheonMetricCategories.java +++ b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/PantheonMetricCategory.java @@ -17,7 +17,7 @@ import com.google.common.collect.ImmutableSet; -public enum PantheonMetricCategories implements MetricCategory { +public enum PantheonMetricCategory implements MetricCategory { BLOCKCHAIN("blockchain"), EXECUTORS("executors"), NETWORK("network"), @@ -33,24 +33,24 @@ public enum PantheonMetricCategories implements MetricCategory { static { // Why not ROCKSDB and KVSTORE_ROCKSDB_STATS? They hurt performance under load. - final EnumSet pantheonCategories = + final EnumSet pantheonCategories = EnumSet.complementOf(EnumSet.of(KVSTORE_ROCKSDB, KVSTORE_ROCKSDB_STATS)); DEFAULT_METRIC_CATEGORIES = ImmutableSet.builder() .addAll(pantheonCategories) - .addAll(EnumSet.allOf(StandardMetricCategories.class)) + .addAll(EnumSet.allOf(StandardMetricCategory.class)) .build(); } private final String name; private final boolean pantheonSpecific; - PantheonMetricCategories(final String name) { + PantheonMetricCategory(final String name) { this(name, true); } - PantheonMetricCategories(final String name, final boolean pantheonSpecific) { + PantheonMetricCategory(final String name, final boolean pantheonSpecific) { this.name = name; this.pantheonSpecific = pantheonSpecific; } diff --git a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/StandardMetricCategories.java b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/StandardMetricCategory.java similarity index 88% rename from metrics/core/src/main/java/tech/pegasys/pantheon/metrics/StandardMetricCategories.java rename to metrics/core/src/main/java/tech/pegasys/pantheon/metrics/StandardMetricCategory.java index 0df0ddd586..c603edf372 100644 --- a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/StandardMetricCategories.java +++ b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/StandardMetricCategory.java @@ -12,13 +12,13 @@ */ package tech.pegasys.pantheon.metrics; -public enum StandardMetricCategories implements MetricCategory { +public enum StandardMetricCategory implements MetricCategory { JVM("jvm"), PROCESS("process"); private final String name; - StandardMetricCategories(final String name) { + StandardMetricCategory(final String name) { this.name = name; } diff --git a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsConfiguration.java b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsConfiguration.java index 5467032362..b47d8fae66 100644 --- a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsConfiguration.java +++ b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsConfiguration.java @@ -12,7 +12,7 @@ */ package tech.pegasys.pantheon.metrics.prometheus; -import static tech.pegasys.pantheon.metrics.PantheonMetricCategories.DEFAULT_METRIC_CATEGORIES; +import static tech.pegasys.pantheon.metrics.PantheonMetricCategory.DEFAULT_METRIC_CATEGORIES; import tech.pegasys.pantheon.metrics.MetricCategory; diff --git a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystem.java b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystem.java index e2ba5c98d8..0d2a4dedda 100644 --- a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystem.java +++ b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystem.java @@ -20,7 +20,7 @@ import tech.pegasys.pantheon.metrics.MetricsSystem; import tech.pegasys.pantheon.metrics.Observation; import tech.pegasys.pantheon.metrics.OperationTimer; -import tech.pegasys.pantheon.metrics.StandardMetricCategories; +import tech.pegasys.pantheon.metrics.StandardMetricCategory; import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; import java.util.ArrayList; @@ -74,14 +74,14 @@ public static MetricsSystem init(final MetricsConfiguration metricsConfiguration new PrometheusMetricsSystem( metricsConfiguration.getMetricCategories(), metricsConfiguration.getApplicationPrefix()); - if (metricsSystem.isCategoryEnabled(StandardMetricCategories.PROCESS)) { + if (metricsSystem.isCategoryEnabled(StandardMetricCategory.PROCESS)) { metricsSystem.collectors.put( - StandardMetricCategories.PROCESS, + StandardMetricCategory.PROCESS, singleton(new StandardExports().register(metricsSystem.registry))); } - if (metricsSystem.isCategoryEnabled(StandardMetricCategories.JVM)) { + if (metricsSystem.isCategoryEnabled(StandardMetricCategory.JVM)) { metricsSystem.collectors.put( - StandardMetricCategories.JVM, + StandardMetricCategory.JVM, asList( new MemoryPoolsExports().register(metricsSystem.registry), new BufferPoolsExports().register(metricsSystem.registry), diff --git a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/vertx/PoolMetricsAdapter.java b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/vertx/PoolMetricsAdapter.java index d9c6ff5474..5e8486c356 100644 --- a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/vertx/PoolMetricsAdapter.java +++ b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/vertx/PoolMetricsAdapter.java @@ -14,7 +14,7 @@ import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import io.vertx.core.spi.metrics.PoolMetrics; @@ -29,7 +29,7 @@ public PoolMetricsAdapter( submittedCounter = metricsSystem .createLabelledCounter( - PantheonMetricCategories.NETWORK, + PantheonMetricCategory.NETWORK, "vertx_worker_pool_submitted_total", "Total number of tasks submitted to the Vertx worker pool", "poolType", @@ -39,7 +39,7 @@ public PoolMetricsAdapter( completedCounter = metricsSystem .createLabelledCounter( - PantheonMetricCategories.NETWORK, + PantheonMetricCategory.NETWORK, "vertx_worker_pool_completed_total", "Total number of tasks completed by the Vertx worker pool", "poolType", @@ -49,7 +49,7 @@ public PoolMetricsAdapter( rejectedCounter = metricsSystem .createLabelledCounter( - PantheonMetricCategories.NETWORK, + PantheonMetricCategory.NETWORK, "vertx_worker_pool_rejected_total", "Total number of tasks rejected by the Vertx worker pool", "poolType", diff --git a/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/noop/NoOpMetricsSystemTest.java b/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/noop/NoOpMetricsSystemTest.java index 77f526e406..88251bb8a3 100644 --- a/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/noop/NoOpMetricsSystemTest.java +++ b/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/noop/NoOpMetricsSystemTest.java @@ -19,7 +19,7 @@ import tech.pegasys.pantheon.metrics.LabelledMetric; import tech.pegasys.pantheon.metrics.MetricsSystem; import tech.pegasys.pantheon.metrics.OperationTimer; -import tech.pegasys.pantheon.metrics.StandardMetricCategories; +import tech.pegasys.pantheon.metrics.StandardMetricCategory; import org.junit.Test; @@ -31,7 +31,7 @@ public class NoOpMetricsSystemTest { public void labelCountsMatchOnCounter() { final LabelledMetric labeledCounter = metricsSystem.createLabelledCounter( - StandardMetricCategories.PROCESS, "name", "help", "label1"); + StandardMetricCategory.PROCESS, "name", "help", "label1"); assertThat(labeledCounter.labels("one")).isSameAs(NoOpMetricsSystem.NO_OP_COUNTER); } @@ -39,7 +39,7 @@ public void labelCountsMatchOnCounter() { public void failsWheLabelCountsDoNotMatchOnCounter() { final LabelledMetric labeledCounter = metricsSystem.createLabelledCounter( - StandardMetricCategories.PROCESS, "name", "help", "label1", "label2"); + StandardMetricCategory.PROCESS, "name", "help", "label1", "label2"); assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> labeledCounter.labels("one")) @@ -52,8 +52,7 @@ public void failsWheLabelCountsDoNotMatchOnCounter() { @Test public void labelCountsMatchOnTimer() { final LabelledMetric labeledTimer = - metricsSystem.createLabelledTimer( - StandardMetricCategories.PROCESS, "name", "help", "label1"); + metricsSystem.createLabelledTimer(StandardMetricCategory.PROCESS, "name", "help", "label1"); assertThat(labeledTimer.labels("one")).isSameAs(NoOpMetricsSystem.NO_OP_OPERATION_TIMER); } @@ -61,7 +60,7 @@ public void labelCountsMatchOnTimer() { public void failsWheLabelCountsDoNotMatchOnTimer() { final LabelledMetric labeledTimer = metricsSystem.createLabelledTimer( - StandardMetricCategories.PROCESS, "name", "help", "label1", "label2"); + StandardMetricCategory.PROCESS, "name", "help", "label1", "label2"); assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> labeledTimer.labels("one")) diff --git a/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystemTest.java b/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystemTest.java index 8630defa87..c38ee8a186 100644 --- a/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystemTest.java +++ b/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystemTest.java @@ -17,11 +17,11 @@ import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static tech.pegasys.pantheon.metrics.PantheonMetricCategories.DEFAULT_METRIC_CATEGORIES; -import static tech.pegasys.pantheon.metrics.PantheonMetricCategories.NETWORK; -import static tech.pegasys.pantheon.metrics.PantheonMetricCategories.PEERS; -import static tech.pegasys.pantheon.metrics.PantheonMetricCategories.RPC; -import static tech.pegasys.pantheon.metrics.StandardMetricCategories.JVM; +import static tech.pegasys.pantheon.metrics.PantheonMetricCategory.DEFAULT_METRIC_CATEGORIES; +import static tech.pegasys.pantheon.metrics.PantheonMetricCategory.NETWORK; +import static tech.pegasys.pantheon.metrics.PantheonMetricCategory.PEERS; +import static tech.pegasys.pantheon.metrics.PantheonMetricCategory.RPC; +import static tech.pegasys.pantheon.metrics.StandardMetricCategory.JVM; import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.LabelledMetric; @@ -29,7 +29,7 @@ import tech.pegasys.pantheon.metrics.Observation; import tech.pegasys.pantheon.metrics.OperationTimer; import tech.pegasys.pantheon.metrics.OperationTimer.TimingContext; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; import java.util.Comparator; @@ -177,7 +177,7 @@ public void shouldNotAllowDuplicateGaugeCreation() { public void shouldOnlyObserveEnabledMetrics() { final MetricsConfiguration metricsConfiguration = MetricsConfiguration.builder() - .metricCategories(ImmutableSet.of(PantheonMetricCategories.RPC)) + .metricCategories(ImmutableSet.of(PantheonMetricCategory.RPC)) .enabled(true) .build(); final MetricsSystem localMetricSystem = PrometheusMetricsSystem.init(metricsConfiguration); diff --git a/metrics/rocksdb/src/main/java/tech/pegasys/pantheon/metrics/rocksdb/RocksDBStats.java b/metrics/rocksdb/src/main/java/tech/pegasys/pantheon/metrics/rocksdb/RocksDBStats.java index 344255090e..cd363ebb5a 100644 --- a/metrics/rocksdb/src/main/java/tech/pegasys/pantheon/metrics/rocksdb/RocksDBStats.java +++ b/metrics/rocksdb/src/main/java/tech/pegasys/pantheon/metrics/rocksdb/RocksDBStats.java @@ -12,7 +12,7 @@ */ package tech.pegasys.pantheon.metrics.rocksdb; -import static tech.pegasys.pantheon.metrics.PantheonMetricCategories.KVSTORE_ROCKSDB_STATS; +import static tech.pegasys.pantheon.metrics.PantheonMetricCategory.KVSTORE_ROCKSDB_STATS; import tech.pegasys.pantheon.metrics.prometheus.PrometheusMetricsSystem; diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java index 16a6c531bd..a01ef2ad58 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -24,7 +24,7 @@ import static tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.DEFAULT_JSON_RPC_PORT; import static tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis.DEFAULT_JSON_RPC_APIS; import static tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration.DEFAULT_WEBSOCKET_PORT; -import static tech.pegasys.pantheon.metrics.PantheonMetricCategories.DEFAULT_METRIC_CATEGORIES; +import static tech.pegasys.pantheon.metrics.PantheonMetricCategory.DEFAULT_METRIC_CATEGORIES; import static tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration.DEFAULT_METRICS_PORT; import static tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration.DEFAULT_METRICS_PUSH_PORT; @@ -68,8 +68,8 @@ import tech.pegasys.pantheon.ethereum.transaction.TransactionSimulator; import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; -import tech.pegasys.pantheon.metrics.StandardMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; +import tech.pegasys.pantheon.metrics.StandardMetricCategory; import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration; import tech.pegasys.pantheon.metrics.prometheus.PrometheusMetricsSystem; import tech.pegasys.pantheon.metrics.vertx.VertxMetricsAdapterFactory; @@ -98,7 +98,10 @@ import java.time.Clock; import java.util.ArrayList; import java.util.Collection; +import java.util.EnumSet; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.function.Supplier; @@ -657,14 +660,18 @@ public void parse( commandLine.registerConverter(UInt256.class, (arg) -> UInt256.of(new BigInteger(arg))); commandLine.registerConverter(Wei.class, (arg) -> Wei.of(Long.parseUnsignedLong(arg))); commandLine.registerConverter(PositiveNumber.class, PositiveNumber::fromString); + + final Map metricCategories = new HashMap<>(); + addCategories(metricCategories, PantheonMetricCategory.class); + addCategories(metricCategories, StandardMetricCategory.class); commandLine.registerConverter( MetricCategory.class, arg -> { - try { - return PantheonMetricCategories.valueOf(arg); - } catch (final IllegalArgumentException e) { - return StandardMetricCategories.valueOf(arg); + final MetricCategory category = metricCategories.get(arg); + if (category == null) { + throw new IllegalArgumentException("Unknown category: " + arg); } + return category; }); // Add performance options @@ -690,6 +697,11 @@ public void parse( commandLine.parseWithHandlers(configParsingHandler, exceptionHandler, args); } + private & MetricCategory> void addCategories( + final Map categories, final Class categoryEnum) { + EnumSet.allOf(categoryEnum).forEach(category -> categories.put(category.name(), category)); + } + @Override public void run() { // set log level per CLI flags diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java index 37a8ea90f4..f5361980c4 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java @@ -50,7 +50,7 @@ import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; import tech.pegasys.pantheon.ethereum.permissioning.SmartContractPermissioningConfiguration; import tech.pegasys.pantheon.ethereum.permissioning.account.AccountPermissioningController; -import tech.pegasys.pantheon.metrics.StandardMetricCategories; +import tech.pegasys.pantheon.metrics.StandardMetricCategory; import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration; import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.enode.EnodeURL; @@ -2050,14 +2050,13 @@ public void metricsHostMayBeIPv6() { @Test public void metricsCategoryPropertyMustBeUsed() { - parseCommand( - "--metrics-enabled", "--metrics-category", StandardMetricCategories.JVM.toString()); + parseCommand("--metrics-enabled", "--metrics-category", StandardMetricCategory.JVM.toString()); verify(mockRunnerBuilder).metricsConfiguration(metricsConfigArgumentCaptor.capture()); verify(mockRunnerBuilder).build(); assertThat(metricsConfigArgumentCaptor.getValue().getMetricCategories()) - .containsExactly(StandardMetricCategories.JVM); + .containsExactly(StandardMetricCategory.JVM); assertThat(commandOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty(); diff --git a/services/kvstore/src/main/java/tech/pegasys/pantheon/services/kvstore/RocksDbKeyValueStorage.java b/services/kvstore/src/main/java/tech/pegasys/pantheon/services/kvstore/RocksDbKeyValueStorage.java index 8275c51791..3f8124b54c 100644 --- a/services/kvstore/src/main/java/tech/pegasys/pantheon/services/kvstore/RocksDbKeyValueStorage.java +++ b/services/kvstore/src/main/java/tech/pegasys/pantheon/services/kvstore/RocksDbKeyValueStorage.java @@ -15,7 +15,7 @@ import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.MetricsSystem; import tech.pegasys.pantheon.metrics.OperationTimer; -import tech.pegasys.pantheon.metrics.PantheonMetricCategories; +import tech.pegasys.pantheon.metrics.PantheonMetricCategory; import tech.pegasys.pantheon.metrics.prometheus.PrometheusMetricsSystem; import tech.pegasys.pantheon.metrics.rocksdb.RocksDBStats; import tech.pegasys.pantheon.services.util.RocksDbUtil; @@ -76,7 +76,7 @@ private RocksDbKeyValueStorage( readLatency = metricsSystem .createLabelledTimer( - PantheonMetricCategories.KVSTORE_ROCKSDB, + PantheonMetricCategory.KVSTORE_ROCKSDB, "read_latency_seconds", "Latency for read from RocksDB.", "database") @@ -84,7 +84,7 @@ private RocksDbKeyValueStorage( removeLatency = metricsSystem .createLabelledTimer( - PantheonMetricCategories.KVSTORE_ROCKSDB, + PantheonMetricCategory.KVSTORE_ROCKSDB, "remove_latency_seconds", "Latency of remove requests from RocksDB.", "database") @@ -92,7 +92,7 @@ private RocksDbKeyValueStorage( writeLatency = metricsSystem .createLabelledTimer( - PantheonMetricCategories.KVSTORE_ROCKSDB, + PantheonMetricCategory.KVSTORE_ROCKSDB, "write_latency_seconds", "Latency for write to RocksDB.", "database") @@ -100,7 +100,7 @@ private RocksDbKeyValueStorage( commitLatency = metricsSystem .createLabelledTimer( - PantheonMetricCategories.KVSTORE_ROCKSDB, + PantheonMetricCategory.KVSTORE_ROCKSDB, "commit_latency_seconds", "Latency for commits to RocksDB.", "database") @@ -111,7 +111,7 @@ private RocksDbKeyValueStorage( } metricsSystem.createLongGauge( - PantheonMetricCategories.KVSTORE_ROCKSDB, + PantheonMetricCategory.KVSTORE_ROCKSDB, "rocks_db_table_readers_memory_bytes", "Estimated memory used for RocksDB index and filter blocks in bytes", () -> { @@ -126,7 +126,7 @@ private RocksDbKeyValueStorage( rollbackCount = metricsSystem .createLabelledCounter( - PantheonMetricCategories.KVSTORE_ROCKSDB, + PantheonMetricCategory.KVSTORE_ROCKSDB, "rollback_count", "Number of RocksDB transactions rolled back.", "database") From c705f354933fe39eb74b3d7b455d1896bf025df1 Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Tue, 11 Jun 2019 14:33:25 +1000 Subject: [PATCH 06/11] Remove dependency on utils from metrics-core. --- metrics/core/build.gradle | 3 +-- .../metrics/prometheus/MetricsHttpService.java | 15 +-------------- .../prometheus/MetricsPushGatewayService.java | 4 +--- .../prometheus/MetricsHttpServiceTest.java | 6 +++--- 4 files changed, 6 insertions(+), 22 deletions(-) diff --git a/metrics/core/build.gradle b/metrics/core/build.gradle index 8770fea7b1..d2709abc7d 100644 --- a/metrics/core/build.gradle +++ b/metrics/core/build.gradle @@ -26,8 +26,6 @@ jar { } dependencies { - implementation project(':util') - implementation 'com.google.guava:guava' implementation 'io.prometheus:simpleclient' implementation 'io.prometheus:simpleclient_common' @@ -40,6 +38,7 @@ dependencies { runtime 'org.apache.logging.log4j:log4j-core' // test dependencies. + testImplementation project(':util') testImplementation 'junit:junit' testImplementation 'org.assertj:assertj-core' testImplementation 'org.mockito:mockito-core' diff --git a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsHttpService.java b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsHttpService.java index 8b77cceed9..6edc76c4d1 100644 --- a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsHttpService.java +++ b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsHttpService.java @@ -14,10 +14,8 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.collect.Streams.stream; -import static tech.pegasys.pantheon.util.NetworkUtility.urlForSocketAddress; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.util.NetworkUtility; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -30,7 +28,6 @@ import java.util.TreeSet; import java.util.concurrent.CompletableFuture; -import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Splitter; import com.google.common.collect.Iterables; import io.netty.handler.codec.http.HttpResponseStatus; @@ -68,9 +65,7 @@ class MetricsHttpService implements MetricsService { } private void validateConfig(final MetricsConfiguration config) { - checkArgument( - config.getPort() == 0 || NetworkUtility.isValidPort(config.getPort()), - "Invalid port configuration."); + checkArgument(config.getPort() >= 0 && config.getPort() < 65535, "Invalid port configuration."); checkArgument(config.getHost() != null, "Required host is not configured."); checkArgument( !(config.isEnabled() && config.isPushEnabled()), @@ -232,14 +227,6 @@ public Optional getPort() { return Optional.of(httpServer.actualPort()); } - @VisibleForTesting - public String url() { - if (httpServer == null) { - return ""; - } - return urlForSocketAddress("http", socketAddress()); - } - // Facilitate remote health-checks in AWS, inter alia. private void handleEmptyRequest(final RoutingContext routingContext) { routingContext.response().setStatusCode(201).end(); diff --git a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsPushGatewayService.java b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsPushGatewayService.java index 78d5eb5482..329ab9a1d4 100644 --- a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsPushGatewayService.java +++ b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsPushGatewayService.java @@ -15,7 +15,6 @@ import static com.google.common.base.Preconditions.checkArgument; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.util.NetworkUtility; import java.io.IOException; import java.util.Optional; @@ -45,8 +44,7 @@ class MetricsPushGatewayService implements MetricsService { private void validateConfig(final MetricsConfiguration config) { checkArgument( - config.getPushPort() == 0 || NetworkUtility.isValidPort(config.getPushPort()), - "Invalid port configuration."); + config.getPushPort() >= 0 && config.getPushPort() < 65536, "Invalid port configuration."); checkArgument(config.getPushHost() != null, "Required host is not configured."); checkArgument( !(config.isEnabled() && config.isPushEnabled()), diff --git a/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/prometheus/MetricsHttpServiceTest.java b/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/prometheus/MetricsHttpServiceTest.java index 189cb8b825..cf6b07ca67 100644 --- a/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/prometheus/MetricsHttpServiceTest.java +++ b/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/prometheus/MetricsHttpServiceTest.java @@ -13,6 +13,7 @@ package tech.pegasys.pantheon.metrics.prometheus; import static org.assertj.core.api.Assertions.assertThat; +import static tech.pegasys.pantheon.util.NetworkUtility.urlForSocketAddress; import java.net.InetSocketAddress; import java.util.Collections; @@ -45,7 +46,7 @@ public static void initServerAndClient() { // Build an OkHttp client. client = new OkHttpClient(); - baseUrl = service.url(); + baseUrl = urlForSocketAddress("http", service.socketAddress()); } private static MetricsHttpService createMetricsHttpService(final MetricsConfiguration config) { @@ -111,7 +112,7 @@ public void getSocketAddressWhenStoppedIsEmpty() { final InetSocketAddress socketAddress = service.socketAddress(); assertThat("0.0.0.0").isEqualTo(socketAddress.getAddress().getHostAddress()); assertThat(0).isEqualTo(socketAddress.getPort()); - assertThat("").isEqualTo(service.url()); + assertThat(new InetSocketAddress("0.0.0.0", 0)).isEqualTo(service.socketAddress()); } @Test @@ -124,7 +125,6 @@ public void getSocketAddressWhenBindingToAllInterfaces() { final InetSocketAddress socketAddress = service.socketAddress(); assertThat("0.0.0.0").isEqualTo(socketAddress.getAddress().getHostAddress()); assertThat(socketAddress.getPort() > 0).isTrue(); - assertThat(!service.url().contains("0.0.0.0")).isTrue(); } finally { service.stop().join(); } From f3178fad1538900fe5a6800da797850867c11dea Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Mon, 17 Jun 2019 11:57:52 +1000 Subject: [PATCH 07/11] Fix tests. --- .../pegasys/pantheon/cli/PantheonCommandTest.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java index 049bcd3952..3df9ec3432 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java @@ -112,7 +112,8 @@ public class PantheonCommandTest extends CommandTestAbstract { defaultWebSocketConfiguration = WebSocketConfiguration.createDefault(); - defaultMetricsConfiguration = MetricsConfiguration.createDefault(); + defaultMetricsConfiguration = + MetricsConfiguration.builder().applicationPrefix("pantheon_").build(); } @Test @@ -298,7 +299,12 @@ public void overrideDefaultValuesIfKeyIsPresentInConfigFile() throws IOException webSocketConfiguration.setRpcApis(expectedApis); final MetricsConfiguration metricsConfiguration = - MetricsConfiguration.builder().enabled(false).host("8.6.7.5").port(309).build(); + MetricsConfiguration.builder() + .enabled(false) + .host("8.6.7.5") + .port(309) + .applicationPrefix("pantheon_") + .build(); parseCommand("--config-file", toml.toString()); @@ -699,7 +705,8 @@ public void noOverrideDefaultValuesIfKeyIsNotPresentInConfigFile() throws IOExce final WebSocketConfiguration webSocketConfiguration = WebSocketConfiguration.createDefault(); - final MetricsConfiguration metricsConfiguration = MetricsConfiguration.createDefault(); + final MetricsConfiguration metricsConfiguration = + MetricsConfiguration.builder().applicationPrefix("pantheon_").build(); verify(mockRunnerBuilder).discovery(eq(true)); verify(mockRunnerBuilder) From a2e50be48ce6aa84bbd80e9bddd512a2cfbcea6e Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Tue, 18 Jun 2019 14:30:32 +1000 Subject: [PATCH 08/11] Retrieve application prefix directly from the metric category instead of making it a config item. --- .../pantheon/metrics/MetricCategory.java | 4 ++- .../metrics/PantheonMetricCategory.java | 6 +++-- .../metrics/StandardMetricCategory.java | 6 +++-- .../prometheus/MetricsConfiguration.java | 25 +++---------------- .../prometheus/PrometheusMetricsSystem.java | 13 +++------- .../PrometheusMetricsSystemTest.java | 2 +- .../pegasys/pantheon/cli/PantheonCommand.java | 1 - .../pantheon/cli/PantheonCommandTest.java | 13 +++------- 8 files changed, 22 insertions(+), 48 deletions(-) diff --git a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/MetricCategory.java b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/MetricCategory.java index 868aff7ac3..6f6de531f8 100644 --- a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/MetricCategory.java +++ b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/MetricCategory.java @@ -12,9 +12,11 @@ */ package tech.pegasys.pantheon.metrics; +import java.util.Optional; + public interface MetricCategory { String getName(); - boolean isApplicationSpecific(); + Optional getAppliationPrefix(); } diff --git a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/PantheonMetricCategory.java b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/PantheonMetricCategory.java index 49df78807b..289d09d09c 100644 --- a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/PantheonMetricCategory.java +++ b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/PantheonMetricCategory.java @@ -13,6 +13,7 @@ package tech.pegasys.pantheon.metrics; import java.util.EnumSet; +import java.util.Optional; import java.util.Set; import com.google.common.collect.ImmutableSet; @@ -29,6 +30,7 @@ public enum PantheonMetricCategory implements MetricCategory { SYNCHRONIZER("synchronizer"), TRANSACTION_POOL("transaction_pool"); + private static final Optional PANTHEON_PREFIX = Optional.of("pantheon_"); public static final Set DEFAULT_METRIC_CATEGORIES; static { @@ -61,7 +63,7 @@ public String getName() { } @Override - public boolean isApplicationSpecific() { - return pantheonSpecific; + public Optional getAppliationPrefix() { + return pantheonSpecific ? PANTHEON_PREFIX : Optional.empty(); } } diff --git a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/StandardMetricCategory.java b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/StandardMetricCategory.java index c603edf372..76e8fcdc47 100644 --- a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/StandardMetricCategory.java +++ b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/StandardMetricCategory.java @@ -12,6 +12,8 @@ */ package tech.pegasys.pantheon.metrics; +import java.util.Optional; + public enum StandardMetricCategory implements MetricCategory { JVM("jvm"), PROCESS("process"); @@ -28,7 +30,7 @@ public String getName() { } @Override - public boolean isApplicationSpecific() { - return false; + public Optional getAppliationPrefix() { + return Optional.empty(); } } diff --git a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsConfiguration.java b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsConfiguration.java index b47d8fae66..40eda94164 100644 --- a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsConfiguration.java +++ b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsConfiguration.java @@ -42,7 +42,6 @@ public class MetricsConfiguration { private final int pushInterval; private final String prometheusJob; private final List hostsWhitelist; - private final String applicationPrefix; public static MetricsConfiguration createDefault() { return builder().build(); @@ -62,8 +61,7 @@ private MetricsConfiguration( final String pushHost, final int pushInterval, final String prometheusJob, - final List hostsWhitelist, - final String applicationPrefix) { + final List hostsWhitelist) { this.enabled = enabled; this.port = port; this.host = host; @@ -74,7 +72,6 @@ private MetricsConfiguration( this.pushInterval = pushInterval; this.prometheusJob = prometheusJob; this.hostsWhitelist = hostsWhitelist; - this.applicationPrefix = applicationPrefix; } public boolean isEnabled() { @@ -117,10 +114,6 @@ Collection getHostsWhitelist() { return Collections.unmodifiableCollection(this.hostsWhitelist); } - public String getApplicationPrefix() { - return applicationPrefix; - } - @Override public String toString() { return MoreObjects.toStringHelper(this) @@ -134,7 +127,6 @@ public String toString() { .add("pushInterval", pushInterval) .add("prometheusJob", prometheusJob) .add("hostsWhitelist", hostsWhitelist) - .add("applicationPrefix", applicationPrefix) .toString(); } @@ -156,8 +148,7 @@ public boolean equals(final Object o) { && Objects.equals(metricCategories, that.metricCategories) && Objects.equals(pushHost, that.pushHost) && Objects.equals(prometheusJob, that.prometheusJob) - && Objects.equals(hostsWhitelist, that.hostsWhitelist) - && Objects.equals(applicationPrefix, that.applicationPrefix); + && Objects.equals(hostsWhitelist, that.hostsWhitelist); } @Override @@ -172,8 +163,7 @@ public int hashCode() { pushHost, pushInterval, prometheusJob, - hostsWhitelist, - applicationPrefix); + hostsWhitelist); } public static class Builder { @@ -187,7 +177,6 @@ public static class Builder { private int pushInterval = 15; private String prometheusJob = "pantheon-client"; private List hostsWhitelist = Arrays.asList("localhost", "127.0.0.1"); - private String applicationPrefix = ""; private Builder() {} @@ -241,11 +230,6 @@ public Builder hostsWhitelist(final List hostsWhitelist) { return this; } - public Builder applicationPrefix(final String applicationPrefix) { - this.applicationPrefix = applicationPrefix; - return this; - } - public MetricsConfiguration build() { return new MetricsConfiguration( enabled, @@ -257,8 +241,7 @@ public MetricsConfiguration build() { pushHost, pushInterval, prometheusJob, - hostsWhitelist, - applicationPrefix); + hostsWhitelist); } } } diff --git a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystem.java b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystem.java index 0d2a4dedda..c8d300fb7e 100644 --- a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystem.java +++ b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystem.java @@ -58,12 +58,9 @@ public class PrometheusMetricsSystem implements MetricsSystem { cachedTimers = new ConcurrentHashMap<>(); private final Set enabledCategories; - private final String applicationPrefix; - PrometheusMetricsSystem( - final Set enabledCategories, final String applicationPrefix) { + PrometheusMetricsSystem(final Set enabledCategories) { this.enabledCategories = ImmutableSet.copyOf(enabledCategories); - this.applicationPrefix = applicationPrefix; } public static MetricsSystem init(final MetricsConfiguration metricsConfiguration) { @@ -71,9 +68,7 @@ public static MetricsSystem init(final MetricsConfiguration metricsConfiguration return new NoOpMetricsSystem(); } final PrometheusMetricsSystem metricsSystem = - new PrometheusMetricsSystem( - metricsConfiguration.getMetricCategories(), - metricsConfiguration.getApplicationPrefix()); + new PrometheusMetricsSystem(metricsConfiguration.getMetricCategories()); if (metricsSystem.isCategoryEnabled(StandardMetricCategory.PROCESS)) { metricsSystem.collectors.put( StandardMetricCategory.PROCESS, @@ -246,9 +241,7 @@ private String convertFromPrometheusName(final MetricCategory category, final St } private String prometheusPrefix(final MetricCategory category) { - return category.isApplicationSpecific() - ? applicationPrefix + category.getName() + "_" - : category.getName() + "_"; + return category.getAppliationPrefix().orElse("") + category.getName() + "_"; } CollectorRegistry getRegistry() { diff --git a/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystemTest.java b/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystemTest.java index c38ee8a186..749d919caf 100644 --- a/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystemTest.java +++ b/metrics/core/src/test/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystemTest.java @@ -45,7 +45,7 @@ public class PrometheusMetricsSystemTest { .thenComparing((o1, o2) -> o1.getLabels().equals(o2.getLabels()) ? 0 : 1); private final MetricsSystem metricsSystem = - new PrometheusMetricsSystem(DEFAULT_METRIC_CATEGORIES, "pantheon_"); + new PrometheusMetricsSystem(DEFAULT_METRIC_CATEGORIES); @Test public void shouldCreateObservationFromCounter() { diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java index d7b3777125..ddf5ae1d4b 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -957,7 +957,6 @@ MetricsConfiguration metricsConfiguration() { .pushInterval(metricsPushInterval) .hostsWhitelist(hostsWhitelist) .prometheusJob(metricsPrometheusJob) - .applicationPrefix("pantheon_") .build(); } diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java index 3df9ec3432..7873d67da6 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java @@ -112,8 +112,7 @@ public class PantheonCommandTest extends CommandTestAbstract { defaultWebSocketConfiguration = WebSocketConfiguration.createDefault(); - defaultMetricsConfiguration = - MetricsConfiguration.builder().applicationPrefix("pantheon_").build(); + defaultMetricsConfiguration = MetricsConfiguration.builder().build(); } @Test @@ -299,12 +298,7 @@ public void overrideDefaultValuesIfKeyIsPresentInConfigFile() throws IOException webSocketConfiguration.setRpcApis(expectedApis); final MetricsConfiguration metricsConfiguration = - MetricsConfiguration.builder() - .enabled(false) - .host("8.6.7.5") - .port(309) - .applicationPrefix("pantheon_") - .build(); + MetricsConfiguration.builder().enabled(false).host("8.6.7.5").port(309).build(); parseCommand("--config-file", toml.toString()); @@ -705,8 +699,7 @@ public void noOverrideDefaultValuesIfKeyIsNotPresentInConfigFile() throws IOExce final WebSocketConfiguration webSocketConfiguration = WebSocketConfiguration.createDefault(); - final MetricsConfiguration metricsConfiguration = - MetricsConfiguration.builder().applicationPrefix("pantheon_").build(); + final MetricsConfiguration metricsConfiguration = MetricsConfiguration.builder().build(); verify(mockRunnerBuilder).discovery(eq(true)); verify(mockRunnerBuilder) From 0a97b9ad3bde1dd9c21118811ebf3788105ff172 Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Wed, 19 Jun 2019 09:36:11 +1000 Subject: [PATCH 09/11] Spotless --- .../main/java/tech/pegasys/pantheon/metrics/MetricsSystem.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/MetricsSystem.java b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/MetricsSystem.java index 5bb88b33df..d4364daa3c 100644 --- a/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/MetricsSystem.java +++ b/metrics/core/src/main/java/tech/pegasys/pantheon/metrics/MetricsSystem.java @@ -35,8 +35,7 @@ default OperationTimer createTimer( LabelledMetric createLabelledTimer( MetricCategory category, String name, String help, String... labelNames); - void createGauge( - MetricCategory category, String name, String help, DoubleSupplier valueSupplier); + void createGauge(MetricCategory category, String name, String help, DoubleSupplier valueSupplier); default void createIntegerGauge( final MetricCategory category, From 5a3bccdf2c1dfc771450b0561f3d9cdda05153f9 Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Wed, 19 Jun 2019 09:49:42 +1000 Subject: [PATCH 10/11] Reduce changes. --- pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java index c23376022d..0957b92a80 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java @@ -360,7 +360,7 @@ private WebSocketConfiguration wsRpcConfiguration() { } private MetricsConfiguration metricsConfiguration() { - return MetricsConfiguration.builder().port(0).enabled(false).build(); + return MetricsConfiguration.builder().enabled(false).port(0).build(); } private static void setupState( From 83c105bcc4c5b28253eb949563b29c2984d6fd28 Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Wed, 19 Jun 2019 11:16:33 +1000 Subject: [PATCH 11/11] Extract MetricCategoryConverter into a separate class. --- .../pegasys/pantheon/cli/PantheonCommand.java | 25 +++--------- .../converter/MetricCategoryConverter.java | 40 +++++++++++++++++++ 2 files changed, 45 insertions(+), 20 deletions(-) create mode 100644 pantheon/src/main/java/tech/pegasys/pantheon/cli/converter/MetricCategoryConverter.java diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java index ddf5ae1d4b..7d29a5bf36 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -31,6 +31,7 @@ import tech.pegasys.pantheon.Runner; import tech.pegasys.pantheon.RunnerBuilder; import tech.pegasys.pantheon.cli.PublicKeySubCommand.KeyLoader; +import tech.pegasys.pantheon.cli.converter.MetricCategoryConverter; import tech.pegasys.pantheon.cli.converter.RpcApisConverter; import tech.pegasys.pantheon.cli.custom.CorsAllowedOriginsProperty; import tech.pegasys.pantheon.cli.custom.JsonRPCWhitelistHostsProperty; @@ -92,10 +93,7 @@ import java.time.Clock; import java.util.ArrayList; import java.util.Collection; -import java.util.EnumSet; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.function.Supplier; @@ -655,18 +653,10 @@ public void parse( commandLine.registerConverter(Wei.class, (arg) -> Wei.of(Long.parseUnsignedLong(arg))); commandLine.registerConverter(PositiveNumber.class, PositiveNumber::fromString); - final Map metricCategories = new HashMap<>(); - addCategories(metricCategories, PantheonMetricCategory.class); - addCategories(metricCategories, StandardMetricCategory.class); - commandLine.registerConverter( - MetricCategory.class, - arg -> { - final MetricCategory category = metricCategories.get(arg); - if (category == null) { - throw new IllegalArgumentException("Unknown category: " + arg); - } - return category; - }); + final MetricCategoryConverter metricCategoryConverter = new MetricCategoryConverter(); + metricCategoryConverter.addCategories(PantheonMetricCategory.class); + metricCategoryConverter.addCategories(StandardMetricCategory.class); + commandLine.registerConverter(MetricCategory.class, metricCategoryConverter); // Add performance options UnstableOptionsSubCommand.createUnstableOptions( @@ -691,11 +681,6 @@ public void parse( commandLine.parseWithHandlers(configParsingHandler, exceptionHandler, args); } - private & MetricCategory> void addCategories( - final Map categories, final Class categoryEnum) { - EnumSet.allOf(categoryEnum).forEach(category -> categories.put(category.name(), category)); - } - @Override public void run() { // set log level per CLI flags diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/converter/MetricCategoryConverter.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/converter/MetricCategoryConverter.java new file mode 100644 index 0000000000..24f6f5a949 --- /dev/null +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/converter/MetricCategoryConverter.java @@ -0,0 +1,40 @@ +/* + * Copyright 2019 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.cli.converter; + +import tech.pegasys.pantheon.metrics.MetricCategory; + +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map; + +import picocli.CommandLine; + +public class MetricCategoryConverter implements CommandLine.ITypeConverter { + + private final Map metricCategories = new HashMap<>(); + + @Override + public MetricCategory convert(final String value) { + final MetricCategory category = metricCategories.get(value); + if (category == null) { + throw new IllegalArgumentException("Unknown category: " + value); + } + return category; + } + + public & MetricCategory> void addCategories(final Class categoryEnum) { + EnumSet.allOf(categoryEnum) + .forEach(category -> metricCategories.put(category.name(), category)); + } +}