aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-core/src
diff options
context:
space:
mode:
authorBenjamin Campomenosi <109955405+benjamin-campomenosi-sonarsource@users.noreply.github.com>2022-11-17 16:16:24 +0100
committersonartech <sonartech@sonarsource.com>2022-11-17 20:03:07 +0000
commita7a84e21235fd677162d11795df0ddc7a66af806 (patch)
tree56d66b84581bb1791dbfb8dcf5ecbc2e0ddb0582 /server/sonar-webserver-core/src
parent04d75741c1b20d0944d8907b4b2844cf7f19ca1b (diff)
downloadsonarqube-a7a84e21235fd677162d11795df0ddc7a66af806.tar.gz
sonarqube-a7a84e21235fd677162d11795df0ddc7a66af806.zip
SONAR-17578 Add LoC count in api/system/info
Diffstat (limited to 'server/sonar-webserver-core/src')
-rw-r--r--server/sonar-webserver-core/src/main/java/org/sonar/server/platform/AbstractSystemInfoWriter.java2
-rw-r--r--server/sonar-webserver-core/src/main/java/org/sonar/server/platform/SystemInfoWriterModule.java4
-rw-r--r--server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/StatisticsSystemSection.java57
-rw-r--r--server/sonar-webserver-core/src/test/java/org/sonar/server/platform/SystemInfoWriterModuleTest.java4
-rw-r--r--server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/StatisticsSystemSectionTest.java55
5 files changed, 118 insertions, 4 deletions
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/AbstractSystemInfoWriter.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/AbstractSystemInfoWriter.java
index 4bdc6e5a238..356368fbadb 100644
--- a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/AbstractSystemInfoWriter.java
+++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/AbstractSystemInfoWriter.java
@@ -28,7 +28,7 @@ import org.sonar.server.health.Health;
public abstract class AbstractSystemInfoWriter implements SystemInfoWriter {
private static final String[] ORDERED_SECTION_NAMES = {
// standalone
- "System", "Database", "Bundled", "Plugins",
+ "System", "Statistics", "Database", "Bundled", "Plugins",
// cluster
"Web JVM State", "Web Database Connection", "Web Logging", "Web JVM Properties",
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/SystemInfoWriterModule.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/SystemInfoWriterModule.java
index c0602d1315e..5ea367dadf5 100644
--- a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/SystemInfoWriterModule.java
+++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/SystemInfoWriterModule.java
@@ -32,6 +32,7 @@ import org.sonar.server.platform.monitoring.LoggingSection;
import org.sonar.server.platform.monitoring.PluginsSection;
import org.sonar.server.platform.monitoring.SettingsSection;
import org.sonar.server.platform.monitoring.StandaloneSystemSection;
+import org.sonar.server.platform.monitoring.StatisticsSystemSection;
import org.sonar.server.platform.monitoring.cluster.AppNodesInfoLoaderImpl;
import org.sonar.server.platform.monitoring.cluster.CeQueueGlobalSection;
import org.sonar.server.platform.monitoring.cluster.EsClusterStateSection;
@@ -64,7 +65,8 @@ public class SystemInfoWriterModule extends Module {
SettingsSection.class,
AlmConfigurationSection.class,
ServerPushSection.class,
- BundledSection.class
+ BundledSection.class,
+ StatisticsSystemSection.class
);
if (standalone) {
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/StatisticsSystemSection.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/StatisticsSystemSection.java
new file mode 100644
index 00000000000..006dbe62743
--- /dev/null
+++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/StatisticsSystemSection.java
@@ -0,0 +1,57 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.monitoring;
+
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.db.measure.SumNclocDbQuery;
+import org.sonar.process.systeminfo.SystemInfoSection;
+import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
+
+import static org.sonar.process.systeminfo.SystemInfoUtils.setAttribute;
+
+public class StatisticsSystemSection implements SystemInfoSection {
+
+ private final DbClient dbClient;
+
+ public StatisticsSystemSection(DbClient dbClient) {
+ this.dbClient = dbClient;
+ }
+
+ @Override
+ public ProtobufSystemInfo.Section toProtobuf() {
+ ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder();
+
+ protobuf.setName("Statistics");
+ setAttribute(protobuf, "loc", getLoc());
+
+ return protobuf.build();
+ }
+
+ private long getLoc(){
+ try (DbSession dbSession = dbClient.openSession(false)) {
+ SumNclocDbQuery query = SumNclocDbQuery.builder()
+ .setOnlyPrivateProjects(false)
+ .build();
+ return dbClient.liveMeasureDao().sumNclocOfBiggestBranch(dbSession, query);
+ }
+ }
+
+}
diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/SystemInfoWriterModuleTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/SystemInfoWriterModuleTest.java
index 21f300bd07b..d8b1f404e93 100644
--- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/SystemInfoWriterModuleTest.java
+++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/SystemInfoWriterModuleTest.java
@@ -35,7 +35,7 @@ public class SystemInfoWriterModuleTest {
when(webServer.isStandalone()).thenReturn(false);
ListContainer container = new ListContainer();
underTest.configure(container);
- assertThat(container.getAddedObjects()).hasSize(20);
+ assertThat(container.getAddedObjects()).hasSize(21);
}
@Test
@@ -44,6 +44,6 @@ public class SystemInfoWriterModuleTest {
ListContainer container = new ListContainer();
underTest.configure(container);
- assertThat(container.getAddedObjects()).hasSize(14);
+ assertThat(container.getAddedObjects()).hasSize(15);
}
}
diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/StatisticsSystemSectionTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/StatisticsSystemSectionTest.java
new file mode 100644
index 00000000000..5ece3b8e079
--- /dev/null
+++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/StatisticsSystemSectionTest.java
@@ -0,0 +1,55 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.monitoring;
+
+import org.junit.Test;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.db.measure.SumNclocDbQuery;
+import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.sonar.process.systeminfo.SystemInfoUtils.attribute;
+
+
+public class StatisticsSystemSectionTest {
+
+ private DbClient dbClient = mock(DbClient.class, RETURNS_DEEP_STUBS);
+
+ private final StatisticsSystemSection statisticsSystemSection = new StatisticsSystemSection(dbClient);
+
+ @Test
+ public void shouldWriteProtobuf() {
+
+ when(dbClient.liveMeasureDao().sumNclocOfBiggestBranch(any(DbSession.class), any(SumNclocDbQuery.class))).thenReturn(1800999L);
+
+ ProtobufSystemInfo.Section protobuf = statisticsSystemSection.toProtobuf();
+ long value = attribute(protobuf, "loc").getLongValue();
+
+ assertThat(value).isEqualTo(1800999L);
+
+ }
+
+
+} \ No newline at end of file