Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/traces/config_test.go
4093 views
1
package traces
2
3
import (
4
"os"
5
"sort"
6
"strings"
7
"testing"
8
9
"github.com/grafana/agent/pkg/traces/pushreceiver"
10
"github.com/stretchr/testify/assert"
11
"github.com/stretchr/testify/require"
12
"go.opentelemetry.io/collector/config"
13
"go.opentelemetry.io/collector/confmap"
14
"go.opentelemetry.io/collector/service/external/configunmarshaler"
15
"gopkg.in/yaml.v2"
16
)
17
18
func tmpFile(t *testing.T, content string) (*os.File, func()) {
19
f, err := os.CreateTemp("", "")
20
require.NoError(t, err)
21
22
_, err = f.Write([]byte(content))
23
require.NoError(t, err)
24
25
err = f.Close()
26
require.NoError(t, err)
27
28
return f, func() {
29
os.Remove(f.Name())
30
}
31
}
32
33
func TestOTelConfig(t *testing.T) {
34
// create a password file to test the password file logic
35
password := "password_in_file"
36
passwordFile, teardown := tmpFile(t, password)
37
defer teardown()
38
39
// Extra linefeed in password_file. Spaces, tabs line feeds should be
40
// stripped when reading it
41
passwordFileExtraNewline, teardown := tmpFile(t, password+"\n")
42
defer teardown()
43
44
// tests!
45
tt := []struct {
46
name string
47
cfg string
48
expectedError bool
49
expectedConfig string
50
}{
51
{
52
name: "disabled",
53
cfg: "",
54
expectedError: true,
55
},
56
{
57
name: "no receivers",
58
cfg: `
59
receivers:
60
`,
61
expectedError: true,
62
},
63
{
64
name: "no rw endpoint",
65
cfg: `
66
receivers:
67
jaeger:
68
`,
69
expectedError: true,
70
},
71
{
72
name: "empty receiver config",
73
cfg: `
74
receivers:
75
jaeger:
76
remote_write:
77
- endpoint: example.com:12345
78
`,
79
expectedError: true,
80
},
81
{
82
name: "basic config",
83
cfg: `
84
receivers:
85
jaeger:
86
protocols:
87
grpc:
88
remote_write:
89
- endpoint: example.com:12345
90
`,
91
expectedConfig: `
92
receivers:
93
push_receiver: {}
94
jaeger:
95
protocols:
96
grpc:
97
exporters:
98
otlp/0:
99
endpoint: example.com:12345
100
compression: gzip
101
retry_on_failure:
102
max_elapsed_time: 60s
103
processors: {}
104
extensions: {}
105
service:
106
pipelines:
107
traces:
108
exporters: ["otlp/0"]
109
processors: []
110
receivers: ["push_receiver", "jaeger"]
111
`,
112
},
113
{
114
name: "processor config",
115
cfg: `
116
receivers:
117
jaeger:
118
protocols:
119
grpc:
120
attributes:
121
actions:
122
- key: montgomery
123
value: forever
124
action: update
125
batch:
126
timeout: 5s
127
send_batch_size: 100
128
remote_write:
129
- endpoint: example.com:12345
130
retry_on_failure:
131
initial_interval: 10s
132
sending_queue:
133
num_consumers: 15
134
`,
135
expectedConfig: `
136
receivers:
137
push_receiver: {}
138
jaeger:
139
protocols:
140
grpc:
141
exporters:
142
otlp/0:
143
endpoint: example.com:12345
144
compression: gzip
145
retry_on_failure:
146
initial_interval: 10s
147
max_elapsed_time: 60s
148
sending_queue:
149
num_consumers: 15
150
processors:
151
attributes:
152
actions:
153
- key: montgomery
154
value: forever
155
action: update
156
batch:
157
timeout: 5s
158
send_batch_size: 100
159
extensions: {}
160
service:
161
pipelines:
162
traces:
163
exporters: ["otlp/0"]
164
processors: ["attributes", "batch"]
165
receivers: ["push_receiver", "jaeger"]
166
`,
167
},
168
{
169
name: "password in file",
170
cfg: `
171
receivers:
172
jaeger:
173
protocols:
174
grpc:
175
remote_write:
176
- insecure: true
177
endpoint: example.com:12345
178
basic_auth:
179
username: test
180
password_file: ` + passwordFile.Name(),
181
expectedConfig: `
182
receivers:
183
push_receiver: {}
184
jaeger:
185
protocols:
186
grpc:
187
exporters:
188
otlp/0:
189
endpoint: example.com:12345
190
compression: gzip
191
tls:
192
insecure: true
193
headers:
194
authorization: Basic dGVzdDpwYXNzd29yZF9pbl9maWxl
195
retry_on_failure:
196
max_elapsed_time: 60s
197
processors: {}
198
extensions: {}
199
service:
200
pipelines:
201
traces:
202
exporters: ["otlp/0"]
203
processors: []
204
receivers: ["push_receiver", "jaeger"]
205
`,
206
},
207
{
208
name: "password in file with extra newline",
209
cfg: `
210
receivers:
211
jaeger:
212
protocols:
213
grpc:
214
remote_write:
215
- insecure: true
216
endpoint: example.com:12345
217
format: otlp
218
basic_auth:
219
username: test
220
password_file: ` + passwordFileExtraNewline.Name(),
221
expectedConfig: `
222
receivers:
223
push_receiver: {}
224
jaeger:
225
protocols:
226
grpc:
227
exporters:
228
otlp/0:
229
endpoint: example.com:12345
230
compression: gzip
231
tls:
232
insecure: true
233
headers:
234
authorization: Basic dGVzdDpwYXNzd29yZF9pbl9maWxl
235
retry_on_failure:
236
max_elapsed_time: 60s
237
processors: {}
238
extensions: {}
239
service:
240
pipelines:
241
traces:
242
exporters: ["otlp/0"]
243
processors: []
244
receivers: ["push_receiver", "jaeger"]
245
`,
246
},
247
{
248
name: "insecure skip verify",
249
cfg: `
250
receivers:
251
jaeger:
252
protocols:
253
grpc:
254
remote_write:
255
- insecure_skip_verify: true
256
endpoint: example.com:12345`,
257
expectedConfig: `
258
receivers:
259
push_receiver: {}
260
jaeger:
261
protocols:
262
grpc:
263
exporters:
264
otlp/0:
265
endpoint: example.com:12345
266
compression: gzip
267
tls:
268
insecure_skip_verify: true
269
retry_on_failure:
270
max_elapsed_time: 60s
271
processors: {}
272
extensions: {}
273
service:
274
pipelines:
275
traces:
276
exporters: ["otlp/0"]
277
processors: []
278
receivers: ["push_receiver", "jaeger"]
279
`,
280
},
281
{
282
name: "no compression",
283
cfg: `
284
receivers:
285
jaeger:
286
protocols:
287
grpc:
288
remote_write:
289
- insecure_skip_verify: true
290
endpoint: example.com:12345
291
compression: none`,
292
expectedConfig: `
293
receivers:
294
push_receiver: {}
295
jaeger:
296
protocols:
297
grpc:
298
exporters:
299
otlp/0:
300
endpoint: example.com:12345
301
tls:
302
insecure_skip_verify: true
303
retry_on_failure:
304
max_elapsed_time: 60s
305
compression: none
306
processors: {}
307
extensions: {}
308
service:
309
pipelines:
310
traces:
311
exporters: ["otlp/0"]
312
processors: []
313
receivers: ["push_receiver", "jaeger"]
314
`,
315
},
316
{
317
name: "jaeger receiver remote_sampling TLS config",
318
cfg: `
319
receivers:
320
jaeger:
321
protocols:
322
grpc:
323
remote_sampling:
324
strategy_file: file_path
325
tls:
326
insecure: true
327
insecure_skip_verify: true
328
server_name_override: hostname
329
remote_write:
330
- endpoint: example.com:12345
331
`,
332
expectedConfig: `
333
receivers:
334
push_receiver: {}
335
jaeger:
336
protocols:
337
grpc:
338
remote_sampling:
339
strategy_file: file_path
340
tls:
341
insecure: true
342
insecure_skip_verify: true
343
server_name_override: hostname
344
exporters:
345
otlp/0:
346
endpoint: example.com:12345
347
compression: gzip
348
retry_on_failure:
349
max_elapsed_time: 60s
350
processors: {}
351
extensions: {}
352
service:
353
pipelines:
354
traces:
355
exporters: ["otlp/0"]
356
processors: []
357
receivers: ["push_receiver", "jaeger"]
358
`,
359
},
360
{
361
name: "push_config and remote_write",
362
cfg: `
363
receivers:
364
jaeger:
365
push_config:
366
endpoint: example:12345
367
remote_write:
368
- endpoint: anotherexample.com:12345
369
`,
370
expectedError: true,
371
},
372
{
373
name: "push_config.batch and batch",
374
cfg: `
375
receivers:
376
jaeger:
377
push_config:
378
endpoint: example:12345
379
batch:
380
timeout: 5s
381
send_batch_size: 100
382
batch:
383
timeout: 5s
384
send_batch_size: 100
385
remote_write:
386
- endpoint: anotherexample.com:12345
387
`,
388
expectedError: true,
389
},
390
{
391
name: "one backend with remote_write",
392
cfg: `
393
receivers:
394
jaeger:
395
protocols:
396
grpc:
397
remote_write:
398
- endpoint: example.com:12345
399
headers:
400
x-some-header: Some value!
401
`,
402
expectedConfig: `
403
receivers:
404
push_receiver: {}
405
jaeger:
406
protocols:
407
grpc:
408
exporters:
409
otlp/0:
410
endpoint: example.com:12345
411
compression: gzip
412
headers:
413
x-some-header: Some value!
414
retry_on_failure:
415
max_elapsed_time: 60s
416
processors: {}
417
extensions: {}
418
service:
419
pipelines:
420
traces:
421
exporters: ["otlp/0"]
422
processors: []
423
receivers: ["push_receiver", "jaeger"]
424
`,
425
},
426
{
427
name: "two backends in a remote_write block",
428
cfg: `
429
receivers:
430
jaeger:
431
protocols:
432
grpc:
433
remote_write:
434
- endpoint: example.com:12345
435
basic_auth:
436
username: test
437
password: blerg
438
- endpoint: anotherexample.com:12345
439
compression: none
440
insecure: false
441
insecure_skip_verify: true
442
basic_auth:
443
username: test
444
password_file: ` + passwordFile.Name() + `
445
retry_on_failure:
446
initial_interval: 10s
447
sending_queue:
448
num_consumers: 15
449
`,
450
expectedConfig: `
451
receivers:
452
push_receiver: {}
453
jaeger:
454
protocols:
455
grpc:
456
exporters:
457
otlp/0:
458
endpoint: example.com:12345
459
compression: gzip
460
headers:
461
authorization: Basic dGVzdDpibGVyZw==
462
retry_on_failure:
463
max_elapsed_time: 60s
464
otlp/1:
465
endpoint: anotherexample.com:12345
466
tls:
467
insecure: false
468
insecure_skip_verify: true
469
headers:
470
authorization: Basic dGVzdDpwYXNzd29yZF9pbl9maWxl
471
retry_on_failure:
472
initial_interval: 10s
473
max_elapsed_time: 60s
474
sending_queue:
475
num_consumers: 15
476
compression: none
477
processors: {}
478
extensions: {}
479
service:
480
pipelines:
481
traces:
482
exporters: ["otlp/1", "otlp/0"]
483
processors: []
484
receivers: ["push_receiver", "jaeger"]
485
`,
486
},
487
{
488
name: "batch block",
489
cfg: `
490
receivers:
491
jaeger:
492
protocols:
493
grpc:
494
remote_write:
495
- endpoint: example.com:12345
496
batch:
497
timeout: 5s
498
send_batch_size: 100
499
`,
500
expectedConfig: `
501
receivers:
502
push_receiver: {}
503
jaeger:
504
protocols:
505
grpc:
506
exporters:
507
otlp/0:
508
endpoint: example.com:12345
509
compression: gzip
510
retry_on_failure:
511
max_elapsed_time: 60s
512
processors:
513
batch:
514
timeout: 5s
515
send_batch_size: 100
516
extensions: {}
517
service:
518
pipelines:
519
traces:
520
exporters: ["otlp/0"]
521
processors: ["batch"]
522
receivers: ["push_receiver", "jaeger"]
523
`,
524
},
525
{
526
name: "span metrics remote write exporter",
527
cfg: `
528
receivers:
529
jaeger:
530
protocols:
531
grpc:
532
remote_write:
533
- endpoint: example.com:12345
534
spanmetrics:
535
latency_histogram_buckets: [2ms, 6ms, 10ms, 100ms, 250ms]
536
dimensions:
537
- name: http.method
538
default: GET
539
- name: http.status_code
540
metrics_instance: traces
541
dimensions_cache_size: 10000
542
`,
543
expectedConfig: `
544
receivers:
545
push_receiver: {}
546
noop:
547
jaeger:
548
protocols:
549
grpc:
550
exporters:
551
otlp/0:
552
endpoint: example.com:12345
553
compression: gzip
554
retry_on_failure:
555
max_elapsed_time: 60s
556
remote_write:
557
namespace: traces_spanmetrics
558
metrics_instance: traces
559
processors:
560
spanmetrics:
561
metrics_exporter: remote_write
562
latency_histogram_buckets: [2ms, 6ms, 10ms, 100ms, 250ms]
563
dimensions:
564
- name: http.method
565
default: GET
566
- name: http.status_code
567
dimensions_cache_size: 10000
568
extensions: {}
569
service:
570
pipelines:
571
traces:
572
exporters: ["otlp/0"]
573
processors: ["spanmetrics"]
574
receivers: ["push_receiver", "jaeger"]
575
metrics/spanmetrics:
576
exporters: ["remote_write"]
577
receivers: ["noop"]
578
`,
579
},
580
{
581
name: "span metrics prometheus exporter",
582
cfg: `
583
receivers:
584
jaeger:
585
protocols:
586
grpc:
587
remote_write:
588
- endpoint: example.com:12345
589
spanmetrics:
590
handler_endpoint: "0.0.0.0:8889"
591
`,
592
expectedConfig: `
593
receivers:
594
push_receiver: {}
595
noop:
596
jaeger:
597
protocols:
598
grpc:
599
exporters:
600
otlp/0:
601
endpoint: example.com:12345
602
compression: gzip
603
retry_on_failure:
604
max_elapsed_time: 60s
605
prometheus:
606
endpoint: "0.0.0.0:8889"
607
namespace: traces_spanmetrics
608
processors:
609
spanmetrics:
610
metrics_exporter: prometheus
611
extensions: {}
612
service:
613
pipelines:
614
traces:
615
exporters: ["otlp/0"]
616
processors: ["spanmetrics"]
617
receivers: ["push_receiver", "jaeger"]
618
metrics/spanmetrics:
619
exporters: ["prometheus"]
620
receivers: ["noop"]
621
`,
622
},
623
{
624
name: "span metrics prometheus and remote write exporters fail",
625
cfg: `
626
receivers:
627
jaeger:
628
protocols:
629
grpc:
630
remote_write:
631
- endpoint: example.com:12345
632
spanmetrics:
633
handler_endpoint: "0.0.0.0:8889"
634
metrics_instance: traces
635
`,
636
expectedError: true,
637
},
638
{
639
name: "tail sampling config",
640
cfg: `
641
receivers:
642
jaeger:
643
protocols:
644
grpc:
645
remote_write:
646
- endpoint: example.com:12345
647
tail_sampling:
648
decision_wait: 11s
649
num_traces: 98765
650
expected_new_traces_per_sec: 76
651
policies:
652
- type: always_sample
653
- type: latency
654
latency:
655
threshold_ms: 100
656
- type: numeric_attribute
657
numeric_attribute:
658
key: key1
659
min_value: 50
660
max_value: 100
661
- type: probabilistic
662
probabilistic:
663
sampling_percentage: 10
664
- type: status_code
665
status_code:
666
status_codes:
667
- ERROR
668
- UNSET
669
- type: string_attribute
670
string_attribute:
671
key: key
672
values:
673
- value1
674
- value2
675
- type: rate_limiting
676
rate_limiting:
677
spans_per_second: 35
678
`,
679
expectedConfig: `
680
receivers:
681
push_receiver: {}
682
jaeger:
683
protocols:
684
grpc:
685
exporters:
686
otlp/0:
687
endpoint: example.com:12345
688
compression: gzip
689
retry_on_failure:
690
max_elapsed_time: 60s
691
processors:
692
tail_sampling:
693
decision_wait: 11s
694
num_traces: 98765
695
expected_new_traces_per_sec: 76
696
policies:
697
- name: always_sample/0
698
type: always_sample
699
- name: latency/1
700
type: latency
701
latency:
702
threshold_ms: 100
703
- name: numeric_attribute/2
704
type: numeric_attribute
705
numeric_attribute:
706
key: key1
707
min_value: 50
708
max_value: 100
709
- name: probabilistic/3
710
type: probabilistic
711
probabilistic:
712
sampling_percentage: 10
713
- name: status_code/4
714
type: status_code
715
status_code:
716
status_codes:
717
- ERROR
718
- UNSET
719
- name: string_attribute/5
720
type: string_attribute
721
string_attribute:
722
key: key
723
values:
724
- value1
725
- value2
726
- name: rate_limiting/6
727
type: rate_limiting
728
rate_limiting:
729
spans_per_second: 35
730
extensions: {}
731
service:
732
pipelines:
733
traces:
734
exporters: ["otlp/0"]
735
processors: ["tail_sampling"]
736
receivers: ["push_receiver", "jaeger"]
737
`,
738
},
739
{
740
name: "tail sampling config with load balancing",
741
cfg: `
742
receivers:
743
jaeger:
744
protocols:
745
grpc:
746
remote_write:
747
- endpoint: example.com:12345
748
tail_sampling:
749
policies:
750
- type: always_sample
751
- type: string_attribute
752
string_attribute:
753
key: key
754
values:
755
- value1
756
- value2
757
load_balancing:
758
receiver_port: 8080
759
exporter:
760
insecure: true
761
resolver:
762
dns:
763
hostname: agent
764
port: 8080
765
`,
766
expectedConfig: `
767
receivers:
768
jaeger:
769
protocols:
770
grpc:
771
push_receiver: {}
772
otlp/lb:
773
protocols:
774
grpc:
775
endpoint: "0.0.0.0:8080"
776
exporters:
777
otlp/0:
778
endpoint: example.com:12345
779
compression: gzip
780
retry_on_failure:
781
max_elapsed_time: 60s
782
loadbalancing:
783
protocol:
784
otlp:
785
tls:
786
insecure: true
787
endpoint: noop
788
retry_on_failure:
789
max_elapsed_time: 60s
790
compression: none
791
resolver:
792
dns:
793
hostname: agent
794
port: 8080
795
processors:
796
tail_sampling:
797
decision_wait: 5s
798
policies:
799
- name: always_sample/0
800
type: always_sample
801
- name: string_attribute/1
802
type: string_attribute
803
string_attribute:
804
key: key
805
values:
806
- value1
807
- value2
808
extensions: {}
809
service:
810
pipelines:
811
traces/0:
812
exporters: ["loadbalancing"]
813
processors: []
814
receivers: ["jaeger", "push_receiver"]
815
traces/1:
816
exporters: ["otlp/0"]
817
processors: ["tail_sampling"]
818
receivers: ["otlp/lb"]
819
`,
820
},
821
{
822
name: "automatic logging : default",
823
cfg: `
824
receivers:
825
jaeger:
826
protocols:
827
grpc:
828
remote_write:
829
- endpoint: example.com:12345
830
automatic_logging:
831
spans: true
832
`,
833
expectedConfig: `
834
receivers:
835
push_receiver: {}
836
jaeger:
837
protocols:
838
grpc:
839
processors:
840
automatic_logging:
841
automatic_logging:
842
spans: true
843
exporters:
844
otlp/0:
845
endpoint: example.com:12345
846
compression: gzip
847
retry_on_failure:
848
max_elapsed_time: 60s
849
extensions: {}
850
service:
851
pipelines:
852
traces:
853
exporters: ["otlp/0"]
854
processors: ["automatic_logging"]
855
receivers: ["push_receiver", "jaeger"]
856
`,
857
},
858
{
859
name: "tls config",
860
cfg: `
861
receivers:
862
jaeger:
863
protocols:
864
grpc:
865
remote_write:
866
- insecure: false
867
tls_config:
868
ca_file: server.crt
869
cert_file: client.crt
870
key_file: client.key
871
endpoint: example.com:12345
872
`,
873
expectedConfig: `
874
receivers:
875
push_receiver: {}
876
jaeger:
877
protocols:
878
grpc:
879
exporters:
880
otlp/0:
881
endpoint: example.com:12345
882
tls:
883
insecure: false
884
ca_file: server.crt
885
cert_file: client.crt
886
key_file: client.key
887
compression: gzip
888
retry_on_failure:
889
max_elapsed_time: 60s
890
processors: {}
891
extensions: {}
892
service:
893
pipelines:
894
traces:
895
exporters: ["otlp/0"]
896
processors: []
897
receivers: ["push_receiver", "jaeger"]
898
`,
899
},
900
{
901
name: "otlp http & grpc exporters",
902
cfg: `
903
receivers:
904
jaeger:
905
protocols:
906
grpc:
907
remote_write:
908
- endpoint: example.com:12345
909
protocol: http
910
- endpoint: example.com:12345
911
protocol: grpc
912
`,
913
expectedConfig: `
914
receivers:
915
push_receiver: {}
916
jaeger:
917
protocols:
918
grpc:
919
exporters:
920
otlphttp/0:
921
endpoint: example.com:12345
922
compression: gzip
923
retry_on_failure:
924
max_elapsed_time: 60s
925
otlp/1:
926
endpoint: example.com:12345
927
compression: gzip
928
retry_on_failure:
929
max_elapsed_time: 60s
930
processors: {}
931
extensions: {}
932
service:
933
pipelines:
934
traces:
935
exporters: ["otlphttp/0", "otlp/1"]
936
processors: []
937
receivers: ["push_receiver", "jaeger"]
938
`,
939
},
940
{
941
name: "prom SD config",
942
cfg: `
943
receivers:
944
jaeger:
945
protocols:
946
grpc:
947
remote_write:
948
- endpoint: example.com:12345
949
protocol: grpc
950
scrape_configs:
951
- im_a_scrape_config
952
prom_sd_operation_type: update
953
`,
954
expectedConfig: `
955
receivers:
956
push_receiver: {}
957
jaeger:
958
protocols:
959
grpc:
960
exporters:
961
otlp/0:
962
endpoint: example.com:12345
963
compression: gzip
964
retry_on_failure:
965
max_elapsed_time: 60s
966
processors:
967
prom_sd_processor:
968
scrape_configs:
969
- im_a_scrape_config
970
operation_type: update
971
extensions: {}
972
service:
973
pipelines:
974
traces:
975
exporters: ["otlp/0"]
976
processors: ["prom_sd_processor"]
977
receivers: ["push_receiver", "jaeger"]
978
`,
979
},
980
{
981
name: "service graphs",
982
cfg: `
983
receivers:
984
jaeger:
985
protocols:
986
grpc:
987
remote_write:
988
- endpoint: example.com:12345
989
service_graphs:
990
enabled: true
991
`,
992
expectedConfig: `
993
receivers:
994
push_receiver: {}
995
jaeger:
996
protocols:
997
grpc:
998
exporters:
999
otlp/0:
1000
endpoint: example.com:12345
1001
compression: gzip
1002
retry_on_failure:
1003
max_elapsed_time: 60s
1004
processors:
1005
service_graphs:
1006
extensions: {}
1007
service:
1008
pipelines:
1009
traces:
1010
exporters: ["otlp/0"]
1011
processors: ["service_graphs"]
1012
receivers: ["push_receiver", "jaeger"]
1013
`,
1014
},
1015
{
1016
name: "jaeger exporter",
1017
cfg: `
1018
receivers:
1019
jaeger:
1020
protocols:
1021
grpc:
1022
remote_write:
1023
- insecure: true
1024
format: jaeger
1025
endpoint: example.com:12345
1026
`,
1027
expectedConfig: `
1028
receivers:
1029
push_receiver: {}
1030
jaeger:
1031
protocols:
1032
grpc:
1033
exporters:
1034
jaeger/0:
1035
endpoint: example.com:12345
1036
compression: gzip
1037
tls:
1038
insecure: true
1039
retry_on_failure:
1040
max_elapsed_time: 60s
1041
processors: {}
1042
extensions: {}
1043
service:
1044
pipelines:
1045
traces:
1046
exporters: ["jaeger/0"]
1047
processors: []
1048
receivers: ["push_receiver", "jaeger"]
1049
`,
1050
},
1051
{
1052
name: "jaeger exporter with basic auth",
1053
cfg: `
1054
receivers:
1055
jaeger:
1056
protocols:
1057
grpc:
1058
remote_write:
1059
- insecure: true
1060
format: jaeger
1061
protocol: grpc
1062
basic_auth:
1063
username: test
1064
password_file: ` + passwordFile.Name() + `
1065
endpoint: example.com:12345
1066
`,
1067
expectedConfig: `
1068
receivers:
1069
push_receiver: {}
1070
jaeger:
1071
protocols:
1072
grpc:
1073
exporters:
1074
jaeger/0:
1075
endpoint: example.com:12345
1076
compression: gzip
1077
tls:
1078
insecure: true
1079
headers:
1080
authorization: Basic dGVzdDpwYXNzd29yZF9pbl9maWxl
1081
retry_on_failure:
1082
max_elapsed_time: 60s
1083
processors: {}
1084
extensions: {}
1085
service:
1086
pipelines:
1087
traces:
1088
exporters: ["jaeger/0"]
1089
processors: []
1090
receivers: ["push_receiver", "jaeger"]
1091
`,
1092
},
1093
{
1094
name: "two exporters different format",
1095
cfg: `
1096
receivers:
1097
jaeger:
1098
protocols:
1099
grpc:
1100
remote_write:
1101
- insecure: true
1102
format: jaeger
1103
endpoint: example.com:12345
1104
- insecure: true
1105
format: otlp
1106
endpoint: something.com:123
1107
`,
1108
expectedConfig: `
1109
receivers:
1110
push_receiver: {}
1111
jaeger:
1112
protocols:
1113
grpc:
1114
exporters:
1115
jaeger/0:
1116
endpoint: example.com:12345
1117
compression: gzip
1118
tls:
1119
insecure: true
1120
retry_on_failure:
1121
max_elapsed_time: 60s
1122
otlp/1:
1123
endpoint: something.com:123
1124
compression: gzip
1125
tls:
1126
insecure: true
1127
retry_on_failure:
1128
max_elapsed_time: 60s
1129
processors: {}
1130
extensions: {}
1131
service:
1132
pipelines:
1133
traces:
1134
exporters: ["jaeger/0", "otlp/1"]
1135
processors: []
1136
receivers: ["push_receiver", "jaeger"]
1137
`,
1138
},
1139
{
1140
name: "one exporter with oauth2 and basic auth",
1141
cfg: `
1142
receivers:
1143
jaeger:
1144
protocols:
1145
grpc:
1146
remote_write:
1147
- endpoint: example.com:12345
1148
basic_auth:
1149
username: test
1150
password: blerg
1151
oauth2:
1152
client_id: somecclient
1153
client_secret: someclientsecret
1154
`,
1155
expectedError: true,
1156
},
1157
{
1158
name: "simple oauth2 config",
1159
cfg: `
1160
receivers:
1161
jaeger:
1162
protocols:
1163
grpc:
1164
remote_write:
1165
- endpoint: example.com:12345
1166
protocol: http
1167
oauth2:
1168
client_id: someclientid
1169
client_secret: someclientsecret
1170
token_url: https://example.com/oauth2/default/v1/token
1171
scopes: ["api.metrics"]
1172
timeout: 2s
1173
`,
1174
expectedConfig: `
1175
receivers:
1176
push_receiver: {}
1177
jaeger:
1178
protocols:
1179
grpc:
1180
extensions:
1181
oauth2client/otlphttp0:
1182
client_id: someclientid
1183
client_secret: someclientsecret
1184
token_url: https://example.com/oauth2/default/v1/token
1185
scopes: ["api.metrics"]
1186
timeout: 2s
1187
exporters:
1188
otlphttp/0:
1189
endpoint: example.com:12345
1190
compression: gzip
1191
retry_on_failure:
1192
max_elapsed_time: 60s
1193
auth:
1194
authenticator: oauth2client/otlphttp0
1195
processors: {}
1196
service:
1197
extensions: ["oauth2client/otlphttp0"]
1198
pipelines:
1199
traces:
1200
exporters: ["otlphttp/0"]
1201
processors: []
1202
receivers: ["push_receiver", "jaeger"]
1203
`,
1204
},
1205
{
1206
name: "oauth2 TLS",
1207
cfg: `
1208
receivers:
1209
jaeger:
1210
protocols:
1211
grpc:
1212
remote_write:
1213
- endpoint: example.com:12345
1214
protocol: http
1215
oauth2:
1216
client_id: someclientid
1217
client_secret: someclientsecret
1218
token_url: https://example.com/oauth2/default/v1/token
1219
scopes: ["api.metrics"]
1220
timeout: 2s
1221
tls:
1222
insecure: true
1223
ca_file: /var/lib/mycert.pem
1224
cert_file: certfile
1225
key_file: keyfile
1226
`,
1227
expectedConfig: `
1228
receivers:
1229
push_receiver: {}
1230
jaeger:
1231
protocols:
1232
grpc:
1233
extensions:
1234
oauth2client/otlphttp0:
1235
client_id: someclientid
1236
client_secret: someclientsecret
1237
token_url: https://example.com/oauth2/default/v1/token
1238
scopes: ["api.metrics"]
1239
timeout: 2s
1240
tls:
1241
insecure: true
1242
ca_file: /var/lib/mycert.pem
1243
cert_file: certfile
1244
key_file: keyfile
1245
exporters:
1246
otlphttp/0:
1247
endpoint: example.com:12345
1248
compression: gzip
1249
retry_on_failure:
1250
max_elapsed_time: 60s
1251
auth:
1252
authenticator: oauth2client/otlphttp0
1253
processors: {}
1254
service:
1255
extensions: ["oauth2client/otlphttp0"]
1256
pipelines:
1257
traces:
1258
exporters: ["otlphttp/0"]
1259
processors: []
1260
receivers: ["push_receiver", "jaeger"]
1261
`,
1262
},
1263
{
1264
name: "2 exporters different auth",
1265
cfg: `
1266
receivers:
1267
jaeger:
1268
protocols:
1269
grpc:
1270
remote_write:
1271
- endpoint: example.com:12345
1272
protocol: http
1273
oauth2:
1274
client_id: someclientid
1275
client_secret: someclientsecret
1276
token_url: https://example.com/oauth2/default/v1/token
1277
scopes: ["api.metrics"]
1278
timeout: 2s
1279
- endpoint: example.com:12345
1280
protocol: grpc
1281
oauth2:
1282
client_id: anotherclientid
1283
client_secret: anotherclientsecret
1284
token_url: https://example.com/oauth2/default/v1/token
1285
scopes: ["api.metrics"]
1286
timeout: 2s
1287
`,
1288
expectedConfig: `
1289
receivers:
1290
push_receiver: {}
1291
jaeger:
1292
protocols:
1293
grpc:
1294
extensions:
1295
oauth2client/otlphttp0:
1296
client_id: someclientid
1297
client_secret: someclientsecret
1298
token_url: https://example.com/oauth2/default/v1/token
1299
scopes: ["api.metrics"]
1300
timeout: 2s
1301
oauth2client/otlp1:
1302
client_id: anotherclientid
1303
client_secret: anotherclientsecret
1304
token_url: https://example.com/oauth2/default/v1/token
1305
scopes: ["api.metrics"]
1306
timeout: 2s
1307
exporters:
1308
otlphttp/0:
1309
endpoint: example.com:12345
1310
compression: gzip
1311
retry_on_failure:
1312
max_elapsed_time: 60s
1313
auth:
1314
authenticator: oauth2client/otlphttp0
1315
otlp/1:
1316
endpoint: example.com:12345
1317
compression: gzip
1318
retry_on_failure:
1319
max_elapsed_time: 60s
1320
auth:
1321
authenticator: oauth2client/otlp1
1322
processors: {}
1323
service:
1324
extensions: ["oauth2client/otlphttp0", "oauth2client/otlp1"]
1325
pipelines:
1326
traces:
1327
exporters: ["otlphttp/0", "otlp/1"]
1328
processors: []
1329
receivers: ["push_receiver", "jaeger"]
1330
`,
1331
},
1332
{
1333
name: "exporter with insecure oauth",
1334
cfg: `
1335
receivers:
1336
jaeger:
1337
protocols:
1338
grpc:
1339
remote_write:
1340
- endpoint: http://example.com:12345
1341
insecure: true
1342
protocol: http
1343
oauth2:
1344
client_id: someclientid
1345
client_secret: someclientsecret
1346
token_url: https://example.com/oauth2/default/v1/token
1347
scopes: ["api.metrics"]
1348
timeout: 2s
1349
tls:
1350
insecure: true
1351
`,
1352
expectedConfig: `
1353
receivers:
1354
push_receiver: {}
1355
jaeger:
1356
protocols:
1357
grpc:
1358
extensions:
1359
oauth2client/otlphttp0:
1360
client_id: someclientid
1361
client_secret: someclientsecret
1362
token_url: https://example.com/oauth2/default/v1/token
1363
scopes: ["api.metrics"]
1364
timeout: 2s
1365
tls:
1366
insecure: true
1367
exporters:
1368
otlphttp/0:
1369
endpoint: http://example.com:12345
1370
tls:
1371
insecure: true
1372
compression: gzip
1373
retry_on_failure:
1374
max_elapsed_time: 60s
1375
auth:
1376
authenticator: oauth2client/otlphttp0
1377
processors: {}
1378
service:
1379
extensions: ["oauth2client/otlphttp0"]
1380
pipelines:
1381
traces:
1382
exporters: ["otlphttp/0"]
1383
processors: []
1384
receivers: ["push_receiver", "jaeger"]
1385
`,
1386
},
1387
{
1388
name: "OTLP receivers get include_metadata set to true by default",
1389
cfg: `
1390
receivers:
1391
otlp/0:
1392
protocols:
1393
grpc:
1394
http:
1395
endpoint: localhost:4318
1396
otlp/1:
1397
protocols:
1398
grpc:
1399
include_metadata: false
1400
http:
1401
include_metadata: false
1402
endpoint: localhost:4318
1403
remote_write:
1404
- endpoint: example.com:12345
1405
`,
1406
expectedConfig: `
1407
receivers:
1408
push_receiver:
1409
otlp/0:
1410
protocols:
1411
grpc:
1412
include_metadata: true
1413
http:
1414
include_metadata: true
1415
endpoint: localhost:4318
1416
otlp/1:
1417
protocols:
1418
grpc:
1419
include_metadata: false
1420
http:
1421
include_metadata: false
1422
endpoint: localhost:4318
1423
exporters:
1424
otlp/0:
1425
endpoint: example.com:12345
1426
compression: gzip
1427
retry_on_failure:
1428
max_elapsed_time: 60s
1429
processors: {}
1430
extensions: {}
1431
service:
1432
pipelines:
1433
traces:
1434
exporters: ["otlp/0"]
1435
processors: []
1436
receivers: ["push_receiver", "otlp/0", "otlp/1"]
1437
`,
1438
},
1439
}
1440
1441
for _, tc := range tt {
1442
t.Run(tc.name, func(t *testing.T) {
1443
var cfg InstanceConfig
1444
err := yaml.Unmarshal([]byte(tc.cfg), &cfg)
1445
require.NoError(t, err)
1446
// check error
1447
actualConfig, err := cfg.otelConfig()
1448
if tc.expectedError {
1449
assert.Error(t, err)
1450
return
1451
}
1452
require.NoError(t, err)
1453
1454
// convert actual config to otel config
1455
otelMapStructure := map[string]interface{}{}
1456
err = yaml.Unmarshal([]byte(tc.expectedConfig), otelMapStructure)
1457
require.NoError(t, err)
1458
1459
factories, err := tracingFactories()
1460
require.NoError(t, err)
1461
1462
configMap := confmap.NewFromStringMap(otelMapStructure)
1463
expectedConfig, err := configunmarshaler.Unmarshal(configMap, factories)
1464
require.NoError(t, err)
1465
1466
// Exporters/Receivers/Processors in the config's service.Pipelines, as well as
1467
// service.Extensions have to be in the same order for them to be asserted as equal.
1468
sortService(actualConfig)
1469
sortService(expectedConfig)
1470
1471
assert.Equal(t, expectedConfig, actualConfig)
1472
})
1473
}
1474
}
1475
1476
func TestProcessorOrder(t *testing.T) {
1477
// tests!
1478
tt := []struct {
1479
name string
1480
cfg string
1481
expectedProcessors map[string][]config.ComponentID
1482
}{
1483
{
1484
name: "no processors",
1485
cfg: `
1486
receivers:
1487
jaeger:
1488
protocols:
1489
grpc:
1490
remote_write:
1491
- endpoint: example.com:12345
1492
headers:
1493
x-some-header: Some value!
1494
`,
1495
expectedProcessors: map[string][]config.ComponentID{
1496
"traces": nil,
1497
},
1498
},
1499
{
1500
name: "all processors w/o load balancing",
1501
cfg: `
1502
receivers:
1503
jaeger:
1504
protocols:
1505
grpc:
1506
remote_write:
1507
- endpoint: example.com:12345
1508
headers:
1509
x-some-header: Some value!
1510
attributes:
1511
actions:
1512
- key: montgomery
1513
value: forever
1514
action: update
1515
spanmetrics:
1516
latency_histogram_buckets: [2ms, 6ms, 10ms, 100ms, 250ms]
1517
dimensions:
1518
- name: http.method
1519
default: GET
1520
- name: http.status_code
1521
metrics_instance: traces
1522
automatic_logging:
1523
spans: true
1524
batch:
1525
timeout: 5s
1526
send_batch_size: 100
1527
tail_sampling:
1528
policies:
1529
- type: always_sample
1530
- type: string_attribute
1531
string_attribute:
1532
key: key
1533
values:
1534
- value1
1535
- value2
1536
service_graphs:
1537
enabled: true
1538
`,
1539
expectedProcessors: map[string][]config.ComponentID{
1540
"traces": {
1541
config.NewComponentID("attributes"),
1542
config.NewComponentID("spanmetrics"),
1543
config.NewComponentID("service_graphs"),
1544
config.NewComponentID("tail_sampling"),
1545
config.NewComponentID("automatic_logging"),
1546
config.NewComponentID("batch"),
1547
},
1548
spanMetricsPipelineName: nil,
1549
},
1550
},
1551
{
1552
name: "all processors with load balancing",
1553
cfg: `
1554
receivers:
1555
jaeger:
1556
protocols:
1557
grpc:
1558
remote_write:
1559
- endpoint: example.com:12345
1560
headers:
1561
x-some-header: Some value!
1562
attributes:
1563
actions:
1564
- key: montgomery
1565
value: forever
1566
action: update
1567
spanmetrics:
1568
latency_histogram_buckets: [2ms, 6ms, 10ms, 100ms, 250ms]
1569
dimensions:
1570
- name: http.method
1571
default: GET
1572
- name: http.status_code
1573
metrics_instance: traces
1574
automatic_logging:
1575
spans: true
1576
batch:
1577
timeout: 5s
1578
send_batch_size: 100
1579
tail_sampling:
1580
policies:
1581
- type: always_sample
1582
- type: string_attribute
1583
string_attribute:
1584
key: key
1585
values:
1586
- value1
1587
- value2
1588
load_balancing:
1589
exporter:
1590
tls:
1591
insecure: true
1592
resolver:
1593
dns:
1594
hostname: agent
1595
port: 4318
1596
service_graphs:
1597
enabled: true
1598
`,
1599
expectedProcessors: map[string][]config.ComponentID{
1600
"traces/0": {
1601
config.NewComponentID("attributes"),
1602
config.NewComponentID("spanmetrics"),
1603
},
1604
"traces/1": {
1605
config.NewComponentID("service_graphs"),
1606
config.NewComponentID("tail_sampling"),
1607
config.NewComponentID("automatic_logging"),
1608
config.NewComponentID("batch"),
1609
},
1610
spanMetricsPipelineName: nil,
1611
},
1612
},
1613
{
1614
name: "load balancing without tail sampling",
1615
cfg: `
1616
receivers:
1617
jaeger:
1618
protocols:
1619
grpc:
1620
remote_write:
1621
- endpoint: example.com:12345
1622
headers:
1623
x-some-header: Some value!
1624
attributes:
1625
actions:
1626
- key: montgomery
1627
value: forever
1628
action: update
1629
spanmetrics:
1630
latency_histogram_buckets: [2ms, 6ms, 10ms, 100ms, 250ms]
1631
dimensions:
1632
- name: http.method
1633
default: GET
1634
- name: http.status_code
1635
metrics_instance: traces
1636
automatic_logging:
1637
spans: true
1638
batch:
1639
timeout: 5s
1640
send_batch_size: 100
1641
load_balancing:
1642
exporter:
1643
tls:
1644
insecure: true
1645
resolver:
1646
dns:
1647
hostname: agent
1648
port: 4318
1649
`,
1650
expectedProcessors: map[string][]config.ComponentID{
1651
"traces/0": {
1652
config.NewComponentID("attributes"),
1653
config.NewComponentID("spanmetrics"),
1654
},
1655
"traces/1": {
1656
config.NewComponentID("automatic_logging"),
1657
config.NewComponentID("batch"),
1658
},
1659
spanMetricsPipelineName: nil,
1660
},
1661
},
1662
}
1663
1664
for _, tc := range tt {
1665
t.Run(tc.name, func(t *testing.T) {
1666
var cfg InstanceConfig
1667
err := yaml.Unmarshal([]byte(tc.cfg), &cfg)
1668
require.NoError(t, err)
1669
1670
// check error
1671
actualConfig, err := cfg.otelConfig()
1672
require.NoError(t, err)
1673
1674
require.Equal(t, len(tc.expectedProcessors), len(actualConfig.Pipelines))
1675
for k := range tc.expectedProcessors {
1676
if len(tc.expectedProcessors[k]) > 0 {
1677
componentID, err := config.NewComponentIDFromString(k)
1678
require.NoError(t, err)
1679
1680
assert.Equal(t, tc.expectedProcessors[k], actualConfig.Pipelines[componentID].Processors)
1681
}
1682
}
1683
})
1684
}
1685
}
1686
1687
func TestOrderProcessors(t *testing.T) {
1688
tests := []struct {
1689
processors []string
1690
splitPipelines bool
1691
expected [][]string
1692
}{
1693
{
1694
expected: [][]string{
1695
nil,
1696
},
1697
},
1698
{
1699
processors: []string{
1700
"tail_sampling",
1701
},
1702
expected: [][]string{
1703
{"tail_sampling"},
1704
},
1705
},
1706
{
1707
processors: []string{
1708
"batch",
1709
"tail_sampling",
1710
"automatic_logging",
1711
},
1712
expected: [][]string{
1713
{
1714
"tail_sampling",
1715
"automatic_logging",
1716
"batch",
1717
},
1718
},
1719
},
1720
{
1721
processors: []string{
1722
"spanmetrics",
1723
"batch",
1724
"tail_sampling",
1725
"attributes",
1726
"automatic_logging",
1727
},
1728
expected: [][]string{
1729
{
1730
"attributes",
1731
"spanmetrics",
1732
"tail_sampling",
1733
"automatic_logging",
1734
"batch",
1735
},
1736
},
1737
},
1738
{
1739
splitPipelines: true,
1740
expected: [][]string{
1741
nil,
1742
nil,
1743
},
1744
},
1745
{
1746
processors: []string{
1747
"spanmetrics",
1748
"batch",
1749
"tail_sampling",
1750
"attributes",
1751
"automatic_logging",
1752
},
1753
splitPipelines: true,
1754
expected: [][]string{
1755
{
1756
"attributes",
1757
"spanmetrics",
1758
},
1759
{
1760
"tail_sampling",
1761
"automatic_logging",
1762
"batch",
1763
},
1764
},
1765
},
1766
{
1767
processors: []string{
1768
"batch",
1769
"tail_sampling",
1770
"automatic_logging",
1771
},
1772
splitPipelines: true,
1773
expected: [][]string{
1774
{},
1775
{
1776
"tail_sampling",
1777
"automatic_logging",
1778
"batch",
1779
},
1780
},
1781
},
1782
{
1783
processors: []string{
1784
"spanmetrics",
1785
"attributes",
1786
},
1787
splitPipelines: true,
1788
expected: [][]string{
1789
{
1790
"attributes",
1791
"spanmetrics",
1792
},
1793
{},
1794
},
1795
},
1796
}
1797
1798
for _, tc := range tests {
1799
actual := orderProcessors(tc.processors, tc.splitPipelines)
1800
assert.Equal(t, tc.expected, actual)
1801
}
1802
}
1803
1804
func TestScrubbedReceivers(t *testing.T) {
1805
test := `
1806
receivers:
1807
jaeger:
1808
protocols:
1809
grpc:`
1810
var cfg InstanceConfig
1811
err := yaml.Unmarshal([]byte(test), &cfg)
1812
assert.Nil(t, err)
1813
data, err := yaml.Marshal(cfg)
1814
assert.Nil(t, err)
1815
assert.True(t, strings.Contains(string(data), "<secret>"))
1816
}
1817
1818
func TestCreatingPushReceiver(t *testing.T) {
1819
test := `
1820
receivers:
1821
jaeger:
1822
protocols:
1823
grpc:`
1824
cfg := InstanceConfig{}
1825
err := yaml.Unmarshal([]byte(test), &cfg)
1826
assert.Nil(t, err)
1827
otel, err := cfg.otelConfig()
1828
assert.Nil(t, err)
1829
assert.Contains(t, otel.Service.Pipelines[config.NewComponentID("traces")].Receivers, config.NewComponentID(pushreceiver.TypeStr))
1830
}
1831
1832
func TestUnmarshalYAMLEmptyOTLP(t *testing.T) {
1833
test := `
1834
receivers:
1835
otlp:`
1836
cfg := InstanceConfig{}
1837
err := yaml.Unmarshal([]byte(test), &cfg)
1838
assert.NotNil(t, err)
1839
require.Contains(t, err.Error(), "failed to parse OTLP receiver config: otlp")
1840
}
1841
1842
func TestUnmarshalYAMLEmptyOTLPProtocols(t *testing.T) {
1843
test := `
1844
receivers:
1845
otlp:
1846
protocols:`
1847
cfg := InstanceConfig{}
1848
err := yaml.Unmarshal([]byte(test), &cfg)
1849
assert.NotNil(t, err)
1850
require.Contains(t, err.Error(), "otlp receiver requires a \"protocols\" field which must be a YAML map: otlp")
1851
}
1852
1853
// sortService is a helper function to lexicographically sort all
1854
// the possibly unsorted elements of a given cfg.Service
1855
func sortService(cfg *config.Config) {
1856
sort.Slice(cfg.Service.Extensions, func(i, j int) bool { return cfg.Service.Extensions[i].String() > cfg.Service.Extensions[j].String() })
1857
1858
for _, pipeline := range cfg.Pipelines {
1859
sort.Slice(pipeline.Exporters, func(i, j int) bool { return pipeline.Exporters[i].String() > pipeline.Exporters[j].String() })
1860
sort.Slice(pipeline.Receivers, func(i, j int) bool { return pipeline.Receivers[i].String() > pipeline.Receivers[j].String() })
1861
sort.Slice(pipeline.Processors, func(i, j int) bool { return pipeline.Processors[i].String() > pipeline.Processors[j].String() })
1862
}
1863
}
1864
1865