diff options
author | lukasz-jarocki-sonarsource <lukasz.jarocki@sonarsource.com> | 2024-09-06 08:47:33 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-09-06 20:02:37 +0000 |
commit | cd40a38f951a1355c086b99017401b93bd203558 (patch) | |
tree | b8c9fe11385b7951a637cf2a5ce6c4ab091f38bc /server/sonar-telemetry | |
parent | 0996c6186cfeb8e2c763d2f174b26ab276b232f7 (diff) | |
download | sonarqube-cd40a38f951a1355c086b99017401b93bd203558.tar.gz sonarqube-cd40a38f951a1355c086b99017401b93bd203558.zip |
SONAR-22891 added new telemetry metric
Diffstat (limited to 'server/sonar-telemetry')
4 files changed, 40 insertions, 7 deletions
diff --git a/server/sonar-telemetry/src/it/java/org/sonar/telemetry/metrics/TelemetryMetricsLoaderIT.java b/server/sonar-telemetry/src/it/java/org/sonar/telemetry/metrics/TelemetryMetricsLoaderIT.java index 6dc2f649365..67e2ea872e8 100644 --- a/server/sonar-telemetry/src/it/java/org/sonar/telemetry/metrics/TelemetryMetricsLoaderIT.java +++ b/server/sonar-telemetry/src/it/java/org/sonar/telemetry/metrics/TelemetryMetricsLoaderIT.java @@ -270,7 +270,7 @@ class TelemetryMetricsLoaderIT { } @Override - public Map<String, T> getUuidValues() { + public Map<String, T> getValues() { return Stream.of(keys) .collect(Collectors.toMap( key -> key, diff --git a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/TelemetryMetricsMapper.java b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/TelemetryMetricsMapper.java index e3379e4772f..d282608d9c2 100644 --- a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/TelemetryMetricsMapper.java +++ b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/TelemetryMetricsMapper.java @@ -52,7 +52,20 @@ public class TelemetryMetricsMapper { private static Set<Metric> mapInstallationMetric(TelemetryDataProvider<?> provider) { Optional<?> optionalValue = provider.getValue(); - if (provider.getGranularity() == Granularity.ADHOC && optionalValue.isEmpty()) { + + Granularity granularity = provider.getGranularity(); + + if (granularity == Granularity.ADHOC && !provider.getValues().isEmpty()) { + return provider.getValues().entrySet().stream() + .map(entry -> new InstallationMetric( + provider.getMetricKey() + "." + entry.getKey(), + entry.getValue(), + provider.getType(), + granularity + )).collect(Collectors.toSet()); + } + + if (granularity == Granularity.ADHOC && optionalValue.isEmpty()) { return Collections.emptySet(); } @@ -60,12 +73,12 @@ public class TelemetryMetricsMapper { provider.getMetricKey(), optionalValue.orElse(null), provider.getType(), - provider.getGranularity() + granularity )); } private static Set<Metric> mapUserMetric(TelemetryDataProvider<?> provider) { - return provider.getUuidValues().entrySet().stream() + return provider.getValues().entrySet().stream() .map(entry -> new UserMetric( provider.getMetricKey(), entry.getValue(), @@ -76,7 +89,7 @@ public class TelemetryMetricsMapper { } private static Set<Metric> mapProjectMetric(TelemetryDataProvider<?> provider) { - return provider.getUuidValues().entrySet().stream() + return provider.getValues().entrySet().stream() .map(entry -> new ProjectMetric( provider.getMetricKey(), entry.getValue(), @@ -87,7 +100,7 @@ public class TelemetryMetricsMapper { } private static Set<Metric> mapLanguageMetric(TelemetryDataProvider<?> provider) { - return provider.getUuidValues().entrySet().stream() + return provider.getValues().entrySet().stream() .map(entry -> new LanguageMetric( provider.getMetricKey(), entry.getValue(), diff --git a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/TelemetryMetricsMapperTest.java b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/TelemetryMetricsMapperTest.java index d2fa9f9533c..d822623d167 100644 --- a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/TelemetryMetricsMapperTest.java +++ b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/TelemetryMetricsMapperTest.java @@ -54,6 +54,26 @@ class TelemetryMetricsMapperTest { } @Test + void mapFromDataProvider_whenInstallationProviderWithMultiValue() { + TelemetryDataProvider<String> provider = new TestTelemetryBean(Dimension.INSTALLATION) { + @Override + public Granularity getGranularity() { + return Granularity.ADHOC; + } + }; + + Set<Metric> metrics = TelemetryMetricsMapper.mapFromDataProvider(provider); + List<InstallationMetric> userMetrics = retrieveList(metrics); + + assertThat(userMetrics) + .extracting(InstallationMetric::getKey, InstallationMetric::getType, InstallationMetric::getValue, InstallationMetric::getGranularity) + .containsExactlyInAnyOrder( + tuple("telemetry-bean-a.key-1", TelemetryDataType.STRING, "value-1", Granularity.ADHOC), + tuple("telemetry-bean-a.key-2", TelemetryDataType.STRING, "value-2", Granularity.ADHOC) + ); + } + + @Test void mapFromDataProvider_whenUserProvider() { TelemetryDataProvider<String> provider = new TestTelemetryBean(Dimension.USER); diff --git a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/TestTelemetryBean.java b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/TestTelemetryBean.java index 7aa64e464dc..f4c4c844d85 100644 --- a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/TestTelemetryBean.java +++ b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/TestTelemetryBean.java @@ -66,7 +66,7 @@ public class TestTelemetryBean implements TelemetryDataProvider<String> { } @Override - public Map<String, String> getUuidValues() { + public Map<String, String> getValues() { return METRIC_UUID_VALUES; } |