Skip to content

Commit 1666056

Browse files
amarzialibric3
andauthored
Ensure client stat reporter is started when the agent is not available at bootstrap (#9082)
* Ensure metric reporter is started when the agent is not available at bootstrap * Update dd-trace-core/src/test/groovy/datadog/trace/common/metrics/ConflatingMetricAggregatorTest.groovy Co-authored-by: Brice Dutheil <[email protected]> --------- Co-authored-by: Brice Dutheil <[email protected]>
1 parent 5353d51 commit 1666056

File tree

2 files changed

+41
-14
lines changed

2 files changed

+41
-14
lines changed

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -143,20 +143,16 @@ public ConflatingMetricsAggregator(
143143

144144
@Override
145145
public void start() {
146-
if (isMetricsEnabled()) {
147-
sink.register(this);
148-
thread.start();
149-
cancellation =
150-
AgentTaskScheduler.INSTANCE.scheduleAtFixedRate(
151-
new ReportTask(),
152-
this,
153-
reportingInterval,
154-
reportingInterval,
155-
reportingIntervalTimeUnit);
156-
log.debug("started metrics aggregator");
157-
} else {
158-
log.debug("metrics not supported by trace agent");
159-
}
146+
sink.register(this);
147+
thread.start();
148+
cancellation =
149+
AgentTaskScheduler.INSTANCE.scheduleAtFixedRate(
150+
new ReportTask(),
151+
this,
152+
reportingInterval,
153+
reportingInterval,
154+
reportingIntervalTimeUnit);
155+
log.debug("started metrics aggregator");
160156
}
161157

162158
private boolean isMetricsEnabled() {

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,37 @@ class ConflatingMetricAggregatorTest extends DDSpecification {
463463
aggregator.close()
464464
}
465465

466+
def "should start even if the agent is not available"() {
467+
setup:
468+
MetricWriter writer = Mock(MetricWriter)
469+
Sink sink = Stub(Sink)
470+
DDAgentFeaturesDiscovery features = Mock(DDAgentFeaturesDiscovery)
471+
features.supportsMetrics() >> false
472+
ConflatingMetricsAggregator aggregator = new ConflatingMetricsAggregator(empty,
473+
features, sink, writer, 10, queueSize, 200, MILLISECONDS)
474+
final spans = [
475+
new SimpleSpan("service" , "operation", "resource", "type", false, true, false, 0, 10, HTTP_OK)
476+
]
477+
aggregator.start()
478+
479+
when:
480+
aggregator.publish(spans)
481+
Thread.sleep(1_000)
482+
483+
then:
484+
0 * writer._
485+
when:
486+
features.supportsMetrics() >> true
487+
aggregator.publish(spans)
488+
Thread.sleep(1_000)
489+
490+
then:
491+
(1.._) * writer._
492+
493+
cleanup:
494+
aggregator.close()
495+
}
496+
466497
def "force flush should wait for aggregator to start"() {
467498
setup:
468499
int maxAggregates = 10

0 commit comments

Comments
 (0)