Skip to content

Commit 0be32bb

Browse files
authored
Merge pull request #1641 from ivangalkin/fix_1640
{Aggregate|Density}MeasureComputer: reduce and soften the logging
2 parents c7af36e + ea32b39 commit 0be32bb

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

cxx-squid/src/main/java/org/sonar/cxx/AggregateMeasureComputer.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,24 @@ public AggregateMeasureComputer(String languageKey, String languagePropsKey) {
7878
private static void compute(MeasureComputerContext context, String metricKey) {
7979
final Component component = context.getComponent();
8080
if (component.getType() == Component.Type.FILE) {
81-
LOG.debug("Component {}: FILE doesn't required an aggregation", component.getKey());
81+
// FILE doesn't required any aggregation. Relevant metrics should be provided by the sensor.
8282
return;
8383
}
8484
final Measure existingMeasure = context.getMeasure(metricKey);
8585
if (existingMeasure != null) {
86+
// For all other component types (e.g. PROJECT, MODULE, DIRECTORY) the
87+
// measurement <metricKey> should not be calculated manually (e.g. in the sensors).
88+
// Otherwise there is a chance, that your custom calculation won't work properly for
89+
// multi-module projects.
8690
LOG.debug("Component {}: measure {} already calculated, value = {}", component.getKey(), metricKey,
8791
existingMeasure.getIntValue());
8892
return;
8993
}
9094
Iterable<Measure> childrenMeasures = context.getChildrenMeasures(metricKey);
9195
if (childrenMeasures == null || !childrenMeasures.iterator().hasNext()) {
92-
LOG.debug("Component {}: measure {} is not set for children", component.getKey(), metricKey);
96+
// There is always a chance, that required metrics were not calculated for this particular component
97+
// (e.g. one of modules in a multi-module project doesn't contain any C/C++ data at all).
98+
// So don't complain about the missing data, but just ignore such components.
9399
return;
94100
}
95101
int aggregation = 0;
@@ -98,7 +104,7 @@ private static void compute(MeasureComputerContext context, String metricKey) {
98104
aggregation += childMeasure.getIntValue();
99105
}
100106
}
101-
LOG.info("Component {}: add measure {}, value {}", component.getKey(), metricKey, aggregation);
107+
LOG.debug("Component {}: add measure {}, value {}", component.getKey(), metricKey, aggregation);
102108
context.addMeasure(metricKey, aggregation);
103109
}
104110

cxx-squid/src/main/java/org/sonar/cxx/DensityMeasureComputer.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,17 @@ private static void compute(MeasureComputerContext context, String valueKey, Str
9797
final Measure valueMeasure = context.getMeasure(valueKey);
9898
final Measure totalMeasure = context.getMeasure(totalKey);
9999
if (valueMeasure == null || totalMeasure == null) {
100-
LOG.error("Component {}: not enough data to calcualte measure {}", context.getComponent().getKey(), densityKey);
100+
// There is always a chance, that required metrics were not calculated for this particular component
101+
// (e.g. one of modules in a multi-module project doesn't contain any C/C++ data at all).
102+
// So don't complain about the missing data, but just ignore such components.
101103
return;
102104
}
103105
final Measure existingMeasure = context.getMeasure(densityKey);
104106
if (existingMeasure != null) {
105-
LOG.error("Component {}: measure {} already calculated, value = {}", component.getKey(), densityKey,
107+
// Measurement <densityKey> should not be calculated manually (e.g. in the sensors).
108+
// Otherwise there is a chance, that your custom calculation won't work properly for
109+
// multi-module projects.
110+
LOG.debug("Component {}: measure {} already calculated, value = {}", component.getKey(), densityKey,
106111
existingMeasure.getDoubleValue());
107112
return;
108113
}
@@ -118,7 +123,7 @@ private static void compute(MeasureComputerContext context, String valueKey, Str
118123
density = (double) value / (double) total * 100.0;
119124
}
120125

121-
LOG.info("Component {}: add measure {}, value {}", component.getKey(), densityKey, density);
126+
LOG.debug("Component {}: add measure {}, value {}", component.getKey(), densityKey, density);
122127
context.addMeasure(densityKey, density);
123128
}
124129

0 commit comments

Comments
 (0)