@@ -34,6 +34,7 @@ func checkParameterAbsent(param string, next http.Handler) http.Handler {
34
34
prometheusAPIError (w , fmt .Sprintf ("unexpected error: %v" , err ), http .StatusInternalServerError )
35
35
return
36
36
}
37
+
37
38
if len (kvs [param ]) != 0 {
38
39
prometheusAPIError (w , fmt .Sprintf ("unexpected parameter %q" , param ), http .StatusInternalServerError )
39
40
return
@@ -264,6 +265,7 @@ func TestMatch(t *testing.T) {
264
265
for _ , tc := range []struct {
265
266
labelv []string
266
267
matches []string
268
+ opts []Option
267
269
268
270
expCode int
269
271
expMatch []string
@@ -277,15 +279,15 @@ func TestMatch(t *testing.T) {
277
279
// No "match" parameter.
278
280
labelv : []string {"default" },
279
281
expCode : http .StatusOK ,
280
- expMatch : []string {`{namespace=~ "default"}` },
282
+ expMatch : []string {`{namespace="default"}` },
281
283
expBody : okResponse ,
282
284
},
283
285
{
284
286
// Single "match" parameters.
285
287
labelv : []string {"default" },
286
288
matches : []string {`{job="prometheus",__name__=~"job:.*"}` },
287
289
expCode : http .StatusOK ,
288
- expMatch : []string {`{job="prometheus",__name__=~"job:.*",namespace=~ "default"}` },
290
+ expMatch : []string {`{job="prometheus",__name__=~"job:.*",namespace="default"}` },
289
291
expBody : okResponse ,
290
292
},
291
293
{
@@ -309,15 +311,15 @@ func TestMatch(t *testing.T) {
309
311
labelv : []string {"default" },
310
312
matches : []string {`{job="prometheus",__name__=~"job:.*",namespace="default"}` },
311
313
expCode : http .StatusOK ,
312
- expMatch : []string {`{job="prometheus",__name__=~"job:.*",namespace="default",namespace=~ "default"}` },
314
+ expMatch : []string {`{job="prometheus",__name__=~"job:.*",namespace="default",namespace="default"}` },
313
315
expBody : okResponse ,
314
316
},
315
317
{
316
318
// Many "match" parameters.
317
319
labelv : []string {"default" },
318
320
matches : []string {`{job="prometheus"}` , `{__name__=~"job:.*"}` },
319
321
expCode : http .StatusOK ,
320
- expMatch : []string {`{job="prometheus",namespace=~ "default"}` , `{__name__=~"job:.*",namespace=~ "default"}` },
322
+ expMatch : []string {`{job="prometheus",namespace="default"}` , `{__name__=~"job:.*",namespace="default"}` },
321
323
expBody : okResponse ,
322
324
},
323
325
{
@@ -336,6 +338,33 @@ func TestMatch(t *testing.T) {
336
338
},
337
339
expBody : okResponse ,
338
340
},
341
+ {
342
+ // Many "match" parameters with a single regex value.
343
+ labelv : []string {".+-monitoring" },
344
+ matches : []string {
345
+ `{job="prometheus"}` ,
346
+ `{__name__=~"job:.*"}` ,
347
+ `{namespace="something"}` ,
348
+ },
349
+ opts : []Option {WithRegexMatch ()},
350
+
351
+ expCode : http .StatusOK ,
352
+ expMatch : []string {
353
+ `{job="prometheus",namespace=~".+-monitoring"}` ,
354
+ `{__name__=~"job:.*",namespace=~".+-monitoring"}` ,
355
+ `{namespace="something",namespace=~".+-monitoring"}` ,
356
+ },
357
+ expBody : okResponse ,
358
+ },
359
+ {
360
+ // A single "match" parameter with multiple regex values.
361
+ labelv : []string {"default" , "something" },
362
+ matches : []string {
363
+ `{job="prometheus"}` ,
364
+ },
365
+ opts : []Option {WithRegexMatch ()},
366
+ expCode : http .StatusBadRequest ,
367
+ },
339
368
} {
340
369
for _ , u := range []string {
341
370
"http://prometheus.example.com/federate" ,
@@ -351,7 +380,12 @@ func TestMatch(t *testing.T) {
351
380
)
352
381
defer m .Close ()
353
382
354
- r , err := NewRoutes (m .url , proxyLabel , HTTPFormEnforcer {ParameterName : proxyLabel }, WithEnabledLabelsAPI ())
383
+ r , err := NewRoutes (
384
+ m .url ,
385
+ proxyLabel ,
386
+ HTTPFormEnforcer {ParameterName : proxyLabel },
387
+ append ([]Option {WithEnabledLabelsAPI ()}, tc .opts ... )... ,
388
+ )
355
389
if err != nil {
356
390
t .Fatalf ("unexpected error: %v" , err )
357
391
}
@@ -382,6 +416,7 @@ func TestMatch(t *testing.T) {
382
416
t .Logf ("%s" , string (body ))
383
417
t .FailNow ()
384
418
}
419
+
385
420
if resp .StatusCode != http .StatusOK {
386
421
return
387
422
}
@@ -411,15 +446,15 @@ func TestMatchWithPost(t *testing.T) {
411
446
// No "match" parameter.
412
447
labelv : []string {"default" },
413
448
expCode : http .StatusOK ,
414
- expMatch : []string {`{namespace=~ "default"}` },
449
+ expMatch : []string {`{namespace="default"}` },
415
450
expBody : okResponse ,
416
451
},
417
452
{
418
453
// Single "match" parameters.
419
454
labelv : []string {"default" },
420
455
matches : []string {`{job="prometheus",__name__=~"job:.*"}` },
421
456
expCode : http .StatusOK ,
422
- expMatch : []string {`{job="prometheus",__name__=~"job:.*",namespace=~ "default"}` },
457
+ expMatch : []string {`{job="prometheus",__name__=~"job:.*",namespace="default"}` },
423
458
expBody : okResponse ,
424
459
},
425
460
{
@@ -443,15 +478,15 @@ func TestMatchWithPost(t *testing.T) {
443
478
labelv : []string {"default" },
444
479
matches : []string {`{job="prometheus",__name__=~"job:.*",namespace="default"}` },
445
480
expCode : http .StatusOK ,
446
- expMatch : []string {`{job="prometheus",__name__=~"job:.*",namespace="default",namespace=~ "default"}` },
481
+ expMatch : []string {`{job="prometheus",__name__=~"job:.*",namespace="default",namespace="default"}` },
447
482
expBody : okResponse ,
448
483
},
449
484
{
450
485
// Many "match" parameters.
451
486
labelv : []string {"default" },
452
487
matches : []string {`{job="prometheus"}` , `{__name__=~"job:.*"}` },
453
488
expCode : http .StatusOK ,
454
- expMatch : []string {`{job="prometheus",namespace=~ "default"}` , `{__name__=~"job:.*",namespace=~ "default"}` },
489
+ expMatch : []string {`{job="prometheus",namespace="default"}` , `{__name__=~"job:.*",namespace="default"}` },
455
490
expBody : okResponse ,
456
491
},
457
492
{
@@ -546,14 +581,14 @@ func TestSeries(t *testing.T) {
546
581
{
547
582
name : `No "match[]" parameter returns 200 with empty body` ,
548
583
labelv : []string {"default" },
549
- expMatch : []string {`{namespace=~ "default"}` },
584
+ expMatch : []string {`{namespace="default"}` },
550
585
expResponse : okResponse ,
551
586
expCode : http .StatusOK ,
552
587
},
553
588
{
554
589
name : `No "match[]" parameter returns 200 with empty body for POSTs` ,
555
590
labelv : []string {"default" },
556
- expMatch : []string {`{namespace=~ "default"}` },
591
+ expMatch : []string {`{namespace="default"}` },
557
592
expResponse : okResponse ,
558
593
expCode : http .StatusOK ,
559
594
},
@@ -562,7 +597,7 @@ func TestSeries(t *testing.T) {
562
597
labelv : []string {"default" },
563
598
promQuery : "up" ,
564
599
expCode : http .StatusOK ,
565
- expMatch : []string {`{__name__="up",namespace=~ "default"}` },
600
+ expMatch : []string {`{__name__="up",namespace="default"}` },
566
601
expResponse : okResponse ,
567
602
},
568
603
{
@@ -586,7 +621,7 @@ func TestSeries(t *testing.T) {
586
621
labelv : []string {"default" },
587
622
promQuery : `up{instance="localhost:9090"}` ,
588
623
expCode : http .StatusOK ,
589
- expMatch : []string {`{instance="localhost:9090",__name__="up",namespace=~ "default"}` },
624
+ expMatch : []string {`{instance="localhost:9090",__name__="up",namespace="default"}` },
590
625
expResponse : okResponse ,
591
626
},
592
627
{
@@ -679,15 +714,15 @@ func TestSeriesWithPost(t *testing.T) {
679
714
name : `No "match[]" parameter returns 200 with empty body` ,
680
715
labelv : []string {"default" },
681
716
method : http .MethodPost ,
682
- expMatch : []string {`{namespace=~ "default"}` },
717
+ expMatch : []string {`{namespace="default"}` },
683
718
expResponse : okResponse ,
684
719
expCode : http .StatusOK ,
685
720
},
686
721
{
687
722
name : `No "match[]" parameter returns 200 with empty body for POSTs` ,
688
723
method : http .MethodPost ,
689
724
labelv : []string {"default" },
690
- expMatch : []string {`{namespace=~ "default"}` },
725
+ expMatch : []string {`{namespace="default"}` },
691
726
expResponse : okResponse ,
692
727
expCode : http .StatusOK ,
693
728
},
@@ -697,7 +732,7 @@ func TestSeriesWithPost(t *testing.T) {
697
732
promQueryBody : "up" ,
698
733
method : http .MethodPost ,
699
734
expCode : http .StatusOK ,
700
- expMatch : []string {`{__name__="up",namespace=~ "default"}` },
735
+ expMatch : []string {`{__name__="up",namespace="default"}` },
701
736
expResponse : okResponse ,
702
737
},
703
738
{
@@ -724,7 +759,7 @@ func TestSeriesWithPost(t *testing.T) {
724
759
promQueryBody : `up{instance="localhost:9090"}` ,
725
760
method : http .MethodPost ,
726
761
expCode : http .StatusOK ,
727
- expMatch : []string {`{instance="localhost:9090",__name__="up",namespace=~ "default"}` },
762
+ expMatch : []string {`{instance="localhost:9090",__name__="up",namespace="default"}` },
728
763
expResponse : okResponse ,
729
764
},
730
765
{
0 commit comments