Skip to content

Commit f1bc43a

Browse files
committed
Only report when hits are nonzero
1 parent 58bde96 commit f1bc43a

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

dd-trace-core/src/main/java/datadog/trace/common/metrics/Aggregator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ private CommonKeyCleaner(Set<MetricKey> commonKeys, HealthMetrics healthMetrics)
200200
@Override
201201
public void accept(Map.Entry<MetricKey, AggregateMetric> expired) {
202202
commonKeys.remove(expired.getKey());
203-
healthMetrics.onStatsAggregateDropped();
203+
if (expired.getValue().getHitCount() > 0) {
204+
healthMetrics.onStatsAggregateDropped();
205+
}
204206
}
205207
}
206208
}

dd-trace-core/src/test/groovy/datadog/trace/common/metrics/ConflatingMetricAggregatorTest.groovy

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,52 @@ class ConflatingMetricAggregatorTest extends DDSpecification {
978978
aggregator.close()
979979
}
980980

981+
def "should not report dropped aggregate when evicted entry was already flushed"() {
982+
setup:
983+
int maxAggregates = 5
984+
MetricWriter writer = Mock(MetricWriter)
985+
Sink sink = Stub(Sink)
986+
DDAgentFeaturesDiscovery features = Mock(DDAgentFeaturesDiscovery)
987+
features.supportsMetrics() >> true
988+
features.peerTags() >> []
989+
HealthMetrics healthMetrics = Mock(HealthMetrics)
990+
ConflatingMetricsAggregator aggregator = new ConflatingMetricsAggregator(empty,
991+
features, healthMetrics, sink, writer, maxAggregates, queueSize, reportingInterval, SECONDS, false)
992+
aggregator.start()
993+
994+
when: "fill cache and flush — entries are cleared (hitCount=0) but stay in the LRU"
995+
CountDownLatch latch1 = new CountDownLatch(1)
996+
for (int i = 0; i < maxAggregates; ++i) {
997+
aggregator.publish([
998+
new SimpleSpan("service" + i, "operation", "resource", "type", false, true, false, 0, 100, HTTP_OK)
999+
.setTag(SPAN_KIND, "baz")
1000+
])
1001+
}
1002+
aggregator.report()
1003+
latch1.await(2, SECONDS)
1004+
1005+
then:
1006+
1 * writer.finishBucket() >> { latch1.countDown() }
1007+
1008+
when: "publish new distinct spans — LRU evicts the cleared entries before the next report"
1009+
CountDownLatch latch2 = new CountDownLatch(1)
1010+
for (int i = maxAggregates; i < maxAggregates * 2; ++i) {
1011+
aggregator.publish([
1012+
new SimpleSpan("service" + i, "operation", "resource", "type", false, true, false, 0, 100, HTTP_OK)
1013+
.setTag(SPAN_KIND, "baz")
1014+
])
1015+
}
1016+
aggregator.report()
1017+
latch2.await(2, SECONDS)
1018+
1019+
then: "no drop metric because all evicted entries had hitCount=0 (already reported)"
1020+
1 * writer.finishBucket() >> { latch2.countDown() }
1021+
0 * healthMetrics.onStatsAggregateDropped()
1022+
1023+
cleanup:
1024+
aggregator.close()
1025+
}
1026+
9811027
def "aggregate not updated in reporting interval not reported"() {
9821028
setup:
9831029
int maxAggregates = 10

0 commit comments

Comments
 (0)