]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-15768 switch 0/1 logic
authorPierre <pierre.guillot@sonarsource.com>
Mon, 13 Dec 2021 09:04:44 +0000 (10:04 +0100)
committerLukasz Jarocki <lukasz.jarocki@sonarsource.com>
Mon, 13 Dec 2021 14:22:58 +0000 (15:22 +0100)
server/sonar-webserver-monitoring/src/main/java/org/sonar/server/monitoring/ServerMonitoringMetrics.java
server/sonar-webserver-monitoring/src/test/java/org/sonar/server/monitoring/ServerMonitoringMetricsTest.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/SafeModeMonitoringMetricAction.java

index ad69899ab92a994b68d7ddac7fa7caf7a62a194a..255bab082ec872bc43d73e8c589664f7b62e58c1 100644 (file)
@@ -70,12 +70,12 @@ public class ServerMonitoringMetrics {
 
     computeEngineGauge = Gauge.build()
       .name("sonarqube_heath_compute_engine_status")
-      .help("Tells whether Compute Engine is up (healthy, ready to take tasks) or down. 0 for up, 1 for down")
+      .help("Tells whether Compute Engine is up (healthy, ready to take tasks) or down. 1 for up, 0 for down")
       .register();
 
     elasticsearchGauge = Gauge.build()
       .name("sonarqube_heath_elasticsearch_status")
-      .help("Tells whether Elasticsearch is up or down. 0 for Up, 1 for down")
+      .help("Tells whether Elasticsearch is up or down. 1 for Up, 0 for down")
       .register();
 
   }
@@ -121,18 +121,18 @@ public class ServerMonitoringMetrics {
   }
 
   public void setComputeEngineStatusToGreen() {
-    computeEngineGauge.set(0);
+    computeEngineGauge.set(1);
   }
 
   public void setComputeEngineStatusToRed() {
-    computeEngineGauge.set(1);
+    computeEngineGauge.set(0);
   }
 
   public void setElasticSearchStatusToGreen() {
-    elasticsearchGauge.set(0);
+    elasticsearchGauge.set(1);
   }
 
   public void setElasticSearchStatusToRed() {
-    elasticsearchGauge.set(1);
+    elasticsearchGauge.set(0);
   }
 }
index 13b99bc7456dc70589808a6547907ebfa1d95621..7e67a8171415e370424e9d25404a5f70d5a9c132 100644 (file)
@@ -60,8 +60,8 @@ public class ServerMonitoringMetricsTest {
     assertThat(CollectorRegistry.defaultRegistry.getSampleValue("gitlab_config_ok")).isZero();
     assertThat(CollectorRegistry.defaultRegistry.getSampleValue("bitbucket_config_ok")).isZero();
     assertThat(CollectorRegistry.defaultRegistry.getSampleValue("azure_config_ok")).isZero();
-    assertThat(CollectorRegistry.defaultRegistry.getSampleValue("sonarqube_heath_compute_engine_status")).isZero();
-    assertThat(CollectorRegistry.defaultRegistry.getSampleValue("sonarqube_heath_elasticsearch_status")).isZero();
+    assertThat(CollectorRegistry.defaultRegistry.getSampleValue("sonarqube_heath_compute_engine_status")).isPositive();
+    assertThat(CollectorRegistry.defaultRegistry.getSampleValue("sonarqube_heath_elasticsearch_status")).isPositive();
   }
 
   @Test
@@ -79,8 +79,8 @@ public class ServerMonitoringMetricsTest {
     assertThat(CollectorRegistry.defaultRegistry.getSampleValue("gitlab_config_ok")).isEqualTo(1);
     assertThat(CollectorRegistry.defaultRegistry.getSampleValue("bitbucket_config_ok")).isEqualTo(1);
     assertThat(CollectorRegistry.defaultRegistry.getSampleValue("azure_config_ok")).isEqualTo(1);
-    assertThat(CollectorRegistry.defaultRegistry.getSampleValue("sonarqube_heath_compute_engine_status")).isEqualTo(1);
-    assertThat(CollectorRegistry.defaultRegistry.getSampleValue("sonarqube_heath_elasticsearch_status")).isEqualTo(1);
+    assertThat(CollectorRegistry.defaultRegistry.getSampleValue("sonarqube_heath_compute_engine_status")).isZero();
+    assertThat(CollectorRegistry.defaultRegistry.getSampleValue("sonarqube_heath_elasticsearch_status")).isZero();
   }
 
   @Test
index 87d6c75c0cefcb5ad136182877c2f5f270b38981..29263a32a30959b7739fa6563e7b84eb57b6cb2c 100644 (file)
@@ -37,7 +37,8 @@ import static java.nio.charset.StandardCharsets.UTF_8;
 
 public class SafeModeMonitoringMetricAction implements MonitoringWsAction {
 
-  protected static final Gauge isWebUpGauge = Gauge.build().name("sonarqube_heath_web_status").help("Tells whether web service is up").register();
+  protected static final Gauge isWebUpGauge = Gauge.build().name("sonarqube_heath_web_status")
+    .help("Tells whether Web process is up or down. 1 for up, 0 for down").register();
 
   private final SystemPasscode systemPasscode;
   private final BearerPasscode bearerPasscode;
@@ -50,7 +51,7 @@ public class SafeModeMonitoringMetricAction implements MonitoringWsAction {
   @Override
   public void define(WebService.NewController context) {
     context.createAction("metrics").setHandler(this);
-    isWebUpGauge.set(0D);
+    isWebUpGauge.set(1D);
   }
 
   @Override