From 69818f6f928222754cd1042cf947442c4130cf9b Mon Sep 17 00:00:00 2001 From: Danno Ferrin Date: Tue, 26 Mar 2019 08:21:51 -0600 Subject: [PATCH] Push Metrics don't work (#1164) When we added the no-op metrics optimization this broke push-metrics. Signed-off-by: Adrian Sutton --- .../prometheus/PrometheusMetricsSystem.java | 2 +- .../PrometheusMetricsSystemTest.java | 30 +++++++++++++++++++ .../pantheon/cli/BlocksSubCommand.java | 2 +- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystem.java b/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystem.java index 9b2bf0e672..ef0523789c 100644 --- a/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystem.java +++ b/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystem.java @@ -61,7 +61,7 @@ public class PrometheusMetricsSystem implements MetricsSystem { PrometheusMetricsSystem() {} public static MetricsSystem init(final MetricsConfiguration metricsConfiguration) { - if (!metricsConfiguration.isEnabled()) { + if (!metricsConfiguration.isEnabled() && !metricsConfiguration.isPushEnabled()) { return new NoOpMetricsSystem(); } final PrometheusMetricsSystem metricsSystem = new PrometheusMetricsSystem(); diff --git a/metrics/src/test/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystemTest.java b/metrics/src/test/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystemTest.java index 06cc324170..de37516835 100644 --- a/metrics/src/test/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystemTest.java +++ b/metrics/src/test/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystemTest.java @@ -195,4 +195,34 @@ public class PrometheusMetricsSystemTest { assertThat(localMetricSystem.getMetrics()) .containsExactly(new Observation(RPC, "name", 1.0, singletonList("op"))); } + + @Test + public void returnsNoOpMetricsWhenAllDisabled() { + final MetricsConfiguration metricsConfiguration = MetricsConfiguration.createDefault(); + metricsConfiguration.setEnabled(false); + metricsConfiguration.setPushEnabled(false); + final MetricsSystem localMetricSystem = PrometheusMetricsSystem.init(metricsConfiguration); + + assertThat(localMetricSystem).isInstanceOf(NoOpMetricsSystem.class); + } + + @Test + public void returnsPrometheusMetricsWhenEnabled() { + final MetricsConfiguration metricsConfiguration = MetricsConfiguration.createDefault(); + metricsConfiguration.setEnabled(true); + metricsConfiguration.setPushEnabled(false); + final MetricsSystem localMetricSystem = PrometheusMetricsSystem.init(metricsConfiguration); + + assertThat(localMetricSystem).isInstanceOf(PrometheusMetricsSystem.class); + } + + @Test + public void returnsNoOpMetricsWhenPushEnabled() { + final MetricsConfiguration metricsConfiguration = MetricsConfiguration.createDefault(); + metricsConfiguration.setEnabled(false); + metricsConfiguration.setPushEnabled(true); + final MetricsSystem localMetricSystem = PrometheusMetricsSystem.init(metricsConfiguration); + + assertThat(localMetricSystem).isInstanceOf(PrometheusMetricsSystem.class); + } } diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/BlocksSubCommand.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/BlocksSubCommand.java index e5e455cf7f..9d21d11e3c 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/BlocksSubCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/BlocksSubCommand.java @@ -105,7 +105,7 @@ class BlocksSubCommand implements Runnable { try { final MetricsConfiguration metricsConfiguration = parentCommand.parentCommand.metricsConfiguration(); - if (metricsConfiguration.isEnabled()) { + if (metricsConfiguration.isEnabled() || metricsConfiguration.isPushEnabled()) { metricsService = Optional.of( MetricsService.create(