Skip to content

Commit

Permalink
Add explicit routeLabel to simplify jsonnet
Browse files Browse the repository at this point in the history
Signed-off-by: György Krajcsovits <[email protected]>
  • Loading branch information
krajorama committed Mar 21, 2024
1 parent c42cc70 commit a67c905
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions operations/mimir-mixin/dashboards/dashboard-queries.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -77,28 +77,25 @@
// These query routes are used in the overview and other dashboard, everythign else is considered "other" queries.
// Has to be a list to keep the same colors as before, see overridesNonErrorColorsPalette.
local overviewRoutes = [
r { routeStr: std.strReplace(r.route, '/', '_') }
for r in [
{ name: 'instantQuery', displayName: 'instant queries', route: '/api/v1/query' },
{ name: 'rangeQuery', displayName: 'range queries', route: '/api/v1/query_range' },
{ name: 'labelNames', displayName: '"label names" queries', route: '/api/v1/labels' },
{ name: 'labelValues', displayName: '"label values" queries', route: '/api/v1/label_name_values' },
{ name: 'series', displayName: 'series queries', route: '/api/v1/series' },
{ name: 'remoteRead', displayName: 'remote read queries', route: '/api/v1/read' },
{ name: 'metadata', displayName: 'metadata queries', route: '/api/v1/metadata' },
{ name: 'exemplars', displayName: 'exemplar queries', route: '/api/v1/query_exemplars' },
{ name: 'activeSeries', displayName: '"active series" queries', route: '/api/v1/cardinality_active_series' },
{ name: 'labelNamesCardinality', displayName: '"label name cardinality" queries', route: '/api/v1/cardinality_label_names' },
{ name: 'labelValuesCardinality', displayName: '"label value cardinality" queries', route: '/api/v1/cardinality_label_values' },
]
{ name: 'instantQuery', displayName: 'instant queries', route: '/api/v1/query', routeLabel: '_api_v1_query' },
{ name: 'rangeQuery', displayName: 'range queries', route: '/api/v1/query_range', routeLabel: '_api_v1_query_range' },
{ name: 'labelNames', displayName: '"label names" queries', route: '/api/v1/labels', routeLabel: '_api_v1_labels' },
{ name: 'labelValues', displayName: '"label values" queries', route: '/api/v1/label_name_values', routeLabel: '_api_v1_label_name_values' },
{ name: 'series', displayName: 'series queries', route: '/api/v1/series', routeLabel: '_api_v1_series' },
{ name: 'remoteRead', displayName: 'remote read queries', route: '/api/v1/read', routeLabel: '_api_v1_read' },
{ name: 'metadata', displayName: 'metadata queries', route: '/api/v1/metadata', routeLabel: '_api_v1_metadata' },
{ name: 'exemplars', displayName: 'exemplar queries', route: '/api/v1/query_exemplars', routeLabel: '_api_v1_query_exemplars' },
{ name: 'activeSeries', displayName: '"active series" queries', route: '/api/v1/cardinality_active_series', routeLabel: '_api_v1_cardinality_active_series' },
{ name: 'labelNamesCardinality', displayName: '"label name cardinality" queries', route: '/api/v1/cardinality_label_names', routeLabel: '_api_v1_cardinality_label_names' },
{ name: 'labelValuesCardinality', displayName: '"label value cardinality" queries', route: '/api/v1/cardinality_label_values', routeLabel: '_api_v1_cardinality_label_values' },
],
local overviewRoutesRegex = '(prometheus|api_prom)(%s)' % std.join('|', [r.routeStr for r in overviewRoutes]),
local overviewRoutesRegex = '(prometheus|api_prom)(%s)' % std.join('|', [r.routeLabel for r in overviewRoutes]),
overviewRoutesOverrides: [
{
matcher: {
id: 'byRegexp',
// To distinguish between query and query_range, we need to match the route with a negative lookahead.
options: '/.*%s($|[^_])/' % r.routeStr,
options: '/.*%s($|[^_])/' % r.routeLabel,
},
properties: [
{
Expand All @@ -113,7 +110,7 @@
nonOverviewRoutesPerSecond: 'sum(rate(cortex_request_duration_seconds_count{%(queryFrontendMatcher)s,route=~"(prometheus|api_prom)_api_v1_.*",route!~"%(overviewRoutesRegex)s"}[$__rate_interval]))' % (variables { overviewRoutesRegex: overviewRoutesRegex }),

local queryPerSecond(name) = 'sum(rate(cortex_request_duration_seconds_count{%(queryFrontendMatcher)s,route=~"(prometheus|api_prom)%(route)s"}[$__rate_interval]))' %
(variables { route: std.filter(function(r) r.name == name, overviewRoutes)[0].routeStr }),
(variables { route: std.filter(function(r) r.name == name, overviewRoutes)[0].routeLabel }),
instantQueriesPerSecond: queryPerSecond('instantQuery'),
rangeQueriesPerSecond: queryPerSecond('rangeQuery'),
labelNamesQueriesPerSecond: queryPerSecond('labelNames'),
Expand Down

0 comments on commit a67c905

Please sign in to comment.