Skip to content

Commit

Permalink
fix: Fix label values query when server.http_path_prefix is set (#15978)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
chaudum authored and salvacorts committed Feb 12, 2025
1 parent 4a17596 commit 0dc531f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
30 changes: 16 additions & 14 deletions pkg/querier/queryrange/roundtrip.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,32 +506,34 @@ func getOperation(path string) string {
switch {
case strings.HasSuffix(path, "/query_range") || strings.HasSuffix(path, "/prom/query"):
return QueryRangeOp
case strings.HasSuffix(path, "/query"):
return InstantQueryOp
case strings.HasSuffix(path, "/series"):
return SeriesOp
case strings.HasSuffix(path, "/labels") || strings.HasSuffix(path, "/label"):
return LabelNamesOp
case strings.HasSuffix(path, "/v1/query"):
return InstantQueryOp
case path == "/loki/api/v1/index/stats":
case strings.HasSuffix(path, "/index/stats"):
return IndexStatsOp
case path == "/loki/api/v1/index/volume":
case strings.HasSuffix(path, "/index/volume"):
return VolumeOp
case path == "/loki/api/v1/index/volume_range":
case strings.HasSuffix(path, "/index/volume_range"):
return VolumeRangeOp
case path == "/loki/api/v1/index/shards":
case strings.HasSuffix(path, "/index/shards"):
return IndexShardsOp
case path == "/loki/api/v1/detected_fields":
case strings.HasSuffix(path, "/detected_fields"):
return DetectedFieldsOp
case strings.HasSuffix(path, "/patterns"):
return PatternsQueryOp
case strings.HasSuffix(path, "/detected_labels"):
return DetectedLabelsOp
case strings.HasSuffix(path, "/values"):
if strings.HasPrefix(path, "/loki/api/v1/label") || strings.HasPrefix(path, "/api/prom/label") {
if strings.Contains(path, "/label") {
return LabelNamesOp
}

return DetectedFieldsOp
case path == "/loki/api/v1/patterns":
return PatternsQueryOp
case path == "/loki/api/v1/detected_labels":
return DetectedLabelsOp
if strings.Contains(path, "/detected_field") {
return DetectedFieldsOp
}
return ""
default:
return ""
}
Expand Down
13 changes: 8 additions & 5 deletions pkg/querier/queryrange/roundtrip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1273,11 +1273,14 @@ func Test_getOperation(t *testing.T) {
},
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
got := getOperation(tc.path)
assert.Equal(t, tc.expectedOp, got)
})
for _, pathPrefix := range []string{"", "/proxy"} {
for _, tc := range cases {
name := tc.name + pathPrefix + tc.path
t.Run(name, func(t *testing.T) {
got := getOperation(pathPrefix + tc.path)
assert.Equal(t, tc.expectedOp, got)
})
}
}
}

Expand Down

0 comments on commit 0dc531f

Please sign in to comment.