From 2eaf4da9b14cc5bfa73719b660c5db706672d182 Mon Sep 17 00:00:00 2001 From: Nolwenn Cadic <98824442+Nolwenn-cadic-sonarsource@users.noreply.github.com> Date: Thu, 26 Oct 2023 14:30:36 +0200 Subject: [PATCH] SONAR-20787 Add telemetry about quality gate conditions and sonar way (#9743) --- .../QualityGateConditionDaoIT.java | 15 +++ .../qualitygate/QualityGateConditionDao.java | 4 + .../QualityGateConditionMapper.java | 2 + .../QualityGateConditionMapper.xml | 7 ++ .../sonar/server/qualitygate/QualityGate.java | 2 + .../server/qualitygate/QualityGateFinder.java | 8 ++ .../sonar/server/telemetry/TelemetryData.java | 16 +++- .../telemetry/TelemetryDataJsonWriter.java | 11 +++ .../server/qualitygate/ConditionTest.java | 2 +- .../TelemetryDataJsonWriterTest.java | 92 +++++++++++++++---- .../telemetry/TelemetryDataLoaderImplIT.java | 22 ++++- .../telemetry/TelemetryDataLoaderImpl.java | 44 ++++++++- .../qualitygate/RegisterQualityGates.java | 2 +- 13 files changed, 200 insertions(+), 27 deletions(-) diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/QualityGateConditionDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/QualityGateConditionDaoIT.java index 6a46ce044d4..aa5e1c27a5e 100644 --- a/server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/QualityGateConditionDaoIT.java +++ b/server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/QualityGateConditionDaoIT.java @@ -33,6 +33,7 @@ import org.sonar.db.metric.MetricDto; import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.tuple; public class QualityGateConditionDaoIT { @@ -81,6 +82,20 @@ public class QualityGateConditionDaoIT { assertThat(underTest.selectForQualityGate(dbSession, "5")).isEmpty(); } + @Test + public void selectAll() { + MetricDto metric = dbTester.measures().insertMetric(t -> t.setEnabled(true)); + QualityGateConditionDto condition1 = insertQGCondition("uuid1", metric.getUuid()); + QualityGateConditionDto condition2 = insertQGCondition("uuid2", metric.getUuid()); + QualityGateConditionDto condition3 = insertQGCondition("uuid3", metric.getUuid()); + + assertThat(underTest.selectAll(dbSession)) + .extracting(QualityGateConditionDto::getUuid, QualityGateConditionDto::getMetricUuid) + .containsOnly(tuple(condition1.getUuid(), condition1.getMetricUuid()), + tuple(condition2.getUuid(), condition2.getMetricUuid()), + tuple(condition3.getUuid(), condition3.getMetricUuid())); + } + @Test public void testSelectByUuid() { QualityGateConditionDto condition = insertQGCondition("1", "2", "GT", "20"); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDao.java index 7187d444538..2c412ff9bb3 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDao.java @@ -34,6 +34,10 @@ public class QualityGateConditionDao implements Dao { return mapper(session).selectForQualityGate(qGateUuid); } + public Collection selectAll(DbSession session) { + return mapper(session).selectAll(); + } + public QualityGateConditionDto selectByUuid(String uuid, DbSession session) { return mapper(session).selectByUuid(uuid); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionMapper.java index 723bd22e96d..8b9efc7fc93 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionMapper.java @@ -27,6 +27,8 @@ public interface QualityGateConditionMapper { List selectForQualityGate(String qGateUuid); + List selectAll(); + void update(QualityGateConditionDto newCondition); QualityGateConditionDto selectByUuid(String uuid); diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateConditionMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateConditionMapper.xml index 2c57a73d936..0efc2c5d5b5 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateConditionMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateConditionMapper.xml @@ -20,6 +20,13 @@ order by created_at asc + +