Skip to content

Commit 65f5990

Browse files
authored
fix: Fix label values query when server.http_path_prefix is set (#15978)
This commit fixes a bug in the query range round tripper. It fixes the detection of the operation when decoding a HTTP request into a queryrange request object by comparing the path suffix rather than the equality of the full path. Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
1 parent d2e6d99 commit 65f5990

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

‎pkg/querier/queryrange/roundtrip.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -506,32 +506,34 @@ func getOperation(path string) string {
506506
switch {
507507
case strings.HasSuffix(path, "/query_range") || strings.HasSuffix(path, "/prom/query"):
508508
return QueryRangeOp
509+
case strings.HasSuffix(path, "/query"):
510+
return InstantQueryOp
509511
case strings.HasSuffix(path, "/series"):
510512
return SeriesOp
511513
case strings.HasSuffix(path, "/labels") || strings.HasSuffix(path, "/label"):
512514
return LabelNamesOp
513-
case strings.HasSuffix(path, "/v1/query"):
514-
return InstantQueryOp
515-
case path == "/loki/api/v1/index/stats":
515+
case strings.HasSuffix(path, "/index/stats"):
516516
return IndexStatsOp
517-
case path == "/loki/api/v1/index/volume":
517+
case strings.HasSuffix(path, "/index/volume"):
518518
return VolumeOp
519-
case path == "/loki/api/v1/index/volume_range":
519+
case strings.HasSuffix(path, "/index/volume_range"):
520520
return VolumeRangeOp
521-
case path == "/loki/api/v1/index/shards":
521+
case strings.HasSuffix(path, "/index/shards"):
522522
return IndexShardsOp
523-
case path == "/loki/api/v1/detected_fields":
523+
case strings.HasSuffix(path, "/detected_fields"):
524524
return DetectedFieldsOp
525+
case strings.HasSuffix(path, "/patterns"):
526+
return PatternsQueryOp
527+
case strings.HasSuffix(path, "/detected_labels"):
528+
return DetectedLabelsOp
525529
case strings.HasSuffix(path, "/values"):
526-
if strings.HasPrefix(path, "/loki/api/v1/label") || strings.HasPrefix(path, "/api/prom/label") {
530+
if strings.Contains(path, "/label") {
527531
return LabelNamesOp
528532
}
529-
530-
return DetectedFieldsOp
531-
case path == "/loki/api/v1/patterns":
532-
return PatternsQueryOp
533-
case path == "/loki/api/v1/detected_labels":
534-
return DetectedLabelsOp
533+
if strings.Contains(path, "/detected_field") {
534+
return DetectedFieldsOp
535+
}
536+
return ""
535537
default:
536538
return ""
537539
}

‎pkg/querier/queryrange/roundtrip_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,11 +1273,14 @@ func Test_getOperation(t *testing.T) {
12731273
},
12741274
}
12751275

1276-
for _, tc := range cases {
1277-
t.Run(tc.name, func(t *testing.T) {
1278-
got := getOperation(tc.path)
1279-
assert.Equal(t, tc.expectedOp, got)
1280-
})
1276+
for _, pathPrefix := range []string{"", "/proxy"} {
1277+
for _, tc := range cases {
1278+
name := tc.name + pathPrefix + tc.path
1279+
t.Run(name, func(t *testing.T) {
1280+
got := getOperation(pathPrefix + tc.path)
1281+
assert.Equal(t, tc.expectedOp, got)
1282+
})
1283+
}
12811284
}
12821285
}
12831286

0 commit comments

Comments
 (0)