@@ -27,7 +27,7 @@ func TestDrain_TrainExtractsPatterns(t *testing.T) {
27
27
format string
28
28
}{
29
29
{
30
- drain : New (DefaultConfig (), nil ),
30
+ drain : New (DefaultConfig (), "" , nil ),
31
31
inputFile : `testdata/agent-logfmt.txt` ,
32
32
format : FormatLogfmt ,
33
33
patterns : []string {
@@ -56,7 +56,7 @@ func TestDrain_TrainExtractsPatterns(t *testing.T) {
56
56
},
57
57
},
58
58
{
59
- drain : New (DefaultConfig (), nil ),
59
+ drain : New (DefaultConfig (), "" , nil ),
60
60
inputFile : `testdata/ingester-logfmt.txt` ,
61
61
format : FormatLogfmt ,
62
62
patterns : []string {
@@ -66,7 +66,7 @@ func TestDrain_TrainExtractsPatterns(t *testing.T) {
66
66
},
67
67
},
68
68
{
69
- drain : New (DefaultConfig (), nil ),
69
+ drain : New (DefaultConfig (), "" , nil ),
70
70
inputFile : `testdata/drone-json.txt` ,
71
71
format : FormatJSON ,
72
72
patterns : []string {
@@ -79,7 +79,7 @@ func TestDrain_TrainExtractsPatterns(t *testing.T) {
79
79
},
80
80
},
81
81
{
82
- drain : New (DefaultConfig (), nil ),
82
+ drain : New (DefaultConfig (), "" , nil ),
83
83
inputFile : "testdata/distributor-logfmt.txt" ,
84
84
format : FormatLogfmt ,
85
85
patterns : []string {
@@ -91,7 +91,7 @@ func TestDrain_TrainExtractsPatterns(t *testing.T) {
91
91
},
92
92
},
93
93
{
94
- drain : New (DefaultConfig (), nil ),
94
+ drain : New (DefaultConfig (), "" , nil ),
95
95
inputFile : "testdata/journald.txt" ,
96
96
format : FormatUnknown ,
97
97
patterns : []string {
@@ -211,7 +211,7 @@ func TestDrain_TrainExtractsPatterns(t *testing.T) {
211
211
},
212
212
},
213
213
{
214
- drain : New (DefaultConfig (), nil ),
214
+ drain : New (DefaultConfig (), "" , nil ),
215
215
inputFile : "testdata/kafka.txt" ,
216
216
format : FormatUnknown ,
217
217
patterns : []string {
@@ -232,7 +232,7 @@ func TestDrain_TrainExtractsPatterns(t *testing.T) {
232
232
},
233
233
},
234
234
{
235
- drain : New (DefaultConfig (), nil ),
235
+ drain : New (DefaultConfig (), "" , nil ),
236
236
inputFile : "testdata/kubernetes.txt" ,
237
237
format : FormatUnknown ,
238
238
patterns : []string {
@@ -273,15 +273,15 @@ func TestDrain_TrainExtractsPatterns(t *testing.T) {
273
273
},
274
274
},
275
275
{
276
- drain : New (DefaultConfig (), nil ),
276
+ drain : New (DefaultConfig (), "" , nil ),
277
277
inputFile : "testdata/vault.txt" ,
278
278
format : FormatUnknown ,
279
279
patterns : []string {
280
280
`<_> [INFO] expiration: revoked lease: lease_id=<_>` ,
281
281
},
282
282
},
283
283
{
284
- drain : New (DefaultConfig (), nil ),
284
+ drain : New (DefaultConfig (), "" , nil ),
285
285
inputFile : "testdata/calico.txt" ,
286
286
format : FormatUnknown ,
287
287
patterns : []string {
@@ -374,7 +374,7 @@ func TestDrain_TrainExtractsPatterns(t *testing.T) {
374
374
},
375
375
},
376
376
{
377
- drain : New (DefaultConfig (), nil ),
377
+ drain : New (DefaultConfig (), "" , nil ),
378
378
inputFile : "testdata/grafana-ruler.txt" ,
379
379
format : FormatLogfmt ,
380
380
patterns : []string {
@@ -426,6 +426,7 @@ func TestDrain_TrainExtractsPatterns(t *testing.T) {
426
426
}
427
427
428
428
for _ , tt := range tests {
429
+ tt := tt
429
430
t .Run (tt .inputFile , func (t * testing.T ) {
430
431
file , err := os .Open (tt .inputFile )
431
432
require .NoError (t , err )
@@ -461,53 +462,6 @@ func TestDrain_TrainExtractsPatterns(t *testing.T) {
461
462
}
462
463
}
463
464
464
- func TestDrain_TrainGeneratesMatchablePatterns (t * testing.T ) {
465
- t .Parallel ()
466
- tests := []struct {
467
- name string
468
- drain * Drain
469
- inputLines []string
470
- }{
471
- {
472
- name : "should match each line against a pattern" ,
473
- drain : New (DefaultConfig (), nil ),
474
- inputLines : []string {
475
- "test test test test" ,
476
- "test test test test" ,
477
- "test test test test" ,
478
- "test test test test" ,
479
- },
480
- },
481
- {
482
- name : "should also match newlines" ,
483
- drain : New (DefaultConfig (), nil ),
484
- inputLines : []string {
485
- `test test test test
486
- ` ,
487
- `test test test test
488
- ` ,
489
- `test test test test
490
- ` ,
491
- `test test test test
492
- ` ,
493
- },
494
- },
495
- }
496
- for _ , tt := range tests {
497
- tt := tt
498
- t .Run (tt .name , func (t * testing.T ) {
499
- for _ , line := range tt .inputLines {
500
- tt .drain .Train (line , 0 )
501
- }
502
-
503
- for _ , line := range tt .inputLines {
504
- match := tt .drain .Match (line )
505
- require .NotNil (t , match , `Line should match a cluster` )
506
- }
507
- })
508
- }
509
- }
510
-
511
465
func TestDrain_TrainGeneratesPatternsMatchableByLokiPatternFilter (t * testing.T ) {
512
466
t .Parallel ()
513
467
tests := []struct {
@@ -517,7 +471,7 @@ func TestDrain_TrainGeneratesPatternsMatchableByLokiPatternFilter(t *testing.T)
517
471
}{
518
472
{
519
473
name : "should extract patterns that all lines match" ,
520
- drain : New (DefaultConfig (), nil ),
474
+ drain : New (DefaultConfig (), "" , nil ),
521
475
inputLines : []string {
522
476
"test 1 test test" ,
523
477
"test 2 test test" ,
@@ -527,7 +481,7 @@ func TestDrain_TrainGeneratesPatternsMatchableByLokiPatternFilter(t *testing.T)
527
481
},
528
482
{
529
483
name : "should extract patterns that match if line ends with newlines" ,
530
- drain : New (DefaultConfig (), nil ),
484
+ drain : New (DefaultConfig (), "" , nil ),
531
485
inputLines : []string {
532
486
`test 1 test test
533
487
` ,
@@ -541,7 +495,7 @@ func TestDrain_TrainGeneratesPatternsMatchableByLokiPatternFilter(t *testing.T)
541
495
},
542
496
{
543
497
name : "should extract patterns that match if line ends with empty space" ,
544
- drain : New (DefaultConfig (), nil ),
498
+ drain : New (DefaultConfig (), "" , nil ),
545
499
inputLines : []string {
546
500
`test 1 test test ` ,
547
501
`test 2 test test ` ,
@@ -551,7 +505,7 @@ func TestDrain_TrainGeneratesPatternsMatchableByLokiPatternFilter(t *testing.T)
551
505
},
552
506
{
553
507
name : "should extract patterns that match if line starts with empty space" ,
554
- drain : New (DefaultConfig (), nil ),
508
+ drain : New (DefaultConfig (), "" , nil ),
555
509
inputLines : []string {
556
510
` test 1 test test` ,
557
511
` test 2 test test` ,
@@ -561,7 +515,7 @@ func TestDrain_TrainGeneratesPatternsMatchableByLokiPatternFilter(t *testing.T)
561
515
},
562
516
{
563
517
name : "Scheduler patterns are matchable" ,
564
- drain : New (DefaultConfig (), nil ),
518
+ drain : New (DefaultConfig (), "" , nil ),
565
519
inputLines : []string {
566
520
`ts=2024-05-30T12:50:36.648377186Z caller=scheduler_processor.go:143 level=warn msg="error contacting scheduler" err="rpc error: code = Unavailable desc = connection error: desc = \"error reading server preface: EOF\"" addr=10.0.151.101:9095` ,
567
521
`ts=2024-05-30T12:50:36.350575929Z caller=scheduler_processor.go:143 level=warn msg="error contacting scheduler" err="rpc error: code = Unavailable desc = connection error: desc = \"error reading server preface: EOF\"" addr=10.0.151.101:9095` ,
@@ -659,7 +613,7 @@ func TestDrain_PruneTreeClearsOldBranches(t *testing.T) {
659
613
}{
660
614
{
661
615
name : "should prune old branches" ,
662
- drain : New (DefaultConfig (), nil ),
616
+ drain : New (DefaultConfig (), "" , nil ),
663
617
inputLines : []string {
664
618
"test test test A" ,
665
619
"test test test B" ,
0 commit comments