Skip to content

Commit

Permalink
SONAR-7372 Too many logs "Disable metric" at server startup
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Brandhof committed Mar 3, 2016
1 parent de9e634 commit c70f344
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
Expand Up @@ -102,9 +102,8 @@ private void save(DbSession session, Iterable<Metric> metrics) {
}

for (MetricDto nonUpdatedBase : basesByKey.values()) {
if (!nonUpdatedBase.isUserManaged()) {
if (!nonUpdatedBase.isUserManaged() && dbClient.metricDao().disableCustomByKey(session, nonUpdatedBase.getKey())) {
LOG.info("Disable metric {} [{}]", nonUpdatedBase.getShortName(), nonUpdatedBase.getKey());
dbClient.metricDao().disableCustomByKey(session, nonUpdatedBase.getKey());
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions sonar-db/src/main/java/org/sonar/db/metric/MetricDao.java
Expand Up @@ -141,8 +141,12 @@ public Void apply(@Nonnull List<Integer> input) {
});
}

public void disableCustomByKey(final DbSession session, String key) {
mapper(session).disableByKey(key);
/**
* Disable a metric and return {@code false} if the metric does not exist
* or is already disabled.
*/
public boolean disableCustomByKey(DbSession session, String key) {
return mapper(session).disableByKey(key) == 1;
}

public void update(DbSession session, MetricDto metric) {
Expand Down
Expand Up @@ -47,7 +47,7 @@ public interface MetricMapper {

void disableByIds(@Param("ids") List<Integer> ids);

void disableByKey(@Param("key") String key);
int disableByKey(@Param("key") String key);

int countEnabled(@Param("isCustom") @Nullable Boolean isCustom);

Expand Down
Expand Up @@ -136,6 +136,7 @@
update metrics
set enabled=${_false}
where name=#{key}
and enabled=${_true}
</update>

<select id="selectByKeys" resultType="org.sonar.db.metric.MetricDto">
Expand Down
Expand Up @@ -297,10 +297,15 @@ public void disableByIds() {
public void disableByKey() {
underTest.insert(session, newMetricDto().setKey("metric-key").setEnabled(true).setUserManaged(true));

underTest.disableCustomByKey(session, "metric-key");
boolean updated = underTest.disableCustomByKey(session, "metric-key");
assertThat(updated).isTrue();

MetricDto result = underTest.selectByKey(session, "metric-key");
assertThat(result.isEnabled()).isFalse();

// disable again -> zero rows are touched
updated = underTest.disableCustomByKey(session, "metric-key");
assertThat(updated).isFalse();
}

@Test
Expand Down

0 comments on commit c70f344

Please sign in to comment.