aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-core
diff options
context:
space:
mode:
authorlukasz-jarocki-sonarsource <lukasz.jarocki@sonarsource.com>2024-09-23 09:11:01 +0200
committersonartech <sonartech@sonarsource.com>2024-09-23 20:02:40 +0000
commit96492f2bf93e4ed65ebc5dff19fb973af94289b3 (patch)
tree95cb8d8405eaae3ba60a9273cfa53d074839163a /server/sonar-webserver-core
parentd5450363bddc9a66114cb8675484f38032a2fc4a (diff)
downloadsonarqube-96492f2bf93e4ed65ebc5dff19fb973af94289b3.tar.gz
sonarqube-96492f2bf93e4ed65ebc5dff19fb973af94289b3.zip
SONAR-22997 added telemetry for openshift
Diffstat (limited to 'server/sonar-webserver-core')
-rw-r--r--server/sonar-webserver-core/src/main/java/org/sonar/server/platform/ContainerSupport.java2
-rw-r--r--server/sonar-webserver-core/src/main/java/org/sonar/server/platform/ContainerSupportImpl.java6
-rw-r--r--server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/cluster/GlobalSystemSection.java1
-rw-r--r--server/sonar-webserver-core/src/test/java/org/sonar/server/platform/ContainerSupportImplTest.java27
-rw-r--r--server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/GlobalSystemSectionTest.java7
5 files changed, 36 insertions, 7 deletions
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/ContainerSupport.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/ContainerSupport.java
index 1611540402e..8968cd60b47 100644
--- a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/ContainerSupport.java
+++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/ContainerSupport.java
@@ -30,4 +30,6 @@ public interface ContainerSupport {
@CheckForNull
String getContainerContext();
+ boolean isRunningOnHelmOpenshift();
+
}
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/ContainerSupportImpl.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/ContainerSupportImpl.java
index dfdd466004a..a836029918c 100644
--- a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/ContainerSupportImpl.java
+++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/ContainerSupportImpl.java
@@ -38,6 +38,7 @@ public class ContainerSupportImpl implements ContainerSupport {
private static final String BUILDAH = "buildah";
private static final String CONTAINER_D = "containerd";
private static final String GENERAL_CONTAINER = "general_container";
+ private static final String IS_HELM_OPENSHIFT_ENABLED = "IS_HELM_OPENSHIFT_ENABLED";
private static final String[] MOUNT_GREP_COMMAND = {"bash", "-c", "mount | grep 'overlay on /'"};
private static final String[] CAT_COMMAND = {"bash", "-c", "cat /run/.containerenv"};
@@ -80,6 +81,11 @@ public class ContainerSupportImpl implements ContainerSupport {
return containerContextCache;
}
+ @Override
+ public boolean isRunningOnHelmOpenshift() {
+ return "true".equals(system2.envVariable(IS_HELM_OPENSHIFT_ENABLED));
+ }
+
private boolean isDocker() {
return getMountOverlays().contains("/docker") && paths2.exists("/.dockerenv");
}
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/cluster/GlobalSystemSection.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/cluster/GlobalSystemSection.java
index c2883156868..cdd591ee3db 100644
--- a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/cluster/GlobalSystemSection.java
+++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/cluster/GlobalSystemSection.java
@@ -60,6 +60,7 @@ public class GlobalSystemSection implements SystemInfoSection, Global {
setAttribute(protobuf, "Edition", sonarRuntime.getEdition().getLabel());
setAttribute(protobuf, NCLOC.getName() ,statisticsSupport.getLinesOfCode());
setAttribute(protobuf, "Container", containerSupport.isRunningInContainer());
+ setAttribute(protobuf, "Running on OpenShift", containerSupport.isRunningOnHelmOpenshift());
setAttribute(protobuf, "High Availability", true);
setAttribute(protobuf, "External Users and Groups Provisioning",
commonSystemInformation.getManagedInstanceProviderName());
diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/ContainerSupportImplTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/ContainerSupportImplTest.java
index 053111efdab..6ec91832ed7 100644
--- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/ContainerSupportImplTest.java
+++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/ContainerSupportImplTest.java
@@ -58,6 +58,7 @@ public class ContainerSupportImplTest {
containerContext.hasPodmanEnvVariable ?
"podman" : "");
when(underTest.getMountOverlays()).thenReturn(containerContext.mountOverlays);
+ when(system2.envVariable("IS_HELM_OPENSHIFT_ENABLED")).thenReturn(containerContext.isRunningOnOpenShiftEnvVariable);
underTest.populateCache();
}
@@ -78,29 +79,41 @@ public class ContainerSupportImplTest {
.isEqualTo(containerContext.expectedContainerContext != null);
}
+ @Test
+ public void testIsRunningOnHelmOpenshift() {
+ assertThat(underTest.isRunningOnHelmOpenshift())
+ .isEqualTo(containerContext.expectedRunningOnOpenShift);
+ }
+
public enum ContainerEnvConfig {
- DOCKER("docker", false, true, false, false, "/docker"),
- PODMAN("podman", true, false, true, false, ""),
- BUILDAH("buildah", true, false, false, true, ""),
- CONTAINER_D("containerd", false, false, false, false, "/containerd"),
- GENERAL_CONTAINER("general_container", true, false, false, false, ""),
- NONE(null, false, false, false, false, "");
+ DOCKER("docker", false, true, false, false, "/docker", "false", false),
+ PODMAN("podman", true, false, true, false, "", "false", false),
+ BUILDAH("buildah", true, false, false, true, "", "false", false),
+ CONTAINER_D("containerd", false, false, false, false, "/containerd", "false", false),
+ GENERAL_CONTAINER("general_container", true, false, false, false, "", "false", false),
+ NONE(null, false, false, false, false, "", null, false),
+ OPENSHIFT(null, false, false, false, false, "", "true", true),
+ OPENSHIFT_SET_TO_FALSE(null, false, false, false, false, "", "false", false);
final String expectedContainerContext;
final boolean hasContainerenvFile;
final boolean hasDockerEnvFile;
final boolean hasPodmanEnvVariable;
final boolean hasBuildahContainerenv;
final String mountOverlays;
+ final String isRunningOnOpenShiftEnvVariable;
+ final boolean expectedRunningOnOpenShift;
ContainerEnvConfig(@Nullable String expectedContainerContext, boolean hasContainerenvFile, boolean hasDockerEnvFile, boolean hasPodmanEnvVariable,
- boolean hasBuildahContainerenv, String mountOverlays) {
+ boolean hasBuildahContainerenv, String mountOverlays, @Nullable String isRunningOnOpenShiftEnvVariable, boolean expectedRunningOnOpenShift) {
this.expectedContainerContext = expectedContainerContext;
this.hasContainerenvFile = hasContainerenvFile;
this.hasDockerEnvFile = hasDockerEnvFile;
this.hasPodmanEnvVariable = hasPodmanEnvVariable;
this.hasBuildahContainerenv = hasBuildahContainerenv;
this.mountOverlays = mountOverlays;
+ this.isRunningOnOpenShiftEnvVariable = isRunningOnOpenShiftEnvVariable;
+ this.expectedRunningOnOpenShift = expectedRunningOnOpenShift;
}
}
diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/GlobalSystemSectionTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/GlobalSystemSectionTest.java
index 7896e24e818..a72a0d76511 100644
--- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/GlobalSystemSectionTest.java
+++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/GlobalSystemSectionTest.java
@@ -133,6 +133,13 @@ public class GlobalSystemSectionTest {
}
@Test
+ public void toProtobuf_whenOnOpenShift_returnIt() {
+ when(containerSupport.isRunningOnHelmOpenshift()).thenReturn(true);
+ ProtobufSystemInfo.Section protobuf = underTest.toProtobuf();
+ assertThatAttributeIs(protobuf, "Running on OpenShift", true);
+ }
+
+ @Test
public void return_Lines_of_Codes_from_StatisticsSupport(){
when(statisticsSupport.getLinesOfCode()).thenReturn(17752L);
ProtobufSystemInfo.Section protobuf = underTest.toProtobuf();