+++ /dev/null
-/*
- * 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.
- */
-@ParametersAreNonnullByDefault
-package org.sonar.server.telemetry;
-
-import javax.annotation.ParametersAreNonnullByDefault;
--- /dev/null
+/*
+ * 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.telemetry.legacy.user;
+
+import java.util.Map;
+import org.assertj.core.api.Assertions;
+import org.junit.Rule;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.sonar.api.impl.utils.AlwaysIncreasingSystem2;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbTester;
+import org.sonar.telemetry.user.TelemetryUserEnabledProvider;
+
+class TelemetryUserEnabledProviderIT {
+
+ private final System2 system2 = new AlwaysIncreasingSystem2();
+
+ @Rule
+ public final DbTester db = DbTester.create(system2);
+
+
+ private final TelemetryUserEnabledProvider underTest = new TelemetryUserEnabledProvider(db.getDbClient());
+
+ @BeforeEach
+ public void beforeEach() {
+ db.executeUpdateSql("delete from users");
+ }
+
+ @Test
+ void getUuidValues_whenNoUsersInDatabase_shouldReturnEmptyMap() {
+ Map<String, Boolean> uuidValues = underTest.getUuidValues();
+
+ Assertions.assertThat(uuidValues).isEmpty();
+ }
+
+ @Test
+ void getUuidValues_whenSomeUsersActive_shouldReturnBothBooleanValues() {
+ db.users().insertUser(user -> user.setUuid("uuid1").setActive(true));
+ db.users().insertUser(user -> user.setUuid("uuid1").setActive(false));
+ db.getSession().commit();
+
+ Map<String, Boolean> uuidValues = underTest.getUuidValues();
+
+ Assertions.assertThat(uuidValues).hasSize(2);
+ Assertions.assertThat(uuidValues.values().stream().filter(Boolean::booleanValue)).hasSize(1);
+ Assertions.assertThat(uuidValues.values().stream().filter(b -> !b)).hasSize(1);
+ }
+
+ @Test
+ void getUuidValues_when10ActiveUsers_shouldReturn10BooleanValues() {
+ for (int i = 0; i < 10; i++) {
+ db.users().insertUser(user -> user.setActive(true));
+ }
+ db.getSession().commit();
+
+ Map<String, Boolean> uuidValues = underTest.getUuidValues();
+
+ Assertions.assertThat(uuidValues).hasSize(10);
+ Assertions.assertThat(uuidValues.values().stream().filter(Boolean::booleanValue)).hasSize(10);
+ }
+}
--- /dev/null
+/*
+ * 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.telemetry.user;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.db.user.UserDto;
+import org.sonar.db.user.UserQuery;
+import org.sonar.telemetry.Dimension;
+import org.sonar.telemetry.Granularity;
+import org.sonar.telemetry.TelemetryDataProvider;
+import org.sonar.telemetry.TelemetryDataType;
+
+public class TelemetryUserEnabledProvider implements TelemetryDataProvider<Boolean> {
+
+ private final DbClient dbClient;
+
+ public TelemetryUserEnabledProvider(DbClient dbClient) {
+ this.dbClient = dbClient;
+ }
+
+ @Override
+ public String getMetricKey() {
+ return "user_enabled";
+ }
+
+ @Override
+ public Dimension getDimension() {
+ return Dimension.USER;
+ }
+
+ @Override
+ public Granularity getGranularity() {
+ return Granularity.DAILY;
+ }
+
+ @Override
+ public TelemetryDataType getType() {
+ return TelemetryDataType.BOOLEAN;
+ }
+
+ @Override
+ public Map<String, Boolean> getUuidValues() {
+ Map<String, Boolean> result = new HashMap<>();
+ int pageSize = 1000;
+ int page = 1;
+ try (DbSession dbSession = dbClient.openSession(false)) {
+ List<UserDto> userDtos = null;
+ do {
+ userDtos = dbClient.userDao().selectUsers(dbSession, UserQuery.builder().build(), page, pageSize);
+ for (UserDto userDto : userDtos) {
+ result.put(userDto.getUuid(), userDto.isActive());
+ }
+ page++;
+ } while (!userDtos.isEmpty());
+ }
+ return result;
+ }
+}
--- /dev/null
+/*
+ * 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.telemetry.user;
+
+import javax.annotation.ParametersAreNonnullByDefault;
--- /dev/null
+/*
+ * 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.telemetry.user;
+
+import org.junit.jupiter.api.Test;
+import org.sonar.db.DbClient;
+import org.sonar.telemetry.Dimension;
+import org.sonar.telemetry.Granularity;
+import org.sonar.telemetry.TelemetryDataType;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+class TelemetryUserEnabledProviderTest {
+
+ private final DbClient dbClient = mock(DbClient.class);
+
+ private final TelemetryUserEnabledProvider underTest = new TelemetryUserEnabledProvider(dbClient);
+
+ @Test
+ void testGetters() {
+ assertThat(underTest.getDimension()).isEqualTo(Dimension.USER);
+ assertThat(underTest.getGranularity()).isEqualTo(Granularity.DAILY);
+ assertThat(underTest.getMetricKey()).isEqualTo("user_enabled");
+ assertThat(underTest.getType()).isEqualTo(TelemetryDataType.BOOLEAN);
+ }
+}
+++ /dev/null
-/*
- * 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.telemetry;
-
-import java.util.Map;
-import org.junit.Rule;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.sonar.api.impl.utils.AlwaysIncreasingSystem2;
-import org.sonar.api.utils.System2;
-import org.sonar.db.DbTester;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-class TelemetryUserEnabledProviderIT {
-
- private final System2 system2 = new AlwaysIncreasingSystem2();
-
- @Rule
- public final DbTester db = DbTester.create(system2);
-
-
- private final TelemetryUserEnabledProvider underTest = new TelemetryUserEnabledProvider(db.getDbClient());
-
- @BeforeEach
- public void beforeEach() {
- db.executeUpdateSql("delete from users");
- }
-
- @Test
- void getUuidValues_whenNoUsersInDatabase_shouldReturnEmptyMap() {
- Map<String, Boolean> uuidValues = underTest.getUuidValues();
-
- assertThat(uuidValues).isEmpty();
- }
-
- @Test
- void getUuidValues_whenSomeUsersActive_shouldReturnBothBooleanValues() {
- db.users().insertUser(user -> user.setUuid("uuid1").setActive(true));
- db.users().insertUser(user -> user.setUuid("uuid1").setActive(false));
- db.getSession().commit();
-
- Map<String, Boolean> uuidValues = underTest.getUuidValues();
-
- assertThat(uuidValues).hasSize(2);
- assertThat(uuidValues.values().stream().filter(Boolean::booleanValue)).hasSize(1);
- assertThat(uuidValues.values().stream().filter(b -> !b)).hasSize(1);
- }
-
- @Test
- void getUuidValues_when10ActiveUsers_shouldReturn10BooleanValues() {
- for (int i = 0; i < 10; i++) {
- db.users().insertUser(user -> user.setActive(true));
- }
- db.getSession().commit();
-
- Map<String, Boolean> uuidValues = underTest.getUuidValues();
-
- assertThat(uuidValues).hasSize(10);
- assertThat(uuidValues.values().stream().filter(Boolean::booleanValue)).hasSize(10);
- }
-}
import org.sonar.server.authentication.event.AuthenticationEventImpl;
import org.sonar.server.authentication.purge.ExpiredSessionsCleaner;
import org.sonar.server.authentication.purge.ExpiredSessionsCleanerExecutorServiceImpl;
-import org.sonar.server.telemetry.TelemetryUserEnabledProvider;
public class AuthenticationModule extends Module {
@Override
ExpiredSessionsCleanerExecutorServiceImpl.class,
UserLastConnectionDatesUpdaterImpl.class,
UserRegistrarImpl.class,
- UserSessionInitializer.class,
- TelemetryUserEnabledProvider.class);
+ UserSessionInitializer.class);
}
}
+++ /dev/null
-/*
- * 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.telemetry;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
-import org.sonar.db.user.UserDto;
-import org.sonar.db.user.UserQuery;
-
-public class TelemetryUserEnabledProvider implements TelemetryDataProvider<Boolean> {
-
- private final DbClient dbClient;
-
- public TelemetryUserEnabledProvider(DbClient dbClient) {
- this.dbClient = dbClient;
- }
-
- @Override
- public String getMetricKey() {
- return "user_enabled";
- }
-
- @Override
- public Dimension getDimension() {
- return Dimension.USER;
- }
-
- @Override
- public Granularity getGranularity() {
- return Granularity.DAILY;
- }
-
- @Override
- public TelemetryDataType getType() {
- return TelemetryDataType.BOOLEAN;
- }
-
- @Override
- public Map<String, Boolean> getUuidValues() {
- Map<String, Boolean> result = new HashMap<>();
- int pageSize = 1000;
- int page = 1;
- try (DbSession dbSession = dbClient.openSession(false)) {
- List<UserDto> userDtos = null;
- do {
- userDtos = dbClient.userDao().selectUsers(dbSession, UserQuery.builder().build(), page, pageSize);
- for (UserDto userDto : userDtos) {
- result.put(userDto.getUuid(), userDto.isActive());
- }
- page++;
- } while (!userDtos.isEmpty());
- }
- return result;
- }
-}
+++ /dev/null
-/*
- * 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.
- */
-@ParametersAreNonnullByDefault
-package org.sonar.server.telemetry;
-
-import javax.annotation.ParametersAreNonnullByDefault;
+++ /dev/null
-/*
- * 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.telemetry;
-
-import org.junit.jupiter.api.Test;
-import org.sonar.db.DbClient;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-
-class TelemetryUserEnabledProviderTest {
-
- private final DbClient dbClient = mock(DbClient.class);
-
- private final TelemetryUserEnabledProvider underTest = new TelemetryUserEnabledProvider(dbClient);
-
- @Test
- void testGetters() {
- assertThat(underTest.getDimension()).isEqualTo(Dimension.USER);
- assertThat(underTest.getGranularity()).isEqualTo(Granularity.DAILY);
- assertThat(underTest.getMetricKey()).isEqualTo("user_enabled");
- assertThat(underTest.getType()).isEqualTo(TelemetryDataType.BOOLEAN);
- }
-}
api project(':sonar-markdown')
api project(':sonar-plugin-api-impl')
api project(':sonar-ws')
- api project(':server:sonar-telemetry')
implementation project(path: ':server:sonar-webserver-webapi')
compileOnlyApi 'com.github.spotbugs:spotbugs-annotations'
import org.sonar.server.plugins.ws.UninstallAction;
import org.sonar.server.plugins.ws.UpdatesAction;
import org.sonar.server.project.DefaultBranchNameResolver;
-import org.sonar.server.project.ProjectCppAutoconfigTelemetryProvider;
import org.sonar.server.project.ProjectQGChangeEventListener;
import org.sonar.server.project.VisibilityService;
import org.sonar.server.project.ws.ProjectsWsModule;
import org.sonar.telemetry.legacy.TelemetryDaemon;
import org.sonar.telemetry.legacy.TelemetryDataJsonWriter;
import org.sonar.telemetry.legacy.TelemetryDataLoaderImpl;
+import org.sonar.telemetry.project.ProjectCppAutoconfigTelemetryProvider;
+import org.sonar.telemetry.user.TelemetryUserEnabledProvider;
import static org.sonar.core.extension.CoreExtensionsInstaller.noAdditionalSideFilter;
import static org.sonar.core.extension.PlatformLevelPredicates.hasPlatformLevel4OrNone;
TelemetryVersionProvider.class,
TelemetryNclocProvider.class,
ProjectCppAutoconfigTelemetryProvider.class,
-
+ TelemetryUserEnabledProvider.class,
// monitoring
ServerMonitoringMetrics.class,