diff options
author | Pierre <pierre.guillot@sonarsource.com> | 2021-12-13 10:35:43 +0100 |
---|---|---|
committer | Lukasz Jarocki <lukasz.jarocki@sonarsource.com> | 2021-12-13 15:22:58 +0100 |
commit | 8eb0cbd1c418311220e57cc259165aff5b559516 (patch) | |
tree | e107d035cddd19247f7d85fc9306335d65d0d271 /server | |
parent | 86fff2bc2be8624fdd7b88d6b6356769c418dd1d (diff) | |
download | sonarqube-8eb0cbd1c418311220e57cc259165aff5b559516.tar.gz sonarqube-8eb0cbd1c418311220e57cc259165aff5b559516.zip |
SONAR-15769 switch 0/1 logic
Diffstat (limited to 'server')
7 files changed, 73 insertions, 56 deletions
diff --git a/server/sonar-webserver-monitoring/src/main/java/org/sonar/server/monitoring/ServerMonitoringMetrics.java b/server/sonar-webserver-monitoring/src/main/java/org/sonar/server/monitoring/ServerMonitoringMetrics.java index 255bab082ec..512b169c895 100644 --- a/server/sonar-webserver-monitoring/src/main/java/org/sonar/server/monitoring/ServerMonitoringMetrics.java +++ b/server/sonar-webserver-monitoring/src/main/java/org/sonar/server/monitoring/ServerMonitoringMetrics.java @@ -26,10 +26,12 @@ import org.sonar.api.server.ServerSide; @ServerSide public class ServerMonitoringMetrics { - private final Gauge githubConfigOk; - private final Gauge gitlabConfigOk; - private final Gauge bitbucketConfigOk; - private final Gauge azureConfigOk; + public static final int UP_STATUS = 1; + public static final int DOWN_STATUS = 0; + private final Gauge githubHealthIntegrationStatus; + private final Gauge gitlabHealthIntegrationStatus; + private final Gauge bitbucketHealthIntegrationStatus; + private final Gauge azureHealthIntegrationStatus; private final Gauge computeEngineGauge; private final Gauge elasticsearchGauge; @@ -37,24 +39,24 @@ public class ServerMonitoringMetrics { private final Summary ceTasksRunningDuration; public ServerMonitoringMetrics() { - githubConfigOk = Gauge.build() - .name("github_config_ok") - .help("Tells whether SonarQube instance has configured GitHub integration and its status is green. 0 for green, 1 otherwise .") + githubHealthIntegrationStatus = Gauge.build() + .name("sonarqube_health_integration_github_status") + .help("Tells whether SonarQube instance has configured GitHub integration and its status is green. 1 for green, 0 otherwise .") .register(); - gitlabConfigOk = Gauge.build() - .name("gitlab_config_ok") - .help("Tells whether SonarQube instance has configured GitLab integration and its status is green. 0 for green, 1 otherwise .") + gitlabHealthIntegrationStatus = Gauge.build() + .name("sonarqube_health_integration_gitlab_status") + .help("Tells whether SonarQube instance has configured GitLab integration and its status is green. 1 for green, 0 otherwise .") .register(); - bitbucketConfigOk = Gauge.build() - .name("bitbucket_config_ok") - .help("Tells whether SonarQube instance has configured BitBucket integration and its status is green. 0 for green, 1 otherwise .") + bitbucketHealthIntegrationStatus = Gauge.build() + .name("sonarqube_health_integration_bitbucket_status") + .help("Tells whether SonarQube instance has configured BitBucket integration and its status is green. 1 for green, 0 otherwise .") .register(); - azureConfigOk = Gauge.build() - .name("azure_config_ok") - .help("Tells whether SonarQube instance has configured Azure integration and its status is green. 0 for green, 1 otherwise .") + azureHealthIntegrationStatus = Gauge.build() + .name("sonarqube_health_integration_azuredevops_status") + .help("Tells whether SonarQube instance has configured Azure integration and its status is green. 1 for green, 0 otherwise .") .register(); cePendingTasksTotal = Gauge.build() @@ -81,35 +83,35 @@ public class ServerMonitoringMetrics { } public void setGithubStatusToGreen() { - githubConfigOk.set(0); + githubHealthIntegrationStatus.set(UP_STATUS); } public void setGithubStatusToRed() { - githubConfigOk.set(1); + githubHealthIntegrationStatus.set(DOWN_STATUS); } public void setGitlabStatusToGreen() { - gitlabConfigOk.set(0); + gitlabHealthIntegrationStatus.set(UP_STATUS); } public void setGitlabStatusToRed() { - gitlabConfigOk.set(1); + gitlabHealthIntegrationStatus.set(DOWN_STATUS); } public void setAzureStatusToGreen() { - azureConfigOk.set(0); + azureHealthIntegrationStatus.set(UP_STATUS); } public void setAzureStatusToRed() { - azureConfigOk.set(1); + azureHealthIntegrationStatus.set(DOWN_STATUS); } public void setBitbucketStatusToGreen() { - bitbucketConfigOk.set(0); + bitbucketHealthIntegrationStatus.set(UP_STATUS); } public void setBitbucketStatusToRed() { - bitbucketConfigOk.set(1); + bitbucketHealthIntegrationStatus.set(DOWN_STATUS); } public void setNumberOfPendingTasks(int numberOfPendingTasks) { @@ -121,18 +123,18 @@ public class ServerMonitoringMetrics { } public void setComputeEngineStatusToGreen() { - computeEngineGauge.set(1); + computeEngineGauge.set(UP_STATUS); } public void setComputeEngineStatusToRed() { - computeEngineGauge.set(0); + computeEngineGauge.set(DOWN_STATUS); } public void setElasticSearchStatusToGreen() { - elasticsearchGauge.set(1); + elasticsearchGauge.set(UP_STATUS); } public void setElasticSearchStatusToRed() { - elasticsearchGauge.set(0); + elasticsearchGauge.set(DOWN_STATUS); } } diff --git a/server/sonar-webserver-monitoring/src/test/java/org/sonar/server/monitoring/ServerMonitoringMetricsTest.java b/server/sonar-webserver-monitoring/src/test/java/org/sonar/server/monitoring/ServerMonitoringMetricsTest.java index 7e67a817141..2f5bb6f050d 100644 --- a/server/sonar-webserver-monitoring/src/test/java/org/sonar/server/monitoring/ServerMonitoringMetricsTest.java +++ b/server/sonar-webserver-monitoring/src/test/java/org/sonar/server/monitoring/ServerMonitoringMetricsTest.java @@ -56,10 +56,10 @@ public class ServerMonitoringMetricsTest { metrics.setComputeEngineStatusToGreen(); metrics.setElasticSearchStatusToGreen(); - assertThat(CollectorRegistry.defaultRegistry.getSampleValue("github_config_ok")).isZero(); - 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_health_integration_github_status")).isPositive(); + assertThat(CollectorRegistry.defaultRegistry.getSampleValue("sonarqube_health_integration_gitlab_status")).isPositive(); + assertThat(CollectorRegistry.defaultRegistry.getSampleValue("sonarqube_health_integration_bitbucket_status")).isPositive(); + assertThat(CollectorRegistry.defaultRegistry.getSampleValue("sonarqube_health_integration_azuredevops_status")).isPositive(); assertThat(CollectorRegistry.defaultRegistry.getSampleValue("sonarqube_heath_compute_engine_status")).isPositive(); assertThat(CollectorRegistry.defaultRegistry.getSampleValue("sonarqube_heath_elasticsearch_status")).isPositive(); } @@ -75,10 +75,10 @@ public class ServerMonitoringMetricsTest { metrics.setComputeEngineStatusToRed(); metrics.setElasticSearchStatusToRed(); - assertThat(CollectorRegistry.defaultRegistry.getSampleValue("github_config_ok")).isEqualTo(1); - 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_health_integration_github_status")).isZero(); + assertThat(CollectorRegistry.defaultRegistry.getSampleValue("sonarqube_health_integration_gitlab_status")).isZero(); + assertThat(CollectorRegistry.defaultRegistry.getSampleValue("sonarqube_health_integration_bitbucket_status")).isZero(); + assertThat(CollectorRegistry.defaultRegistry.getSampleValue("sonarqube_health_integration_azuredevops_status")).isZero(); assertThat(CollectorRegistry.defaultRegistry.getSampleValue("sonarqube_heath_compute_engine_status")).isZero(); assertThat(CollectorRegistry.defaultRegistry.getSampleValue("sonarqube_heath_elasticsearch_status")).isZero(); } diff --git a/server/sonar-webserver-monitoring/src/test/java/org/sonar/server/monitoring/devops/AzureMetricsTaskTest.java b/server/sonar-webserver-monitoring/src/test/java/org/sonar/server/monitoring/devops/AzureMetricsTaskTest.java index 09081b3b8d9..88b168c54b4 100644 --- a/server/sonar-webserver-monitoring/src/test/java/org/sonar/server/monitoring/devops/AzureMetricsTaskTest.java +++ b/server/sonar-webserver-monitoring/src/test/java/org/sonar/server/monitoring/devops/AzureMetricsTaskTest.java @@ -19,10 +19,8 @@ */ package org.sonar.server.monitoring.devops; -import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.stream.IntStream; import org.junit.Before; import org.junit.Test; import org.sonar.alm.client.azure.AzureDevOpsValidator; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/monitoring/MetricsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/monitoring/MetricsAction.java index 4ce1289564e..5c7f30b7827 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/monitoring/MetricsAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/monitoring/MetricsAction.java @@ -44,7 +44,7 @@ public class MetricsAction extends SafeModeMonitoringMetricAction { .setResponseExample(getClass().getResource("monitoring-metrics.txt")) .setHandler(this); - isWebUpGauge.set(0D); + isWebUpGauge.set(1D); } @Override diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/monitoring/monitoring-metrics.txt b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/monitoring/monitoring-metrics.txt index 993d9a418c3..15cff35ab9b 100644 --- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/monitoring/monitoring-metrics.txt +++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/monitoring/monitoring-metrics.txt @@ -1,9 +1,26 @@ -# HELP sonarqube_heath_web_status Tells whether web service is up +# HELP sonarqube_compute_engine_tasks_running_duration_seconds Compute engine task running time in seconds +# TYPE sonarqube_compute_engine_tasks_running_duration_seconds summary +# HELP sonarqube_heath_elasticsearch_status Tells whether Elasticsearch is up or down. 1 for Up, 0 for down +# TYPE sonarqube_heath_elasticsearch_status gauge +sonarqube_heath_elasticsearch_status 1.0 +# HELP sonarqube_health_integration_github_status Tells whether SonarQube instance has configured GitHub integration and its status is green. 1 for green, 0 otherwise . +# TYPE sonarqube_health_integration_github_status gauge +sonarqube_health_integration_github_status 0.0 +# HELP sonarqube_health_integration_gitlab_status Tells whether SonarQube instance has configured GitLab integration and its status is green. 1 for green, 0 otherwise . +# TYPE sonarqube_health_integration_gitlab_status gauge +sonarqube_health_integration_gitlab_status 0.0 +# HELP sonarqube_health_integration_bitbucket_status Tells whether SonarQube instance has configured BitBucket integration and its status is green. 1 for green, 0 otherwise . +# TYPE sonarqube_health_integration_bitbucket_status gauge +sonarqube_health_integration_bitbucket_status 0.0 +# HELP sonarqube_health_integration_azuredevops_status Tells whether SonarQube instance has configured Azure integration and its status is green. 1 for green, 0 otherwise . +# TYPE sonarqube_health_integration_azuredevops_status gauge +sonarqube_health_integration_azuredevops_status 0.0 +# HELP sonarqube_heath_web_status Tells whether Web process is up or down. 1 for up, 0 for down # TYPE sonarqube_heath_web_status gauge -sonarqube_heath_web_status 0.0 -# HELP sonarqube_heath_compute_engine_status Tells whether Compute Engine is up (healthy, ready to take tasks) or down. 0 for up, 1 for down +sonarqube_heath_web_status 1.0 +# HELP sonarqube_compute_engine_pending_tasks_total Number of tasks at given point of time that were pending in the Compute Engine queue [SHARED, same value for every SonarQube instance] +# TYPE sonarqube_compute_engine_pending_tasks_total gauge +sonarqube_compute_engine_pending_tasks_total 0.0 +# HELP sonarqube_heath_compute_engine_status Tells whether Compute Engine is up (healthy, ready to take tasks) or down. 1 for up, 0 for down # TYPE sonarqube_heath_compute_engine_status gauge -sonarqube_heath_compute_engine_status 0.0 -# HELP sonarqube_heath_elasticsearch_status Tells whether Elasticsearch is up or down. 0 for Up, 1 for down -# TYPE sonarqube_heath_elasticsearch_status gauge -sonarqube_heath_elasticsearch_status 0.0 +sonarqube_heath_compute_engine_status 1.0
\ No newline at end of file diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/monitoring/MetricsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/monitoring/MetricsActionTest.java index a59df534343..82910285da0 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/monitoring/MetricsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/monitoring/MetricsActionTest.java @@ -86,9 +86,9 @@ public class MetricsActionTest { TestResponse response = ws.newRequest().execute(); String content = response.getInput(); assertThat(content) - .contains("# HELP sonarqube_heath_web_status Tells whether web service is up") + .contains("# HELP sonarqube_heath_web_status Tells whether Web process is up or down. 1 for up, 0 for down") .contains("# TYPE sonarqube_heath_web_status gauge") - .contains("sonarqube_heath_web_status 0.0"); + .contains("sonarqube_heath_web_status 1.0"); } @Test @@ -98,9 +98,9 @@ public class MetricsActionTest { TestResponse response = ws.newRequest().execute(); String content = response.getInput(); assertThat(content) - .contains("# HELP sonarqube_heath_web_status Tells whether web service is up") + .contains("# HELP sonarqube_heath_web_status Tells whether Web process is up or down. 1 for up, 0 for down") .contains("# TYPE sonarqube_heath_web_status gauge") - .contains("sonarqube_heath_web_status 0.0"); + .contains("sonarqube_heath_web_status 1.0"); } @Test @@ -110,9 +110,9 @@ public class MetricsActionTest { TestResponse response = ws.newRequest().execute(); String content = response.getInput(); assertThat(content) - .contains("# HELP sonarqube_heath_web_status Tells whether web service is up") + .contains("# HELP sonarqube_heath_web_status Tells whether Web process is up or down. 1 for up, 0 for down") .contains("# TYPE sonarqube_heath_web_status gauge") - .contains("sonarqube_heath_web_status 0.0"); + .contains("sonarqube_heath_web_status 1.0"); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeMonitoringMetricActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeMonitoringMetricActionTest.java index 97e91f2451d..e5c8cf44338 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeMonitoringMetricActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeMonitoringMetricActionTest.java @@ -76,9 +76,9 @@ public class SafeModeMonitoringMetricActionTest { TestResponse response = ws.newRequest().execute(); String content = response.getInput(); assertThat(content) - .contains("# HELP sonarqube_heath_web_status Tells whether web service is up") + .contains("# HELP sonarqube_heath_web_status Tells whether Web process is up or down. 1 for up, 0 for down") .contains("# TYPE sonarqube_heath_web_status gauge") - .contains("sonarqube_heath_web_status 0.0"); + .contains("sonarqube_heath_web_status 1.0"); } @Test @@ -88,9 +88,9 @@ public class SafeModeMonitoringMetricActionTest { TestResponse response = ws.newRequest().execute(); String content = response.getInput(); assertThat(content) - .contains("# HELP sonarqube_heath_web_status Tells whether web service is up") + .contains("# HELP sonarqube_heath_web_status Tells whether Web process is up or down. 1 for up, 0 for down") .contains("# TYPE sonarqube_heath_web_status gauge") - .contains("sonarqube_heath_web_status 0.0"); + .contains("sonarqube_heath_web_status 1.0"); } @Test |