|
1 | 1 | package datadog.trace.common.metrics |
2 | 2 |
|
| 3 | +import static datadog.trace.bootstrap.instrumentation.api.Tags.SPAN_KIND |
| 4 | +import static java.util.concurrent.TimeUnit.MILLISECONDS |
| 5 | +import static java.util.concurrent.TimeUnit.SECONDS |
| 6 | + |
3 | 7 | import datadog.communication.ddagent.DDAgentFeaturesDiscovery |
4 | 8 | import datadog.trace.api.WellKnownTags |
5 | 9 | import datadog.trace.bootstrap.instrumentation.api.UTF8BytesString |
6 | 10 | import datadog.trace.core.CoreSpan |
7 | 11 | import datadog.trace.core.monitor.HealthMetrics |
8 | 12 | import datadog.trace.test.util.DDSpecification |
9 | | -import spock.lang.Shared |
10 | | - |
11 | 13 | import java.util.concurrent.CompletableFuture |
12 | 14 | import java.util.concurrent.CountDownLatch |
13 | 15 | import java.util.concurrent.TimeUnit |
14 | 16 | import java.util.concurrent.TimeoutException |
15 | 17 | import java.util.function.Supplier |
16 | | - |
17 | | -import static datadog.trace.bootstrap.instrumentation.api.Tags.SPAN_KIND |
18 | | -import static java.util.concurrent.TimeUnit.MILLISECONDS |
19 | | -import static java.util.concurrent.TimeUnit.SECONDS |
| 18 | +import spock.lang.Shared |
20 | 19 |
|
21 | 20 | class ConflatingMetricAggregatorTest extends DDSpecification { |
22 | 21 |
|
@@ -96,6 +95,48 @@ class ConflatingMetricAggregatorTest extends DDSpecification { |
96 | 95 | aggregator.close() |
97 | 96 | } |
98 | 97 |
|
| 98 | + def "should be resilient to null resource names"() { |
| 99 | + setup: |
| 100 | + MetricWriter writer = Mock(MetricWriter) |
| 101 | + Sink sink = Stub(Sink) |
| 102 | + DDAgentFeaturesDiscovery features = Mock(DDAgentFeaturesDiscovery) |
| 103 | + features.supportsMetrics() >> true |
| 104 | + features.peerTags() >> [] |
| 105 | + ConflatingMetricsAggregator aggregator = new ConflatingMetricsAggregator(empty, |
| 106 | + features, HealthMetrics.NO_OP, sink, writer, 10, queueSize, reportingInterval, SECONDS) |
| 107 | + aggregator.start() |
| 108 | + |
| 109 | + when: |
| 110 | + CountDownLatch latch = new CountDownLatch(1) |
| 111 | + aggregator.publish([ |
| 112 | + new SimpleSpan("service", "operation", null, "type", false, true, false, 0, 100, HTTP_OK) |
| 113 | + .setTag(SPAN_KIND, "baz") |
| 114 | + ]) |
| 115 | + aggregator.report() |
| 116 | + def latchTriggered = latch.await(2, SECONDS) |
| 117 | + |
| 118 | + then: |
| 119 | + latchTriggered |
| 120 | + 1 * writer.startBucket(1, _, _) |
| 121 | + 1 * writer.add(new MetricKey( |
| 122 | + null, |
| 123 | + "service", |
| 124 | + "operation", |
| 125 | + "type", |
| 126 | + HTTP_OK, |
| 127 | + false, |
| 128 | + false, |
| 129 | + "baz", |
| 130 | + [] |
| 131 | + ), _) >> { MetricKey key, AggregateMetric value -> |
| 132 | + value.getHitCount() == 1 && value.getTopLevelCount() == 1 && value.getDuration() == 100 |
| 133 | + } |
| 134 | + 1 * writer.finishBucket() >> { latch.countDown() } |
| 135 | + |
| 136 | + cleanup: |
| 137 | + aggregator.close() |
| 138 | + } |
| 139 | + |
99 | 140 | def "unmeasured top level spans have metrics computed"() { |
100 | 141 | setup: |
101 | 142 | MetricWriter writer = Mock(MetricWriter) |
|
0 commit comments