Browse Source

SONAR-17195 Use "externalIdentityProvider" in users array in telemetry

- drop "externalAuthProviders" field
tags/9.7.0.61563
Jacek 1 year ago
parent
commit
601559308a

+ 13
- 3
server/sonar-db-dao/src/main/java/org/sonar/db/user/UserTelemetryDto.java View File

@@ -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;

+ 1
- 0
server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml View File

@@ -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

+ 0
- 13
server/sonar-server-common/src/main/java/org/sonar/server/telemetry/TelemetryData.java View File

@@ -36,7 +36,6 @@ public class TelemetryData {
private final String version;
private final Map<String, String> plugins;
private final Database database;
private final List<String> 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<String> getExternalAuthenticationProviders() {
return externalAuthenticationProviders;
}

public List<UserTelemetryDto> getUserTelemetries() {
return users;
}
@@ -149,7 +143,6 @@ public class TelemetryData {
private Boolean hasUnanalyzedC;
private Boolean hasUnanalyzedCpp;
private List<String> customSecurityConfigs;
private List<String> externalAuthenticationProviders;
private List<UserTelemetryDto> users;
private List<Project> projects;
private List<ProjectStatistics> projectStatistics;
@@ -158,11 +151,6 @@ public class TelemetryData {
// enforce static factory method
}

Builder setExternalAuthenticationProviders(List<String> 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);
}

+ 1
- 5
server/sonar-server-common/src/main/java/org/sonar/server/telemetry/TelemetryDataJsonWriter.java View File

@@ -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()));

+ 6
- 12
server/sonar-server-common/src/test/java/org/sonar/server/telemetry/TelemetryDataJsonWriterTest.java View File

@@ -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<UserTelemetryDto> 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());
}


+ 0
- 2
server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java View File

@@ -121,8 +121,6 @@ public class TelemetryDataLoaderImpl implements TelemetryDataLoader {
data.setHasUnanalyzedCpp(numberOfUnanalyzedCppMeasures > 0);
});

data.setExternalAuthenticationProviders(dbClient.userDao().selectExternalIdentityProviders(dbSession));

Map<String, String> scmByProject = getAnalysisPropertyByProject(dbSession, SONAR_ANALYSIS_DETECTEDSCM);
Map<String, String> ciByProject = getAnalysisPropertyByProject(dbSession, SONAR_ANALYSIS_DETECTEDCI);
Map<String, ProjectAlmKeyAndProject> almAndUrlByProject = getAlmAndUrlByProject(dbSession);

+ 0
- 3
server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDaemonTest.java View File

@@ -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();


+ 0
- 1
server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDataLoaderImplTest.java View File

@@ -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)

Loading…
Cancel
Save