From 601559308afd3eb6f98853365785ead41c25ebff Mon Sep 17 00:00:00 2001 From: Jacek Date: Tue, 27 Sep 2022 14:40:19 +0200 Subject: [PATCH] SONAR-17195 Use "externalIdentityProvider" in users array in telemetry - drop "externalAuthProviders" field --- .../org/sonar/db/user/UserTelemetryDto.java | 16 +++++++++++++--- .../resources/org/sonar/db/user/UserMapper.xml | 1 + .../sonar/server/telemetry/TelemetryData.java | 13 ------------- .../telemetry/TelemetryDataJsonWriter.java | 6 +----- .../telemetry/TelemetryDataJsonWriterTest.java | 18 ++++++------------ .../telemetry/TelemetryDataLoaderImpl.java | 2 -- .../server/telemetry/TelemetryDaemonTest.java | 3 --- .../telemetry/TelemetryDataLoaderImplTest.java | 1 - 8 files changed, 21 insertions(+), 39 deletions(-) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserTelemetryDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserTelemetryDto.java index 0c0a0c35539..cbee0dc4f60 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserTelemetryDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserTelemetryDto.java @@ -23,12 +23,13 @@ import javax.annotation.Nullable; public class UserTelemetryDto { - private String uuid; + private String uuid = null; private boolean active = true; + private String externalIdentityProvider = null; @Nullable - private Long lastConnectionDate; + private Long lastConnectionDate = null; @Nullable - private Long lastSonarlintConnectionDate; + private Long lastSonarlintConnectionDate = null; public String getUuid() { return uuid; @@ -48,6 +49,15 @@ public class UserTelemetryDto { return this; } + public String getExternalIdentityProvider() { + return externalIdentityProvider; + } + + public UserTelemetryDto setExternalIdentityProvider(String externalIdentityProvider) { + this.externalIdentityProvider = externalIdentityProvider; + return this; + } + @Nullable public Long getLastConnectionDate() { return lastConnectionDate; diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml index 7265b8dde2e..abab22c8757 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml @@ -108,6 +108,7 @@ SELECT u.uuid as uuid, u.active as "active", + u.external_identity_provider as "externalIdentityProvider", u.last_connection_date as "lastConnectionDate", u.last_sonarlint_connection as "lastSonarlintConnectionDate" FROM users u diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/telemetry/TelemetryData.java b/server/sonar-server-common/src/main/java/org/sonar/server/telemetry/TelemetryData.java index 1f4cd508c6d..09b2c1ee5a1 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/telemetry/TelemetryData.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/telemetry/TelemetryData.java @@ -36,7 +36,6 @@ public class TelemetryData { private final String version; private final Map plugins; private final Database database; - private final List externalAuthenticationProviders; private final EditionProvider.Edition edition; private final String licenseType; private final Long installationDate; @@ -62,7 +61,6 @@ public class TelemetryData { hasUnanalyzedC = builder.hasUnanalyzedC; hasUnanalyzedCpp = builder.hasUnanalyzedCpp; customSecurityConfigs = builder.customSecurityConfigs == null ? emptyList() : builder.customSecurityConfigs; - externalAuthenticationProviders = builder.externalAuthenticationProviders; users = builder.users; projects = builder.projects; projectStatistics = builder.projectStatistics; @@ -116,10 +114,6 @@ public class TelemetryData { return customSecurityConfigs; } - public List getExternalAuthenticationProviders() { - return externalAuthenticationProviders; - } - public List getUserTelemetries() { return users; } @@ -149,7 +143,6 @@ public class TelemetryData { private Boolean hasUnanalyzedC; private Boolean hasUnanalyzedCpp; private List customSecurityConfigs; - private List externalAuthenticationProviders; private List users; private List projects; private List projectStatistics; @@ -158,11 +151,6 @@ public class TelemetryData { // enforce static factory method } - Builder setExternalAuthenticationProviders(List providers) { - this.externalAuthenticationProviders = providers; - return this; - } - Builder setServerId(String serverId) { this.serverId = serverId; return this; @@ -238,7 +226,6 @@ public class TelemetryData { requireNonNull(version); requireNonNull(plugins); requireNonNull(database); - requireNonNull(externalAuthenticationProviders); return new TelemetryData(this); } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/telemetry/TelemetryDataJsonWriter.java b/server/sonar-server-common/src/main/java/org/sonar/server/telemetry/TelemetryDataJsonWriter.java index 3bd3dda66e4..c6ab6177ff8 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/telemetry/TelemetryDataJsonWriter.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/telemetry/TelemetryDataJsonWriter.java @@ -64,11 +64,6 @@ public class TelemetryDataJsonWriter { statistics.hasUnanalyzedC().ifPresent(hasUnanalyzedC -> json.prop("hasUnanalyzedC", hasUnanalyzedC)); statistics.hasUnanalyzedCpp().ifPresent(hasUnanalyzedCpp -> json.prop("hasUnanalyzedCpp", hasUnanalyzedCpp)); - json.name("externalAuthProviders"); - json.beginArray(); - statistics.getExternalAuthenticationProviders().forEach(json::value); - json.endArray(); - if (statistics.getInstallationDate() != null) { json.prop("installationDate", toUtc(statistics.getInstallationDate())); } @@ -92,6 +87,7 @@ public class TelemetryDataJsonWriter { json.beginObject(); json.prop("userUuid", DigestUtils.sha3_224Hex(user.getUuid())); json.prop("status", user.isActive() ? "active" : "inactive"); + json.prop("identityProvider", user.getExternalIdentityProvider()); if (user.getLastConnectionDate() != null) { json.prop("lastActivity", toUtc(user.getLastConnectionDate())); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/telemetry/TelemetryDataJsonWriterTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/telemetry/TelemetryDataJsonWriterTest.java index 8782cd1863b..4d6d482f62d 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/telemetry/TelemetryDataJsonWriterTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/telemetry/TelemetryDataJsonWriterTest.java @@ -40,7 +40,6 @@ import org.sonar.core.platform.EditionProvider; import org.sonar.core.util.stream.MoreCollectors; import org.sonar.db.user.UserTelemetryDto; -import static java.util.Arrays.asList; import static java.util.stream.Collectors.joining; import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; import static org.assertj.core.api.Assertions.assertThat; @@ -53,7 +52,6 @@ public class TelemetryDataJsonWriterTest { .setServerId("foo") .setVersion("bar") .setPlugins(Collections.emptyMap()) - .setExternalAuthenticationProviders(asList("github", "gitlab")) .setDatabase(new TelemetryData.Database("H2", "11")); private final Random random = new Random(); @@ -81,15 +79,6 @@ public class TelemetryDataJsonWriterTest { assertThat(json).doesNotContain("edition"); } - @Test - public void write_external_auth_providers() { - TelemetryData data = SOME_TELEMETRY_DATA.build(); - - String json = writeTelemetryData(data); - - assertJson(json).isSimilarTo("{ \"externalAuthProviders\": [ \"github\", \"gitlab\" ] }"); - } - @Test @UseDataProvider("allEditions") public void writes_edition_if_non_null(EditionProvider.Edition edition) { @@ -281,18 +270,21 @@ public class TelemetryDataJsonWriterTest { " {" + " \"userUuid\":\"" + DigestUtils.sha3_224Hex("uuid-0") + "\"," + " \"lastActivity\":\"1970-01-01T00:00:00+0000\"," + + " \"identityProvider\":\"gitlab\"," + " \"lastSonarlintActivity\":\"1970-01-01T00:00:00+0000\"," + " \"status\":\"active\"" + " }," + " {" + " \"userUuid\":\"" + DigestUtils.sha3_224Hex("uuid-1") + "\"," + " \"lastActivity\":\"1970-01-01T00:00:00+0000\"," + + " \"identityProvider\":\"gitlab\"," + " \"lastSonarlintActivity\":\"1970-01-01T00:00:00+0000\"," + " \"status\":\"inactive\"" + " }," + " {" + " \"userUuid\":\"" + DigestUtils.sha3_224Hex("uuid-2") + "\"," + " \"lastActivity\":\"1970-01-01T00:00:00+0000\"," + + " \"identityProvider\":\"gitlab\"," + " \"lastSonarlintActivity\":\"1970-01-01T00:00:00+0000\"," + " \"status\":\"active\"" + " }" + @@ -372,7 +364,9 @@ public class TelemetryDataJsonWriterTest { @NotNull private static List getUsers() { - return IntStream.range(0, 3).mapToObj(i -> new UserTelemetryDto().setUuid("uuid-" + i).setActive(i % 2 == 0).setLastConnectionDate(1L).setLastSonarlintConnectionDate(2L)) + return IntStream.range(0, 3) + .mapToObj( + i -> new UserTelemetryDto().setUuid("uuid-" + i).setActive(i % 2 == 0).setLastConnectionDate(1L).setLastSonarlintConnectionDate(2L).setExternalIdentityProvider("gitlab")) .collect(Collectors.toList()); } diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java index 8a91caa4505..4c643684752 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java @@ -121,8 +121,6 @@ public class TelemetryDataLoaderImpl implements TelemetryDataLoader { data.setHasUnanalyzedCpp(numberOfUnanalyzedCppMeasures > 0); }); - data.setExternalAuthenticationProviders(dbClient.userDao().selectExternalIdentityProviders(dbSession)); - Map scmByProject = getAnalysisPropertyByProject(dbSession, SONAR_ANALYSIS_DETECTEDSCM); Map ciByProject = getAnalysisPropertyByProject(dbSession, SONAR_ANALYSIS_DETECTEDCI); Map almAndUrlByProject = getAlmAndUrlByProject(dbSession); diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDaemonTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDaemonTest.java index bed2ed3e7a0..ba4186af014 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDaemonTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDaemonTest.java @@ -34,7 +34,6 @@ import org.sonar.server.property.MapInternalProperties; import org.sonar.server.util.GlobalLockManager; import org.sonar.server.util.GlobalLockManagerImpl; -import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; @@ -64,8 +63,6 @@ public class TelemetryDaemonTest { .setServerId("foo") .setVersion("bar") .setPlugins(Collections.emptyMap()) - .setExternalAuthenticationProviders(singletonList("github")) - .setExternalAuthenticationProviders(Collections.emptyList()) .setDatabase(new TelemetryData.Database("H2", "11")) .build(); diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDataLoaderImplTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDataLoaderImplTest.java index b4fa868a8df..1ef601422d5 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDataLoaderImplTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDataLoaderImplTest.java @@ -154,7 +154,6 @@ public class TelemetryDataLoaderImplTest { assertThat(data.getPlugins()).containsOnly( entry("java", "4.12.0.11033"), entry("scmgit", "1.2"), entry("other", "undefined")); assertThat(data.isInDocker()).isFalse(); - assertThat(data.getExternalAuthenticationProviders()).containsExactlyInAnyOrder("provider0", "provider1", "provider2"); assertThat(data.getUserTelemetries()) .extracting(UserTelemetryDto::getUuid, UserTelemetryDto::getLastConnectionDate, UserTelemetryDto::getLastSonarlintConnectionDate, UserTelemetryDto::isActive) -- 2.39.5