diff options
author | OrlovAlexander <alexander.orlov@sonarsource.com> | 2024-12-10 09:07:58 +0100 |
---|---|---|
committer | Steve Marion <steve.marion@sonarsource.com> | 2024-12-18 11:13:20 +0100 |
commit | b0a822491040b6f2f0b3ad4e778b72a1ed4c9c27 (patch) | |
tree | 1da4ef6929c66cc906bb2027135e4ecf4cb917f8 /server/sonar-webserver/src | |
parent | 378471f2ece7bec0809dea18c7c84d9b85e4be83 (diff) | |
download | sonarqube-b0a822491040b6f2f0b3ad4e778b72a1ed4c9c27.tar.gz sonarqube-b0a822491040b6f2f0b3ad4e778b72a1ed4c9c27.zip |
SONAR-23738 Portfolio and Subportfolio selection mode telemetry
Diffstat (limited to 'server/sonar-webserver/src')
5 files changed, 199 insertions, 0 deletions
diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java index 3a1587f66a5..21977575c71 100644 --- a/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java +++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java @@ -195,6 +195,8 @@ import org.sonar.server.platform.db.CheckAnyonePermissionsAtStartup; import org.sonar.server.platform.telemetry.TelemetryFipsEnabledProvider; import org.sonar.server.platform.telemetry.TelemetryMQRModePropertyProvider; import org.sonar.server.platform.telemetry.TelemetryNclocProvider; +import org.sonar.server.platform.telemetry.TelemetryPortfolioSelectionModeProvider; +import org.sonar.server.platform.telemetry.TelemetrySubportfolioSelectionModeProvider; import org.sonar.server.platform.telemetry.TelemetryUserEnabledProvider; import org.sonar.server.platform.telemetry.TelemetryVersionProvider; import org.sonar.server.platform.web.ActionDeprecationLoggerInterceptor; @@ -682,6 +684,8 @@ public class PlatformLevel4 extends PlatformLevel { TelemetryNclocProvider.class, TelemetryUserEnabledProvider.class, TelemetryFipsEnabledProvider.class, + TelemetrySubportfolioSelectionModeProvider.class, + TelemetryPortfolioSelectionModeProvider.class, // Reports telemetry TelemetryApplicationSubscriptionsProvider.class, diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryPortfolioSelectionModeProvider.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryPortfolioSelectionModeProvider.java new file mode 100644 index 00000000000..97545de54b6 --- /dev/null +++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryPortfolioSelectionModeProvider.java @@ -0,0 +1,45 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 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.telemetry; + +import java.util.Map; +import org.sonar.db.DbClient; +import org.sonar.db.DbSession; +import org.sonar.telemetry.core.AbstractTelemetryDataProvider; +import org.sonar.telemetry.core.Dimension; +import org.sonar.telemetry.core.Granularity; +import org.sonar.telemetry.core.TelemetryDataType; + +public class TelemetryPortfolioSelectionModeProvider extends AbstractTelemetryDataProvider<Integer> { + private static final String METRIC_KEY = "portfolio_using_selection_mode"; + private final DbClient dbClient; + + public TelemetryPortfolioSelectionModeProvider(DbClient dbClient) { + super(METRIC_KEY, Dimension.INSTALLATION, Granularity.ADHOC, TelemetryDataType.INTEGER); + this.dbClient = dbClient; + } + + @Override + public Map<String, Integer> getValues() { + try (DbSession dbSession = dbClient.openSession(false)) { + return dbClient.portfolioDao().countPortfoliosByMode(dbSession); + } + } +} diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetrySubportfolioSelectionModeProvider.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetrySubportfolioSelectionModeProvider.java new file mode 100644 index 00000000000..8fa49251275 --- /dev/null +++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetrySubportfolioSelectionModeProvider.java @@ -0,0 +1,45 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 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.telemetry; + +import java.util.Map; +import org.sonar.db.DbClient; +import org.sonar.db.DbSession; +import org.sonar.telemetry.core.AbstractTelemetryDataProvider; +import org.sonar.telemetry.core.Dimension; +import org.sonar.telemetry.core.Granularity; +import org.sonar.telemetry.core.TelemetryDataType; + +public class TelemetrySubportfolioSelectionModeProvider extends AbstractTelemetryDataProvider<Integer> { + private static final String METRIC_KEY = "subportfolio_using_selection_mode"; + private final DbClient dbClient; + + public TelemetrySubportfolioSelectionModeProvider(DbClient dbClient) { + super(METRIC_KEY, Dimension.INSTALLATION, Granularity.ADHOC, TelemetryDataType.INTEGER); + this.dbClient = dbClient; + } + + @Override + public Map<String, Integer> getValues() { + try (DbSession dbSession = dbClient.openSession(false)) { + return dbClient.portfolioDao().countSubportfoliosByMode(dbSession); + } + } +} diff --git a/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryPortfolioSelectionModeProviderTest.java b/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryPortfolioSelectionModeProviderTest.java new file mode 100644 index 00000000000..9dedd49a8c6 --- /dev/null +++ b/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryPortfolioSelectionModeProviderTest.java @@ -0,0 +1,52 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 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.telemetry; + +import java.util.Map; +import org.junit.jupiter.api.Test; +import org.sonar.db.DbClient; +import org.sonar.db.portfolio.PortfolioDao; +import org.sonar.telemetry.core.Dimension; +import org.sonar.telemetry.core.Granularity; +import org.sonar.telemetry.core.TelemetryDataType; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class TelemetryPortfolioSelectionModeProviderTest { + private final DbClient dbClient = mock(DbClient.class); + private final PortfolioDao portfolioDao = mock(PortfolioDao.class); + + @Test + void testGetters() { + when(dbClient.portfolioDao()).thenReturn(portfolioDao); + TelemetryPortfolioSelectionModeProvider underTest = new TelemetryPortfolioSelectionModeProvider(dbClient); + + assertThat(underTest.getMetricKey()).isEqualTo("portfolio_using_selection_mode"); + assertThat(underTest.getDimension()).isEqualTo(Dimension.INSTALLATION); + assertThat(underTest.getGranularity()).isEqualTo(Granularity.ADHOC); + assertThat(underTest.getType()).isEqualTo(TelemetryDataType.INTEGER); + Map<String, Integer> expected = Map.of("REGEXP", 42, "REST", 7); + when(portfolioDao.countPortfoliosByMode(any())).thenReturn(expected); + assertThat(underTest.getValues()).containsAllEntriesOf(expected); + } +} diff --git a/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetrySubportfolioSelectionModeProviderTest.java b/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetrySubportfolioSelectionModeProviderTest.java new file mode 100644 index 00000000000..50ddfd895a6 --- /dev/null +++ b/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetrySubportfolioSelectionModeProviderTest.java @@ -0,0 +1,53 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 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.telemetry; + +import java.util.Map; +import org.junit.jupiter.api.Test; +import org.sonar.db.DbClient; +import org.sonar.db.portfolio.PortfolioDao; +import org.sonar.telemetry.core.Dimension; +import org.sonar.telemetry.core.Granularity; +import org.sonar.telemetry.core.TelemetryDataType; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class TelemetrySubportfolioSelectionModeProviderTest { + private final DbClient dbClient = mock(DbClient.class); + private final PortfolioDao portfolioDao = mock(PortfolioDao.class); + + @Test + void testGetters() { + when(dbClient.portfolioDao()).thenReturn(portfolioDao); + TelemetrySubportfolioSelectionModeProvider underTest = new TelemetrySubportfolioSelectionModeProvider(dbClient); + + assertThat(underTest.getMetricKey()).isEqualTo("subportfolio_using_selection_mode"); + assertThat(underTest.getDimension()).isEqualTo(Dimension.INSTALLATION); + assertThat(underTest.getGranularity()).isEqualTo(Granularity.ADHOC); + assertThat(underTest.getType()).isEqualTo(TelemetryDataType.INTEGER); + Map<String, Integer> expected = Map.of("REGEXP", 42, "REST", 7); + when(portfolioDao.countSubportfoliosByMode(any())).thenReturn(expected); + assertThat(underTest.getValues()).containsAllEntriesOf(expected); + } + +} |