Skip to content

Commit bca7d15

Browse files
amarzialibric3
andauthored
Exclude long running partial versions from stats (#9495)
* Exclude long running partial versions from stats * Update dd-trace-core/src/main/java/datadog/trace/common/metrics/ConflatingMetricsAggregator.java Co-authored-by: Brice Dutheil <[email protected]> * suggestion --------- Co-authored-by: Brice Dutheil <[email protected]>
1 parent 42be7a0 commit bca7d15

File tree

7 files changed

+78
-1
lines changed

7 files changed

+78
-1
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ public boolean publish(List<? extends CoreSpan<?>> trace) {
293293

294294
private boolean shouldComputeMetric(CoreSpan<?> span) {
295295
return (span.isMeasured() || span.isTopLevel() || spanKindEligible(span))
296+
&& span.getLongRunningVersion()
297+
<= 0 // either not long-running or unpublished long-running span
296298
&& span.getDurationNano() > 0;
297299
}
298300

dd-trace-core/src/main/java/datadog/trace/core/CoreSpan.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,14 @@ T setSamplingPriority(
114114
* @return this
115115
*/
116116
T setMetaStruct(final String field, final Object value);
117+
118+
/**
119+
* Version of a span that can be set by the long running spans feature:
120+
* <li>eq 0 -> span is not long running.
121+
* <li>lt 0 -> finished span that had running versions previously written.
122+
* <li>gt 0 -> long running span and its write version.
123+
*
124+
* @return the version.
125+
*/
126+
int getLongRunningVersion();
117127
}

dd-trace-core/src/main/java/datadog/trace/core/DDSpan.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,4 +869,9 @@ public void copyPropagationAndBaggage(final AgentSpan source) {
869869
sourceSpanContext.getBaggageItems().forEach(context::setBaggageItem);
870870
}
871871
}
872+
873+
@Override
874+
public int getLongRunningVersion() {
875+
return longRunningVersion;
876+
}
872877
}

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,48 @@ class ConflatingMetricAggregatorTest extends DDSpecification {
820820
aggregator.close()
821821
}
822822

823+
def "should not count partial snapshot(long running)"() {
824+
setup:
825+
MetricWriter writer = Mock(MetricWriter)
826+
Sink sink = Stub(Sink)
827+
DDAgentFeaturesDiscovery features = Mock(DDAgentFeaturesDiscovery)
828+
features.supportsMetrics() >> true
829+
ConflatingMetricsAggregator aggregator = new ConflatingMetricsAggregator(empty,
830+
features, HealthMetrics.NO_OP, sink, writer, 10, queueSize, reportingInterval, SECONDS)
831+
aggregator.start()
832+
833+
when:
834+
CountDownLatch latch = new CountDownLatch(1)
835+
aggregator.publish([
836+
new SimpleSpan("service", "operation", "resource", "type", true, true, false, 0, 100, HTTP_OK, true, 12345),
837+
new SimpleSpan("service", "operation", "resource", "type", true, true, false, 0, 100, HTTP_OK, true, 0)
838+
])
839+
aggregator.report()
840+
def latchTriggered = latch.await(2, SECONDS)
841+
842+
then:
843+
latchTriggered
844+
1 * writer.startBucket(1, _, _)
845+
1 * writer.add(
846+
new MetricKey(
847+
"resource",
848+
"service",
849+
"operation",
850+
"type",
851+
HTTP_OK,
852+
false,
853+
true,
854+
"",
855+
[]
856+
), { AggregateMetric aggregateMetric ->
857+
aggregateMetric.getHitCount() == 1 && aggregateMetric.getTopLevelCount() == 1 && aggregateMetric.getDuration() == 100
858+
})
859+
1 * writer.finishBucket() >> { latch.countDown() }
860+
861+
cleanup:
862+
aggregator.close()
863+
}
864+
823865
def reportAndWaitUntilEmpty(ConflatingMetricsAggregator aggregator) {
824866
waitUntilEmpty(aggregator)
825867
aggregator.report()

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class SimpleSpan implements CoreSpan<SimpleSpan> {
1919

2020
private final long duration
2121
private final long startTime
22+
private final long longRunningVersion
2223

2324
private final Map<Object, Object> tags = [:]
2425

@@ -33,7 +34,8 @@ class SimpleSpan implements CoreSpan<SimpleSpan> {
3334
long startTime,
3435
long duration,
3536
int statusCode,
36-
boolean traceRoot = false
37+
boolean traceRoot = false,
38+
int longRunningVersion = 0
3739
) {
3840
this.serviceName = serviceName
3941
this.operationName = operationName
@@ -46,6 +48,7 @@ class SimpleSpan implements CoreSpan<SimpleSpan> {
4648
this.startTime = startTime
4749
this.duration = duration
4850
this.statusCode = (short) statusCode
51+
this.longRunningVersion = longRunningVersion
4952
}
5053

5154
@Override
@@ -266,4 +269,9 @@ class SimpleSpan implements CoreSpan<SimpleSpan> {
266269
SimpleSpan setMetaStruct(String field, Object value) {
267270
return this
268271
}
272+
273+
@Override
274+
int getLongRunningVersion() {
275+
return longRunningVersion
276+
}
269277
}

dd-trace-core/src/test/groovy/datadog/trace/common/writer/TraceGenerator.groovy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,5 +430,10 @@ class TraceGenerator {
430430
}
431431
return this
432432
}
433+
434+
@Override
435+
int getLongRunningVersion() {
436+
return 0
437+
}
433438
}
434439
}

dd-trace-core/src/traceAgentTest/groovy/TraceGenerator.groovy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,5 +401,10 @@ class TraceGenerator {
401401
PojoSpan setMetaStruct(String field, Object value) {
402402
return this
403403
}
404+
405+
@Override
406+
int getLongRunningVersion() {
407+
return 0
408+
}
404409
}
405410
}

0 commit comments

Comments
 (0)