Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more op label values to cortex_query_frontend_queries_total metric #6519

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* [FEATURE] Query Frontend: Support a metadata federated query when `-tenant-federation.enabled=true`. #6461
* [FEATURE] Query Frontend: Support an exemplar federated query when `-tenant-federation.enabled=true`. #6455
* [FEATURE] Ingester/StoreGateway: Add support for cache regex query matchers via `-ingester.matchers-cache-max-items` and `-blocks-storage.bucket-store.matchers-cache-max-items`. #6477 #6491
* [ENHANCEMENT] Query Frontend: Add more operation label values to the `cortex_query_frontend_queries_total` metric. #6519
* [ENHANCEMENT] Query Frontend: Add a `source` label to query stat metrics. #6470
* [ENHANCEMENT] Query Frontend: Add a flag `-tenant-federation.max-tenant` to limit the number of tenants for federated query. #6493
* [ENHANCEMENT] Querier: Add a `-tenant-federation.max-concurrent` flags to configure the number of worker processing federated query and add a `cortex_querier_federated_tenants_per_query` histogram to track the number of tenants per query. #6449
Expand Down
39 changes: 33 additions & 6 deletions pkg/querier/tripperware/roundtrip.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ import (
util_log "github.com/cortexproject/cortex/pkg/util/log"
)

const (
opTypeQuery = "query"
opTypeQueryRange = "query_range"
opTypeSeries = "series"
opTypeRemoteRead = "remote_read"
opTypeLabelNames = "label_names"
opTypeLabelValues = "label_values"
opTypeMetadata = "metadata"
opTypeQueryExemplars = "query_exemplars"
)

// HandlerFunc is like http.HandlerFunc, but for Handler.
type HandlerFunc func(context.Context, Request) (Response, error)

Expand Down Expand Up @@ -140,12 +151,28 @@ func NewQueryTripperware(
isQuery := strings.HasSuffix(r.URL.Path, "/query")
isQueryRange := strings.HasSuffix(r.URL.Path, "/query_range")
isSeries := strings.HasSuffix(r.URL.Path, "/series")

op := "query"
if isQueryRange {
op = "query_range"
} else if isSeries {
op = "series"
isRemoteRead := strings.HasSuffix(r.URL.Path, "/read")
isLabelNames := strings.HasSuffix(r.URL.Path, "/labels")
isLabelValues := strings.HasSuffix(r.URL.Path, "/values")
isMetadata := strings.HasSuffix(r.URL.Path, "/metadata")
isQueryExemplars := strings.HasSuffix(r.URL.Path, "/query_exemplars")

op := opTypeQuery
switch {
case isQueryRange:
op = opTypeQueryRange
case isSeries:
op = opTypeSeries
case isRemoteRead:
op = opTypeRemoteRead
case isLabelNames:
op = opTypeLabelNames
case isLabelValues:
op = opTypeLabelValues
case isMetadata:
op = opTypeMetadata
case isQueryExemplars:
op = opTypeQueryExemplars
}

tenantIDs, err := tenant.TenantIDs(r.Context())
Expand Down
54 changes: 53 additions & 1 deletion pkg/querier/tripperware/roundtrip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ const (
querySubqueryStepSizeTooSmall = "/api/v1/query?query=up%5B30d%3A%5D"
queryExceedsMaxQueryLength = "/api/v1/query?query=up%5B90d%5D"
seriesQuery = "/api/v1/series?match[]"
remoteReadQuery = "/api/v1/read"
labelNamesQuery = "/api/v1/labels"
labelValuesQuery = "/api/v1/label/label/values"
metadataQuery = "/api/v1/metadata"

responseBody = `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"foo":"bar"},"values":[[1536673680,"137"],[1536673780,"137"]]}]}}`
instantResponseBody = `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"foo":"bar"},"values":[[1536673680,"137"],[1536673780,"137"]]}]}}`
Expand Down Expand Up @@ -153,7 +157,7 @@ cortex_query_frontend_queries_total{op="query", source="api", user="1"} 1
expectedMetric: `
# HELP cortex_query_frontend_queries_total Total queries sent per tenant.
# TYPE cortex_query_frontend_queries_total counter
cortex_query_frontend_queries_total{op="query", source="api", user="1"} 1
cortex_query_frontend_queries_total{op="query_exemplars", source="api", user="1"} 1
`,
},
{
Expand All @@ -166,6 +170,54 @@ cortex_query_frontend_queries_total{op="query", source="api", user="1"} 1
# HELP cortex_query_frontend_queries_total Total queries sent per tenant.
# TYPE cortex_query_frontend_queries_total counter
cortex_query_frontend_queries_total{op="series", source="api", user="1"} 1
`,
},
{
path: labelNamesQuery,
expectedBody: "bar",
limits: defaultOverrides,
maxSubQuerySteps: 11000,
userAgent: "dummyUserAgent/1.2",
expectedMetric: `
# HELP cortex_query_frontend_queries_total Total queries sent per tenant.
# TYPE cortex_query_frontend_queries_total counter
cortex_query_frontend_queries_total{op="label_names", source="api", user="1"} 1
`,
},
{
path: labelValuesQuery,
expectedBody: "bar",
limits: defaultOverrides,
maxSubQuerySteps: 11000,
userAgent: "dummyUserAgent/1.2",
expectedMetric: `
# HELP cortex_query_frontend_queries_total Total queries sent per tenant.
# TYPE cortex_query_frontend_queries_total counter
cortex_query_frontend_queries_total{op="label_values", source="api", user="1"} 1
`,
},
{
path: metadataQuery,
expectedBody: "bar",
limits: defaultOverrides,
maxSubQuerySteps: 11000,
userAgent: "dummyUserAgent/1.2",
expectedMetric: `
# HELP cortex_query_frontend_queries_total Total queries sent per tenant.
# TYPE cortex_query_frontend_queries_total counter
cortex_query_frontend_queries_total{op="metadata", source="api", user="1"} 1
`,
},
{
path: remoteReadQuery,
expectedBody: "bar",
limits: defaultOverrides,
maxSubQuerySteps: 11000,
userAgent: "dummyUserAgent/1.2",
expectedMetric: `
# HELP cortex_query_frontend_queries_total Total queries sent per tenant.
# TYPE cortex_query_frontend_queries_total counter
cortex_query_frontend_queries_total{op="remote_read", source="api", user="1"} 1
`,
},
{
Expand Down
Loading