Skip to content

Commit 6800ca8

Browse files
committed
Fixed http tests, improved test coverage
1 parent 8718b22 commit 6800ca8

File tree

2 files changed

+48
-18
lines changed

2 files changed

+48
-18
lines changed

dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/base/HttpClientTest.groovy

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import datadog.trace.agent.test.server.http.HttpProxy
66
import datadog.trace.api.DDSpanTypes
77
import datadog.trace.api.DDTags
88
import datadog.trace.api.config.TracerConfig
9+
import datadog.trace.api.datastreams.DataStreamsContext
910
import datadog.trace.api.datastreams.DataStreamsTags
1011
import datadog.trace.bootstrap.instrumentation.api.Tags
1112
import datadog.trace.bootstrap.instrumentation.api.URIUtils
@@ -36,6 +37,7 @@ abstract class HttpClientTest extends VersionedNamingTestBase {
3637
protected static final int READ_TIMEOUT_MS = TimeUnit.SECONDS.toMillis(5) as int
3738
protected static final BASIC_AUTH_KEY = "custom_authorization_header"
3839
protected static final BASIC_AUTH_VAL = "plain text auth token"
40+
protected static final DSM_EDGE_TAGS = DataStreamsContext.forHttpClient().tags()
3941

4042
@AutoCleanup
4143
@Shared
@@ -175,7 +177,7 @@ abstract class HttpClientTest extends VersionedNamingTestBase {
175177
if (isDataStreamsEnabled()) {
176178
StatsGroup first = TEST_DATA_STREAMS_WRITER.groups.find { it.parentHash == 0 }
177179
verifyAll(first) {
178-
getTags() == DataStreamsTags.fromTags("type:http", "direction:in")
180+
getTags() == DSM_EDGE_TAGS
179181
}
180182
}
181183

@@ -217,7 +219,7 @@ abstract class HttpClientTest extends VersionedNamingTestBase {
217219
if (isDataStreamsEnabled()) {
218220
StatsGroup first = TEST_DATA_STREAMS_WRITER.groups.find { it.parentHash == 0 }
219221
verifyAll(first) {
220-
getTags() == DataStreamsTags.fromTags("type:http", "direction:in")
222+
getTags() == DSM_EDGE_TAGS
221223
}
222224
}
223225

@@ -264,7 +266,7 @@ abstract class HttpClientTest extends VersionedNamingTestBase {
264266
if (isDataStreamsEnabled()) {
265267
StatsGroup first = TEST_DATA_STREAMS_WRITER.groups.find { it.parentHash == 0 }
266268
verifyAll(first) {
267-
getTags() == DataStreamsTags.fromTags("type:http", "direction:in")
269+
getTags() == DSM_EDGE_TAGS
268270
}
269271
}
270272

@@ -298,7 +300,7 @@ abstract class HttpClientTest extends VersionedNamingTestBase {
298300
if (isDataStreamsEnabled()) {
299301
StatsGroup first = TEST_DATA_STREAMS_WRITER.groups.find { it.parentHash == 0 }
300302
verifyAll(first) {
301-
getTags() == DataStreamsTags.fromTags("type:http", "direction:in")
303+
getTags() == DSM_EDGE_TAGS
302304
}
303305
}
304306

@@ -335,7 +337,7 @@ abstract class HttpClientTest extends VersionedNamingTestBase {
335337
if (isDataStreamsEnabled()) {
336338
StatsGroup first = TEST_DATA_STREAMS_WRITER.groups.find { it.parentHash == 0 }
337339
verifyAll(first) {
338-
getTags() == DataStreamsTags.fromTags("type:http", "direction:in")
340+
getTags() == DSM_EDGE_TAGS
339341
}
340342
}
341343

@@ -373,7 +375,7 @@ abstract class HttpClientTest extends VersionedNamingTestBase {
373375
if (isDataStreamsEnabled()) {
374376
StatsGroup first = TEST_DATA_STREAMS_WRITER.groups.find { it.parentHash == 0 }
375377
verifyAll(first) {
376-
getTags() == DataStreamsTags.fromTags("type:http", "direction:in")
378+
getTags() == DSM_EDGE_TAGS
377379
}
378380
}
379381

@@ -406,7 +408,7 @@ abstract class HttpClientTest extends VersionedNamingTestBase {
406408
if (isDataStreamsEnabled()) {
407409
StatsGroup first = TEST_DATA_STREAMS_WRITER.groups.find { it.parentHash == 0 }
408410
verifyAll(first) {
409-
getTags() == DataStreamsTags.fromTags("type:http", "direction:in")
411+
getTags() == DSM_EDGE_TAGS
410412
}
411413
}
412414

@@ -440,7 +442,7 @@ abstract class HttpClientTest extends VersionedNamingTestBase {
440442
if (isDataStreamsEnabled()) {
441443
StatsGroup first = TEST_DATA_STREAMS_WRITER.groups.find { it.parentHash == 0 }
442444
verifyAll(first) {
443-
getTags() == DataStreamsTags.fromTags("type:http", "direction:in")
445+
getTags() == DSM_EDGE_TAGS
444446
}
445447
}
446448

@@ -484,7 +486,7 @@ abstract class HttpClientTest extends VersionedNamingTestBase {
484486
if (isDataStreamsEnabled()) {
485487
StatsGroup first = TEST_DATA_STREAMS_WRITER.groups.find { it.parentHash == 0 }
486488
verifyAll(first) {
487-
getTags() == DataStreamsTags.fromTags("type:http", "direction:in")
489+
getTags() == DSM_EDGE_TAGS
488490
}
489491
}
490492
}
@@ -531,7 +533,7 @@ abstract class HttpClientTest extends VersionedNamingTestBase {
531533
if (isDataStreamsEnabled()) {
532534
StatsGroup first = TEST_DATA_STREAMS_WRITER.groups.find { it.parentHash == 0 }
533535
verifyAll(first) {
534-
getTags() == DataStreamsTags.fromTags("type:http", "direction:in")
536+
getTags() == DSM_EDGE_TAGS
535537
}
536538
}
537539

@@ -567,7 +569,7 @@ abstract class HttpClientTest extends VersionedNamingTestBase {
567569
if (isDataStreamsEnabled()) {
568570
StatsGroup first = TEST_DATA_STREAMS_WRITER.groups.find { it.parentHash == 0 }
569571
verifyAll(first) {
570-
getTags() == DataStreamsTags.fromTags("type:http", "direction:in")
572+
getTags() == DSM_EDGE_TAGS
571573
}
572574
}
573575

@@ -601,7 +603,7 @@ abstract class HttpClientTest extends VersionedNamingTestBase {
601603
if (isDataStreamsEnabled()) {
602604
StatsGroup first = TEST_DATA_STREAMS_WRITER.groups.find { it.parentHash == 0 }
603605
verifyAll(first) {
604-
getTags() == DataStreamsTags.fromTags("type:http", "direction:in")
606+
getTags() == DSM_EDGE_TAGS
605607
}
606608
}
607609

@@ -659,7 +661,7 @@ abstract class HttpClientTest extends VersionedNamingTestBase {
659661
if (isDataStreamsEnabled()) {
660662
StatsGroup first = TEST_DATA_STREAMS_WRITER.groups.find { it.parentHash == 0 }
661663
verifyAll(first) {
662-
getTags() == DataStreamsTags.fromTags("type:http", "direction:in")
664+
getTags() == DSM_EDGE_TAGS
663665
}
664666
}
665667

@@ -743,7 +745,7 @@ abstract class HttpClientTest extends VersionedNamingTestBase {
743745
if (isDataStreamsEnabled()) {
744746
StatsGroup first = TEST_DATA_STREAMS_WRITER.groups.find { it.parentHash == 0 }
745747
verifyAll(first) {
746-
getTags() == DataStreamsTags.fromTags("type:http", "direction:in")
748+
getTags() == DSM_EDGE_TAGS
747749
}
748750
}
749751

@@ -771,7 +773,7 @@ abstract class HttpClientTest extends VersionedNamingTestBase {
771773
if (isDataStreamsEnabled()) {
772774
StatsGroup first = TEST_DATA_STREAMS_WRITER.groups.find { it.parentHash == 0 }
773775
verifyAll(first) {
774-
getTags() == DataStreamsTags.fromTags("type:http", "direction:in")
776+
getTags() == DSM_EDGE_TAGS
775777
}
776778
}
777779

@@ -804,7 +806,7 @@ abstract class HttpClientTest extends VersionedNamingTestBase {
804806
if (isDataStreamsEnabled()) {
805807
StatsGroup first = TEST_DATA_STREAMS_WRITER.groups.find { it.parentHash == 0 }
806808
verifyAll(first) {
807-
getTags() == DataStreamsTags.fromTags("type:http", "direction:in")
809+
getTags() == DSM_EDGE_TAGS
808810
}
809811
}
810812

internal-api/src/test/groovy/datadog/trace/api/datastreams/DataStreamsTagsTest.groovy

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,49 @@ class DataStreamsTagsTest extends Specification {
6767

6868
def 'test from tags'() {
6969
setup:
70-
def one = DataStreamsTags.fromTags("direction:in", "topic:abc")
70+
def one = DataStreamsTags.fromTags(
71+
"direction:in",
72+
"topic:abc",
73+
"exchange:exchange",
74+
"partition:0",
75+
"has_routing_key:true",
76+
"ds.name:dataset",
77+
"subscription:subscription",
78+
"bus:bus",
79+
"garbage",
80+
"ds.namespace:namespace",
81+
"manual_checkpoint:false",
82+
"consumer_group:group",
83+
"group:group"
84+
)
7185
expect:
72-
one.nonNullSize() == 2
86+
one.nonNullSize() == 12
87+
one.bus == "bus:bus"
7388
one.direction == "direction:in"
7489
one.topic == "topic:abc"
90+
one.exchange == "exchange:exchange"
91+
one.partition == "partition:0"
92+
one.hasRoutingKey == "has_routing_key:true"
93+
one.datasetName == "ds.name:dataset"
94+
one.subscription == "subscription:subscription"
95+
one.datasetNamespace == "ds.namespace:namespace"
96+
one.isManual == "manual_checkpoint:false"
97+
one.consumerGroup == "consumer_group:group"
98+
one.group == "group:group"
7599
}
76100

77101
def 'test create'() {
78102
setup:
79103
def one = DataStreamsTags.create("type", DataStreamsTags.Direction.Outbound)
80104
def two = DataStreamsTags.create("type", DataStreamsTags.Direction.Outbound, "topic")
81105
def three = DataStreamsTags.create("type", DataStreamsTags.Direction.Outbound, "topic", "group", "cluster")
106+
def four = DataStreamsTags.createWithPartition("type", "topic", "partition", "cluster", "group")
107+
def five = DataStreamsTags.createWithDataset("type", DataStreamsTags.Direction.Outbound, "topic", "dataset", "namespace")
82108
expect:
83109
one == DataStreamsTags.fromTags("type:type", "direction:out")
84110
two == DataStreamsTags.fromTags("type:type", "direction:out", "topic:topic")
85111
three == DataStreamsTags.fromTags("type:type", "direction:out", "topic:topic", "group:group", "kafka_cluster_id:cluster")
112+
four == DataStreamsTags.fromTags("type:type", "topic:topic", "partition:partition", "kafka_cluster_id:cluster", "consumer_group:group")
113+
five == DataStreamsTags.fromTags("type:type", "direction:out", "topic:topic", "ds.name:dataset", "ds.namespace:namespace")
86114
}
87115
}

0 commit comments

Comments
 (0)