Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
Push Metrics don't work (#1164)
Browse files Browse the repository at this point in the history
When we added the no-op metrics optimization this broke push-metrics.
  • Loading branch information
shemnon authored Mar 26, 2019
1 parent 142d7b3 commit faebbc8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,34 @@ public void shouldOnlyObserveEnabledMetrics() {
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void run() {
try {
final MetricsConfiguration metricsConfiguration =
parentCommand.parentCommand.metricsConfiguration();
if (metricsConfiguration.isEnabled()) {
if (metricsConfiguration.isEnabled() || metricsConfiguration.isPushEnabled()) {
metricsService =
Optional.of(
MetricsService.create(
Expand Down

0 comments on commit faebbc8

Please sign in to comment.