From 366705e4e89f949ccd4d6147b1b6a0dcd55160e1 Mon Sep 17 00:00:00 2001 From: shemnon Date: Mon, 28 Jan 2019 10:34:51 -0700 Subject: [PATCH 1/4] Metrics Push Gateway dont' overload `--metrics-host` and `--metrics-port` for push mode, instead use `--metrics-push-host` and `--metrics-push-port`. The former is inbound, the latter is outbound. --- .../prometheus/MetricsConfiguration.java | 44 ++++++++++++++++++- .../prometheus/MetricsPushGatewayService.java | 8 ++-- .../pegasys/pantheon/cli/PantheonCommand.java | 20 +++++++++ .../pantheon/cli/PantheonCommandTest.java | 16 +++++++ .../src/test/resources/everything_config.toml | 2 + 5 files changed, 85 insertions(+), 5 deletions(-) diff --git a/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsConfiguration.java b/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsConfiguration.java index d9fdac4ba5..fd4d40ef6e 100644 --- a/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsConfiguration.java +++ b/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsConfiguration.java @@ -22,12 +22,17 @@ public class MetricsConfiguration { private static final String DEFAULT_METRICS_HOST = "127.0.0.1"; public static final int DEFAULT_METRICS_PORT = 9545; + private static final String DEFAULT_METRICS_PUSH_HOST = "127.0.0.1"; + public static final int DEFAULT_METRICS_PUSH_PORT = 9001; + public static final String MODE_PUSH_GATEWAY = "push"; public static final String MODE_SERVER_PULL = "pull"; private boolean enabled; private int port; private String host; + private int pushPort; + private String pushHost; private String mode; private int pushInterval; private String prometheusJob; @@ -38,6 +43,8 @@ public static MetricsConfiguration createDefault() { metricsConfiguration.setEnabled(false); metricsConfiguration.setPort(DEFAULT_METRICS_PORT); metricsConfiguration.setHost(DEFAULT_METRICS_HOST); + metricsConfiguration.setPushPort(DEFAULT_METRICS_PUSH_PORT); + metricsConfiguration.setPushHost(DEFAULT_METRICS_PUSH_HOST); metricsConfiguration.setMode(MODE_SERVER_PULL); metricsConfiguration.setPushInterval(15); metricsConfiguration.setPrometheusJob("pantheon-client"); @@ -71,6 +78,22 @@ public void setHost(final String host) { this.host = host; } + 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 String getMode() { return mode; } @@ -113,6 +136,19 @@ public String toString() { + ", host='" + host + '\'' + + ", pushPort=" + + pushPort + + ", pushHost='" + + pushHost + + '\'' + + ", mode='" + + mode + + '\'' + + ", pushInterval=" + + pushInterval + + ", prometheusJob='" + + prometheusJob + + '\'' + ", hostsWhitelist=" + hostsWhitelist + '}'; @@ -125,13 +161,19 @@ public boolean equals(final Object o) { final MetricsConfiguration that = (MetricsConfiguration) o; return enabled == that.enabled && port == that.port + && pushPort == that.pushPort + && pushInterval == that.pushInterval && Objects.equals(host, that.host) + && Objects.equals(pushHost, that.pushHost) + && Objects.equals(mode, that.mode) + && Objects.equals(prometheusJob, that.prometheusJob) && com.google.common.base.Objects.equal( Lists.newArrayList(hostsWhitelist), Lists.newArrayList(that.hostsWhitelist)); } @Override public int hashCode() { - return Objects.hash(enabled, port, host, hostsWhitelist); + return Objects.hash( + enabled, port, host, pushPort, pushHost, mode, pushInterval, prometheusJob, hostsWhitelist); } } diff --git a/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsPushGatewayService.java b/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsPushGatewayService.java index 56874e4244..e20e326f7c 100644 --- a/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsPushGatewayService.java +++ b/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsPushGatewayService.java @@ -45,9 +45,9 @@ class MetricsPushGatewayService implements MetricsService { private void validateConfig(final MetricsConfiguration config) { checkArgument( - config.getPort() == 0 || NetworkUtility.isValidPort(config.getPort()), + config.getPushPort() == 0 || NetworkUtility.isValidPort(config.getPushPort()), "Invalid port configuration."); - checkArgument(config.getHost() != null, "Required host is not configured."); + checkArgument(config.getPushHost() != null, "Required host is not configured."); checkArgument( MetricsConfiguration.MODE_PUSH_GATEWAY.equals(config.getMode()), "Metrics Push Gateway Service cannot start up outside of '" @@ -60,9 +60,9 @@ private void validateConfig(final MetricsConfiguration config) { @Override public CompletableFuture start() { - LOG.info("Starting Metrics service on {}:{}", config.getHost(), config.getPort()); + LOG.info("Starting Metrics service on {}:{}", config.getPushHost(), config.getPushPort()); - pushGateway = new PushGateway(config.getHost() + ":" + config.getPort()); + pushGateway = new PushGateway(config.getPushHost() + ":" + config.getPushPort()); // Create the executor scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); 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 a9c3ba3f68..b966714901 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -22,6 +22,7 @@ import static tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration.DEFAULT_WEBSOCKET_REFRESH_DELAY; import static tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeer.DEFAULT_PORT; 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; @@ -391,6 +392,23 @@ private Long configureRefreshDelay(final Long refreshDelay) { ) private final Integer metricsPort = DEFAULT_METRICS_PORT; + @Option( + names = {"--metrics-push-host"}, + paramLabel = MANDATORY_HOST_FORMAT_HELP, + description = "Host of the Prometheus Push Gateway for push mode (default: ${DEFAULT-VALUE})", + arity = "1" + ) + private final HostSpecifier metricsPushHost = + HostSpecifier.fromValid(autoDiscoverDefaultIP().getHostAddress()); + + @Option( + names = {"--metrics-push-port"}, + paramLabel = MANDATORY_PORT_FORMAT_HELP, + description = "Port of the Prometheus Push Gateway for push mode (default: ${DEFAULT-VALUE})", + arity = "1" + ) + private final Integer metricsPushPort = DEFAULT_METRICS_PUSH_PORT; + @Option( names = {"--metrics-push-interval"}, paramLabel = MANDATORY_INTEGER_FORMAT_HELP, @@ -674,6 +692,8 @@ MetricsConfiguration metricsConfiguration() { metricsConfiguration.setMode(metricsMode); metricsConfiguration.setHost(metricsHost.toString()); metricsConfiguration.setPort(metricsPort); + metricsConfiguration.setPushHost(metricsPushHost.toString()); + metricsConfiguration.setPushPort(metricsPushPort); metricsConfiguration.setPushInterval(metricsPushInterval); metricsConfiguration.setPrometheusJob(metricsPrometheusJob); metricsConfiguration.setHostsWhitelist(hostsWhitelist); 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 edd4791611..2003924903 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java @@ -1432,6 +1432,22 @@ public void metricsModeOptionMustBeUsed() { assertThat(commandErrorOutput.toString()).isEmpty(); } + @Test + public void metricsPushHostAndPushPortOptionMustBeUsed() { + final String host = "1.2.3.4"; + final int port = 1234; + parseCommand("--metrics-push-host", host, "--metrics-push-port", String.valueOf(port)); + + verify(mockRunnerBuilder).metricsConfiguration(metricsConfigArgumentCaptor.capture()); + verify(mockRunnerBuilder).build(); + + assertThat(metricsConfigArgumentCaptor.getValue().getPushHost()).isEqualTo(host); + assertThat(metricsConfigArgumentCaptor.getValue().getPushPort()).isEqualTo(port); + + assertThat(commandOutput.toString()).isEmpty(); + assertThat(commandErrorOutput.toString()).isEmpty(); + } + @Test public void metricsPushIntervalMustBeUsed() { parseCommand("--metrics-push-interval", "42"); diff --git a/pantheon/src/test/resources/everything_config.toml b/pantheon/src/test/resources/everything_config.toml index 262b07ae97..10734e1ec5 100644 --- a/pantheon/src/test/resources/everything_config.toml +++ b/pantheon/src/test/resources/everything_config.toml @@ -55,6 +55,8 @@ metrics-enabled=false metrics-mode="pull" metrics-host="8.6.7.5" metrics-port=309 +metrics-push-host="5.5.5.1" +metrics-push-port=212 metrics-push-interval=42 metrics-prometheus-job="pantheon-everything" From 7c0b9fbf9faa13f50b397638c79f1c0c54256ab4 Mon Sep 17 00:00:00 2001 From: shemnon Date: Mon, 28 Jan 2019 10:50:21 -0700 Subject: [PATCH 2/4] Metrics Push Gateway allow problematic shutdown. --- .../metrics/prometheus/MetricsPushGatewayService.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsPushGatewayService.java b/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsPushGatewayService.java index e20e326f7c..fc80839b94 100644 --- a/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsPushGatewayService.java +++ b/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsPushGatewayService.java @@ -81,9 +81,15 @@ public CompletableFuture stop() { // Calling shutdown now cancels the pending push, which is desirable. scheduledExecutorService.shutdownNow(); scheduledExecutorService.awaitTermination(30, TimeUnit.SECONDS); - pushGateway.delete(config.getPrometheusJob()); + try { + pushGateway.delete(config.getPrometheusJob()); + } catch (final Exception e) { + LOG.error("Could not clean up results on the Prometheus Push Gateway.", e); + // Do not complete exceptionally, the gateway may be down and failures + // here cause the shutdown to loop. Failure is acceptable. + } resultFuture.complete(null); - } catch (final IOException | InterruptedException e) { + } catch (final InterruptedException e) { LOG.error(e); resultFuture.completeExceptionally(e); } From e9a55f496347a7490dbcc84733416600fef327b9 Mon Sep 17 00:00:00 2001 From: shemnon Date: Mon, 28 Jan 2019 15:58:05 -0700 Subject: [PATCH 3/4] Metrics Push Gateway CLI change - go to --metrics-push-* instead and get reid of --metrics-mode. --- .../prometheus/MetricsConfiguration.java | 32 +++++++++++-------- .../prometheus/MetricsHttpService.java | 8 ++--- .../prometheus/MetricsPushGatewayService.java | 6 ++-- .../metrics/prometheus/MetricsService.java | 13 ++++---- .../pegasys/pantheon/cli/PantheonCommand.java | 18 +++++------ .../pantheon/cli/PantheonCommandTest.java | 8 ++--- .../src/test/resources/everything_config.toml | 4 +-- 7 files changed, 43 insertions(+), 46 deletions(-) diff --git a/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsConfiguration.java b/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsConfiguration.java index fd4d40ef6e..647f95927e 100644 --- a/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsConfiguration.java +++ b/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsConfiguration.java @@ -25,15 +25,12 @@ public class MetricsConfiguration { private static final String DEFAULT_METRICS_PUSH_HOST = "127.0.0.1"; public static final int DEFAULT_METRICS_PUSH_PORT = 9001; - public static final String MODE_PUSH_GATEWAY = "push"; - public static final String MODE_SERVER_PULL = "pull"; - private boolean enabled; private int port; private String host; + private boolean pushEnabled; private int pushPort; private String pushHost; - private String mode; private int pushInterval; private String prometheusJob; private Collection hostsWhitelist = Collections.singletonList("localhost"); @@ -43,9 +40,9 @@ public static MetricsConfiguration createDefault() { metricsConfiguration.setEnabled(false); metricsConfiguration.setPort(DEFAULT_METRICS_PORT); metricsConfiguration.setHost(DEFAULT_METRICS_HOST); + metricsConfiguration.setPushEnabled(false); metricsConfiguration.setPushPort(DEFAULT_METRICS_PUSH_PORT); metricsConfiguration.setPushHost(DEFAULT_METRICS_PUSH_HOST); - metricsConfiguration.setMode(MODE_SERVER_PULL); metricsConfiguration.setPushInterval(15); metricsConfiguration.setPrometheusJob("pantheon-client"); @@ -94,12 +91,12 @@ public void setPushHost(final String pushHost) { this.pushHost = pushHost; } - public String getMode() { - return mode; + public boolean isPushEnabled() { + return pushEnabled; } - public void setMode(final String mode) { - this.mode = mode; + public void setPushEnabled(final boolean pushEnabled) { + this.pushEnabled = pushEnabled; } public int getPushInterval() { @@ -136,14 +133,13 @@ public String toString() { + ", host='" + host + '\'' + + ", pushEnabled=" + + pushEnabled + ", pushPort=" + pushPort + ", pushHost='" + pushHost + '\'' - + ", mode='" - + mode - + '\'' + ", pushInterval=" + pushInterval + ", prometheusJob='" @@ -161,11 +157,11 @@ public boolean equals(final Object o) { final MetricsConfiguration that = (MetricsConfiguration) o; return enabled == that.enabled && port == that.port + && pushEnabled == that.pushEnabled && pushPort == that.pushPort && pushInterval == that.pushInterval && Objects.equals(host, that.host) && Objects.equals(pushHost, that.pushHost) - && Objects.equals(mode, that.mode) && Objects.equals(prometheusJob, that.prometheusJob) && com.google.common.base.Objects.equal( Lists.newArrayList(hostsWhitelist), Lists.newArrayList(that.hostsWhitelist)); @@ -174,6 +170,14 @@ public boolean equals(final Object o) { @Override public int hashCode() { return Objects.hash( - enabled, port, host, pushPort, pushHost, mode, pushInterval, prometheusJob, hostsWhitelist); + enabled, + port, + host, + pushEnabled, + pushPort, + pushHost, + pushInterval, + prometheusJob, + hostsWhitelist); } } diff --git a/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsHttpService.java b/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsHttpService.java index 75a142595e..fdb988c80d 100644 --- a/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsHttpService.java +++ b/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsHttpService.java @@ -73,12 +73,8 @@ private void validateConfig(final MetricsConfiguration config) { "Invalid port configuration."); checkArgument(config.getHost() != null, "Required host is not configured."); checkArgument( - MetricsConfiguration.MODE_SERVER_PULL.equals(config.getMode()), - "Metrics Http Service cannot start up outside of '" - + MetricsConfiguration.MODE_SERVER_PULL - + "' mode, requested mode is '" - + config.getMode() - + "'."); + !(config.isEnabled() && config.isPushEnabled()), + "Metrics Http Service cannot run concurrent with push metrics."); } @Override diff --git a/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsPushGatewayService.java b/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsPushGatewayService.java index fc80839b94..7231808675 100644 --- a/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsPushGatewayService.java +++ b/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsPushGatewayService.java @@ -49,10 +49,8 @@ private void validateConfig(final MetricsConfiguration config) { "Invalid port configuration."); checkArgument(config.getPushHost() != null, "Required host is not configured."); checkArgument( - MetricsConfiguration.MODE_PUSH_GATEWAY.equals(config.getMode()), - "Metrics Push Gateway Service cannot start up outside of '" - + MetricsConfiguration.MODE_PUSH_GATEWAY - + "' mode."); + !(config.isEnabled() && config.isPushEnabled()), + "Metrics Push Gateway Service cannot run concurrent with the normal metrics."); checkArgument( metricsSystem instanceof PrometheusMetricsSystem, "Push Gateway requires a Prometheus Metrics System."); diff --git a/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsService.java b/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsService.java index 0104335e1b..64ba734957 100644 --- a/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsService.java +++ b/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/MetricsService.java @@ -25,13 +25,12 @@ static MetricsService create( final Vertx vertx, final MetricsConfiguration configuration, final MetricsSystem metricsSystem) { - switch (configuration.getMode()) { - case MetricsConfiguration.MODE_PUSH_GATEWAY: - return new MetricsPushGatewayService(configuration, metricsSystem); - case MetricsConfiguration.MODE_SERVER_PULL: - return new MetricsHttpService(vertx, configuration, metricsSystem); - default: - throw new RuntimeException("No metrics service for mode '" + configuration.getMode() + "'"); + if (configuration.isEnabled()) { + return new MetricsPushGatewayService(configuration, metricsSystem); + } else if (configuration.isPushEnabled()) { + return new MetricsHttpService(vertx, configuration, metricsSystem); + } else { + throw new RuntimeException("No metrics service enabled."); } } 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 b966714901..bfff785d37 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -368,13 +368,6 @@ private Long configureRefreshDelay(final Long refreshDelay) { ) private final Boolean isMetricsEnabled = false; - @Option( - names = {"--metrics-mode"}, - description = - "Mode for the metrics service to run in, 'push' or 'pull' (default: ${DEFAULT-VALUE})" - ) - private String metricsMode = MetricsConfiguration.MODE_SERVER_PULL; - @Option( names = {"--metrics-host"}, paramLabel = MANDATORY_HOST_FORMAT_HELP, @@ -392,6 +385,13 @@ private Long configureRefreshDelay(final Long refreshDelay) { ) private final Integer metricsPort = DEFAULT_METRICS_PORT; + @Option( + names = {"--metrics-push-enabled"}, + description = + "Set if the metrics push gateway integration should be started (default: ${DEFAULT-VALUE})" + ) + private Boolean isMetricsPushEnabled = false; + @Option( names = {"--metrics-push-host"}, paramLabel = MANDATORY_HOST_FORMAT_HELP, @@ -419,7 +419,7 @@ private Long configureRefreshDelay(final Long refreshDelay) { private final Integer metricsPushInterval = 15; @Option( - names = {"--metrics-prometheus-job"}, + names = {"--metrics-push-prometheus-job"}, description = "Job name to use when in push mode (default: ${DEFAULT-VALUE})", arity = "1" ) @@ -689,9 +689,9 @@ private WebSocketConfiguration webSocketConfiguration() { MetricsConfiguration metricsConfiguration() { final MetricsConfiguration metricsConfiguration = createDefault(); metricsConfiguration.setEnabled(isMetricsEnabled); - metricsConfiguration.setMode(metricsMode); metricsConfiguration.setHost(metricsHost.toString()); metricsConfiguration.setPort(metricsPort); + metricsConfiguration.setPushEnabled(isMetricsPushEnabled); metricsConfiguration.setPushHost(metricsPushHost.toString()); metricsConfiguration.setPushPort(metricsPushPort); metricsConfiguration.setPushInterval(metricsPushInterval); 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 2003924903..76ab106599 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java @@ -1420,13 +1420,13 @@ public void metricsHostAndPortOptionMustBeUsed() { } @Test - public void metricsModeOptionMustBeUsed() { - parseCommand("--metrics-mode", "pull"); + public void metricsPushEnabledPropertyMustBeUsed() { + parseCommand("--metrics-push-enabled"); verify(mockRunnerBuilder).metricsConfiguration(metricsConfigArgumentCaptor.capture()); verify(mockRunnerBuilder).build(); - assertThat(metricsConfigArgumentCaptor.getValue().getMode()).isEqualTo("pull"); + assertThat(metricsConfigArgumentCaptor.getValue().isPushEnabled()).isTrue(); assertThat(commandOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty(); @@ -1463,7 +1463,7 @@ public void metricsPushIntervalMustBeUsed() { @Test public void metricsPrometheusJobMustBeUsed() { - parseCommand("--metrics-prometheus-job", "pantheon-command-test"); + parseCommand("--metrics-push-prometheus-job", "pantheon-command-test"); verify(mockRunnerBuilder).metricsConfiguration(metricsConfigArgumentCaptor.capture()); verify(mockRunnerBuilder).build(); diff --git a/pantheon/src/test/resources/everything_config.toml b/pantheon/src/test/resources/everything_config.toml index 10734e1ec5..e5dba34854 100644 --- a/pantheon/src/test/resources/everything_config.toml +++ b/pantheon/src/test/resources/everything_config.toml @@ -52,13 +52,13 @@ rpc-ws-refresh-delay=500 # Prometheus Metrics Endpoint metrics-enabled=false -metrics-mode="pull" metrics-host="8.6.7.5" metrics-port=309 +metrics-push-enabled=false metrics-push-host="5.5.5.1" metrics-push-port=212 metrics-push-interval=42 -metrics-prometheus-job="pantheon-everything" +metrics-push-prometheus-job="pantheon-everything" # Mining miner-enabled=false From 21479b7999a49a1de1a81b524f52cbbccc2feb65 Mon Sep 17 00:00:00 2001 From: shemnon Date: Mon, 28 Jan 2019 16:41:08 -0700 Subject: [PATCH 4/4] Metrics Push Gateway add error if both metrics and metrics-push are enabled. --- .../pegasys/pantheon/cli/PantheonCommand.java | 11 +++++++++-- .../pantheon/cli/PantheonCommandTest.java | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) 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 bfff785d37..dc45094c7f 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -687,6 +687,13 @@ private WebSocketConfiguration webSocketConfiguration() { } MetricsConfiguration metricsConfiguration() { + if (isMetricsEnabled && isMetricsPushEnabled) { + throw new ParameterException( + new CommandLine(this), + "--metrics-enabled option and --metrics-push-enabled option can't be used at the same " + + "time. Please refer to CLI reference for more details about this constraint."); + } + final MetricsConfiguration metricsConfiguration = createDefault(); metricsConfiguration.setEnabled(isMetricsEnabled); metricsConfiguration.setHost(metricsHost.toString()); @@ -805,8 +812,8 @@ private EthNetworkConfig updateNetworkConfig(final NetworkName network) { // conflict error throw new ParameterException( new CommandLine(this), - "--network option and --genesis-file option can't be used at the same time." - + "Please refer to CLI reference for more details about this constraint."); + "--network option and --genesis-file option can't be used at the same time. Please " + + "refer to CLI reference for more details about this constraint."); } builder.setGenesisConfig(genesisConfig()); 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 76ab106599..ded07b80f3 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java @@ -1475,6 +1475,23 @@ public void metricsPrometheusJobMustBeUsed() { assertThat(commandErrorOutput.toString()).isEmpty(); } + @Test + public void metricsAndMetricsPushMustNotBeUsedTogether() throws Exception { + assumeTrue(isFullInstantiation()); + + final Path genesisFile = createFakeGenesisFile(GENESIS_VALID_JSON); + final ArgumentCaptor networkArg = + ArgumentCaptor.forClass(EthNetworkConfig.class); + + parseCommand("--metrics-enabled", "--metrics-push-enabled"); + + verifyZeroInteractions(mockRunnerBuilder); + + assertThat(commandOutput.toString()).isEmpty(); + assertThat(commandErrorOutput.toString()) + .startsWith("--metrics-enabled option and --metrics-push-enabled option can't be used"); + } + @Test public void pantheonDoesNotStartInMiningModeIfCoinbaseNotSet() { parseCommand("--miner-enabled");