aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server-common
diff options
context:
space:
mode:
authorOrlovAlexander <alexander.orlov@sonarsource.com>2024-12-04 15:44:45 +0100
committersonartech <sonartech@sonarsource.com>2024-12-04 20:03:23 +0000
commit14937df5136fce44296521061f11c571919fc854 (patch)
tree30aec037add8ca750f28dfd1d5005744d60c2c47 /server/sonar-server-common
parent33ab48ae6fc78cd3e67029d402dc1861ea787251 (diff)
downloadsonarqube-14937df5136fce44296521061f11c571919fc854.tar.gz
sonarqube-14937df5136fce44296521061f11c571919fc854.zip
SONAR-23736 Add application report Telemetry
Diffstat (limited to 'server/sonar-server-common')
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/notification/email/telemetry/TelemetryApplicationSubscriptionsProvider.java46
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/notification/email/telemetry/TelemetryApplicationSubscriptionsProviderTest.java51
2 files changed, 97 insertions, 0 deletions
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/telemetry/TelemetryApplicationSubscriptionsProvider.java b/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/telemetry/TelemetryApplicationSubscriptionsProvider.java
new file mode 100644
index 00000000000..87be470e976
--- /dev/null
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/telemetry/TelemetryApplicationSubscriptionsProvider.java
@@ -0,0 +1,46 @@
+/*
+ * 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.notification.email.telemetry;
+
+import java.util.Optional;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.db.component.ComponentQualifiers;
+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 TelemetryApplicationSubscriptionsProvider extends AbstractTelemetryDataProvider<Integer> {
+ private static final String METRIC_KEY = "application_report_pdf_subscriptions";
+ private final DbClient dbClient;
+
+ public TelemetryApplicationSubscriptionsProvider(DbClient dbClient) {
+ super(METRIC_KEY, Dimension.INSTALLATION, Granularity.DAILY, TelemetryDataType.INTEGER);
+ this.dbClient = dbClient;
+ }
+
+ @Override
+ public Optional<Integer> getValue() {
+ try (DbSession dbSession = dbClient.openSession(false)) {
+ return Optional.of(dbClient.reportSubscriptionDao().countByQualifier(dbSession, ComponentQualifiers.APP));
+ }
+ }
+}
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/notification/email/telemetry/TelemetryApplicationSubscriptionsProviderTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/notification/email/telemetry/TelemetryApplicationSubscriptionsProviderTest.java
new file mode 100644
index 00000000000..2e3dc01bb5b
--- /dev/null
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/notification/email/telemetry/TelemetryApplicationSubscriptionsProviderTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.notification.email.telemetry;
+
+import org.junit.jupiter.api.Test;
+import org.sonar.db.DbClient;
+import org.sonar.db.report.ReportSubscriptionDao;
+import org.sonar.telemetry.core.Dimension;
+import org.sonar.telemetry.core.Granularity;
+
+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 TelemetryApplicationSubscriptionsProviderTest {
+
+ private final DbClient dbClient = mock(DbClient.class);
+ private final ReportSubscriptionDao reportSubscriptionDao = mock(ReportSubscriptionDao.class);
+
+ @Test
+ void testGetters() {
+ when(dbClient.reportSubscriptionDao()).thenReturn(reportSubscriptionDao);
+ TelemetryApplicationSubscriptionsProvider underTest = new TelemetryApplicationSubscriptionsProvider(dbClient);
+
+ assertThat(underTest.getMetricKey()).isEqualTo("application_report_pdf_subscriptions");
+ assertThat(underTest.getDimension()).isEqualTo(Dimension.INSTALLATION);
+ assertThat(underTest.getGranularity()).isEqualTo(Granularity.DAILY);
+ when(reportSubscriptionDao.countByQualifier(any(), any())).thenReturn(42);
+ assertThat(underTest.getValue()).contains(42);
+ when(reportSubscriptionDao.countByQualifier(any(), any())).thenReturn(0);
+ assertThat(underTest.getValue()).contains(0);
+ }
+}