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",
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;
SettingsSection.class,
AlmConfigurationSection.class,
ServerPushSection.class,
- BundledSection.class
+ BundledSection.class,
+ StatisticsSystemSection.class
);
if (standalone) {
--- /dev/null
+/*
+ * 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);
+ }
+ }
+
+}
when(webServer.isStandalone()).thenReturn(false);
ListContainer container = new ListContainer();
underTest.configure(container);
- assertThat(container.getAddedObjects()).hasSize(20);
+ assertThat(container.getAddedObjects()).hasSize(21);
}
@Test
ListContainer container = new ListContainer();
underTest.configure(container);
- assertThat(container.getAddedObjects()).hasSize(14);
+ assertThat(container.getAddedObjects()).hasSize(15);
}
}
--- /dev/null
+/*
+ * 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
@Override
public void handle(Request request, Response response) {
+ int a = 100;
try (DbSession session = dbClient.openSession(false)) {
ComponentDto component = loadComponent(session, request);
userSession.checkComponentPermission(UserRole.USER, component);
String branch = request.param(PARAM_BRANCH);
String pullRequest = request.param(PARAM_PULL_REQUEST);
String componentKey = request.mandatoryParam(PARAM_COMPONENT);
-
+int a = 9;
return componentFinder.getByKeyAndOptionalBranchOrPullRequest(dbSession, componentKey, branch, pullRequest);
}