@@ -14,14 +14,17 @@ import (
14
14
"testing"
15
15
16
16
"github.com/DataDog/agent-payload/v5/gogen"
17
+ pb "github.com/DataDog/datadog-agent/pkg/proto/pbgo/trace"
17
18
"github.com/stretchr/testify/assert"
18
19
"github.com/stretchr/testify/require"
19
20
"go.opentelemetry.io/collector/component/componenttest"
21
+ "go.opentelemetry.io/collector/consumer"
20
22
"go.opentelemetry.io/collector/consumer/consumertest"
21
23
"go.opentelemetry.io/collector/pdata/pcommon"
22
24
"go.opentelemetry.io/collector/pdata/pmetric"
23
25
"go.opentelemetry.io/collector/receiver/receivertest"
24
26
"go.uber.org/multierr"
27
+ "google.golang.org/protobuf/proto"
25
28
)
26
29
27
30
func TestDatadogTracesReceiver_Lifecycle (t * testing.T ) {
@@ -84,6 +87,12 @@ func TestDatadogServer(t *testing.T) {
84
87
expectCode : http .StatusBadRequest ,
85
88
expectContent : "Unable to unmarshal reqs\n " ,
86
89
},
90
+ {
91
+ name : "Fake featuresdiscovery" ,
92
+ op : nil , // Content-length: 0.
93
+ expectCode : http .StatusBadRequest ,
94
+ expectContent : "Fake featuresdiscovery\n " ,
95
+ },
87
96
} {
88
97
tc := tc
89
98
t .Run (tc .name , func (t * testing.T ) {
@@ -108,6 +117,143 @@ func TestDatadogServer(t *testing.T) {
108
117
}
109
118
}
110
119
120
+ func TestDatadogInfoEndpoint (t * testing.T ) {
121
+ for _ , tc := range []struct {
122
+ name string
123
+ tracesConsumer consumer.Traces
124
+ metricsConsumer consumer.Metrics
125
+
126
+ expectContent string
127
+ }{
128
+ {
129
+ name : "No consumers" ,
130
+ tracesConsumer : nil ,
131
+ metricsConsumer : nil ,
132
+ expectContent : `{
133
+ "version": "datadogreceiver-otelcol-latest",
134
+ "endpoints": [
135
+ "/"
136
+ ],
137
+ "client_drop_p0s": false,
138
+ "span_meta_structs": false,
139
+ "long_running_spans": false,
140
+ "config": null
141
+ }` ,
142
+ },
143
+ {
144
+ name : "Traces consumer only" ,
145
+ tracesConsumer : consumertest .NewNop (),
146
+ metricsConsumer : nil ,
147
+ expectContent : `{
148
+ "version": "datadogreceiver-otelcol-latest",
149
+ "endpoints": [
150
+ "/",
151
+ "/v0.3/traces",
152
+ "/v0.4/traces",
153
+ "/v0.5/traces",
154
+ "/v0.7/traces",
155
+ "/api/v0.2/traces"
156
+ ],
157
+ "client_drop_p0s": false,
158
+ "span_meta_structs": false,
159
+ "long_running_spans": false,
160
+ "config": null
161
+ }` ,
162
+ },
163
+ {
164
+ name : "Metrics consumer only" ,
165
+ tracesConsumer : nil ,
166
+ metricsConsumer : consumertest .NewNop (),
167
+ expectContent : `{
168
+ "version": "datadogreceiver-otelcol-latest",
169
+ "endpoints": [
170
+ "/",
171
+ "/api/v1/series",
172
+ "/api/v2/series",
173
+ "/api/v1/check_run",
174
+ "/api/v1/sketches",
175
+ "/api/beta/sketches",
176
+ "/intake",
177
+ "/api/v1/distribution_points",
178
+ "/v0.6/stats"
179
+ ],
180
+ "client_drop_p0s": false,
181
+ "span_meta_structs": false,
182
+ "long_running_spans": false,
183
+ "config": null
184
+ }` ,
185
+ },
186
+ {
187
+ name : "Both consumers" ,
188
+ tracesConsumer : consumertest .NewNop (),
189
+ metricsConsumer : consumertest .NewNop (),
190
+ expectContent : `{
191
+ "version": "datadogreceiver-otelcol-latest",
192
+ "endpoints": [
193
+ "/",
194
+ "/v0.3/traces",
195
+ "/v0.4/traces",
196
+ "/v0.5/traces",
197
+ "/v0.7/traces",
198
+ "/api/v0.2/traces",
199
+ "/api/v1/series",
200
+ "/api/v2/series",
201
+ "/api/v1/check_run",
202
+ "/api/v1/sketches",
203
+ "/api/beta/sketches",
204
+ "/intake",
205
+ "/api/v1/distribution_points",
206
+ "/v0.6/stats"
207
+ ],
208
+ "client_drop_p0s": false,
209
+ "span_meta_structs": false,
210
+ "long_running_spans": false,
211
+ "config": null
212
+ }` ,
213
+ },
214
+ } {
215
+ tc := tc
216
+ t .Run (tc .name , func (t * testing.T ) {
217
+ t .Parallel ()
218
+
219
+ cfg := createDefaultConfig ().(* Config )
220
+ cfg .Endpoint = "localhost:0" // Using a randomly assigned address
221
+
222
+ dd , err := newDataDogReceiver (
223
+ cfg ,
224
+ receivertest .NewNopSettings (),
225
+ )
226
+ require .NoError (t , err , "Must not error when creating receiver" )
227
+
228
+ dd .(* datadogReceiver ).nextTracesConsumer = tc .tracesConsumer
229
+ dd .(* datadogReceiver ).nextMetricsConsumer = tc .metricsConsumer
230
+
231
+ ctx , cancel := context .WithCancel (context .Background ())
232
+ t .Cleanup (cancel )
233
+
234
+ require .NoError (t , dd .Start (ctx , componenttest .NewNopHost ()))
235
+ t .Cleanup (func () {
236
+ require .NoError (t , dd .Shutdown (ctx ), "Must not error shutting down" )
237
+ })
238
+
239
+ req , err := http .NewRequest (
240
+ http .MethodPost ,
241
+ fmt .Sprintf ("http://%s/info" , dd .(* datadogReceiver ).address ),
242
+ nil ,
243
+ )
244
+ require .NoError (t , err , "Must not error when creating request" )
245
+
246
+ resp , err := http .DefaultClient .Do (req )
247
+ require .NoError (t , err , "Must not error performing request" )
248
+
249
+ body , err := io .ReadAll (resp .Body )
250
+ require .NoError (t , multierr .Combine (err , resp .Body .Close ()), "Must not error when reading body" )
251
+ require .Equal (t , tc .expectContent , string (body ), "Expected response to be '%s', got %s" , tc .expectContent , string (body ))
252
+ require .Equal (t , http .StatusOK , resp .StatusCode )
253
+ })
254
+ }
255
+ }
256
+
111
257
func TestDatadogMetricsV1_EndToEnd (t * testing.T ) {
112
258
cfg := createDefaultConfig ().(* Config )
113
259
cfg .Endpoint = "localhost:0" // Using a randomly assigned address
@@ -163,7 +309,7 @@ func TestDatadogMetricsV1_EndToEnd(t *testing.T) {
163
309
assert .Equal (t , pmetric .MetricTypeSum , metric .Type ())
164
310
assert .Equal (t , "system.load.1" , metric .Name ())
165
311
assert .Equal (t , pmetric .AggregationTemporalityDelta , metric .Sum ().AggregationTemporality ())
166
- assert .Equal ( t , false , metric .Sum ().IsMonotonic ())
312
+ assert .False ( t , metric .Sum ().IsMonotonic ())
167
313
assert .Equal (t , pcommon .Timestamp (1636629071 * 1_000_000_000 ), metric .Sum ().DataPoints ().At (0 ).Timestamp ())
168
314
assert .Equal (t , 0.7 , metric .Sum ().DataPoints ().At (0 ).DoubleValue ())
169
315
expectedEnvironment , _ := metric .Sum ().DataPoints ().At (0 ).Attributes ().Get ("environment" )
@@ -241,7 +387,7 @@ func TestDatadogMetricsV2_EndToEnd(t *testing.T) {
241
387
assert .Equal (t , pmetric .MetricTypeSum , metric .Type ())
242
388
assert .Equal (t , "system.load.1" , metric .Name ())
243
389
assert .Equal (t , pmetric .AggregationTemporalityDelta , metric .Sum ().AggregationTemporality ())
244
- assert .Equal ( t , false , metric .Sum ().IsMonotonic ())
390
+ assert .False ( t , metric .Sum ().IsMonotonic ())
245
391
assert .Equal (t , pcommon .Timestamp (1636629071 * 1_000_000_000 ), metric .Sum ().DataPoints ().At (0 ).Timestamp ())
246
392
assert .Equal (t , 1.5 , metric .Sum ().DataPoints ().At (0 ).DoubleValue ())
247
393
assert .Equal (t , pcommon .Timestamp (0 ), metric .Sum ().DataPoints ().At (0 ).StartTimestamp ())
0 commit comments