-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
Copy pathloki-operational.libsonnet
289 lines (269 loc) · 18.5 KB
/
loki-operational.libsonnet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
local lokiOperational = (import './dashboard-loki-operational.json');
local utils = import 'mixin-utils/utils.libsonnet';
(import 'dashboard-utils.libsonnet') {
grafanaDashboards+: {
local dashboards = self,
'loki-operational.json': {
local cfg = self,
showAnnotations:: true,
showLinks:: true,
showMultiCluster:: true,
hiddenRows:: [
'Cassandra',
if $._config.ssd.enabled then 'Ingester',
if !$._config.ssd.enabled then 'Backend Path',
if !$._config.operational.memcached then 'Memcached',
if !$._config.operational.consul then 'Consul',
if !$._config.operational.bigTable then 'Big Table',
if !$._config.operational.dynamo then 'Dynamo',
if !$._config.operational.gcs then 'GCS',
if !$._config.operational.s3 then 'S3',
if !$._config.operational.azureBlob then 'Azure Blob',
if !$._config.operational.boltDB then 'BoltDB Shipper',
],
hiddenPanels:: if $._config.promtail.enabled then [] else [
'Bad Words',
],
jobMatchers:: {
cortexgateway: [utils.selector.re('job', '($namespace)/cortex-gw(-internal)?')],
distributor: if $._config.meta_monitoring.enabled
then [utils.selector.re('job', '($namespace)/(distributor|%s-write|loki-single-binary)' % $._config.ssd.pod_prefix_matcher)]
else [utils.selector.re('job', '($namespace)/%s' % (if $._config.ssd.enabled then '%s-write' % $._config.ssd.pod_prefix_matcher else 'distributor'))],
ingester: if $._config.meta_monitoring.enabled
then [utils.selector.re('job', '($namespace)/(partition-ingester.*|ingester.*|%s-write|loki-single-binary)' % $._config.ssd.pod_prefix_matcher)]
else [utils.selector.re('job', '($namespace)/%s' % (if $._config.ssd.enabled then '%s-write' % $._config.ssd.pod_prefix_matcher else '(ingester.*|partition-ingester.*)'))],
querier: if $._config.meta_monitoring.enabled
then [utils.selector.re('job', '($namespace)/(querier|%s-read|loki-single-binary)' % $._config.ssd.pod_prefix_matcher)]
else [utils.selector.re('job', '($namespace)/%s' % (if $._config.ssd.enabled then '%s-read' % $._config.ssd.pod_prefix_matcher else 'querier'))],
queryFrontend: if $._config.meta_monitoring.enabled
then [utils.selector.re('job', '($namespace)/(query-frontend|%s-read|loki-single-binary)' % $._config.ssd.pod_prefix_matcher)]
else [utils.selector.re('job', '($namespace)/%s' % (if $._config.ssd.enabled then '%s-read' % $._config.ssd.pod_prefix_matcher else 'query-frontend'))],
backend: [utils.selector.re('job', '($namespace)/%s-backend' % $._config.ssd.pod_prefix_matcher)],
},
podMatchers:: {
cortexgateway: [utils.selector.re('pod', 'cortex-gw')],
distributor: if $._config.meta_monitoring.enabled
then [utils.selector.re('pod', '(distributor|%s-write|loki-single-binary)' % $._config.ssd.pod_prefix_matcher)]
else [utils.selector.re('pod', '%s' % (if $._config.ssd.enabled then '%s-write.*' % $._config.ssd.pod_prefix_matcher else 'distributor.*'))],
ingester: if $._config.meta_monitoring.enabled
then [utils.selector.re('pod', '(partition-ingester.*|ingester.*|%s-write|loki-single-binary)' % $._config.ssd.pod_prefix_matcher)]
else [utils.selector.re('pod', '%s' % (if $._config.ssd.enabled then '%s-write.*' % $._config.ssd.pod_prefix_matcher else '(ingester.*|partition-ingester.*)'))],
querier: if $._config.meta_monitoring.enabled
then [utils.selector.re('pod', '(querier|%s-read|loki-single-binary)' % $._config.ssd.pod_prefix_matcher)]
else [utils.selector.re('pod', '%s' % (if $._config.ssd.enabled then '%s-read.*' % $._config.ssd.pod_prefix_matcher else 'querier.*'))],
backend: [utils.selector.re('pod', '%s-backend.*' % $._config.ssd.pod_prefix_matcher)],
},
}
+ lokiOperational + {
annotations:
if dashboards['loki-operational.json'].showAnnotations
then super.annotations
else {},
links:
if dashboards['loki-operational.json'].showLinks then
super.links
else [],
local matcherStr(matcherId, matcher='job', sep=',') =
if matcher == 'job' then
if std.length(dashboards['loki-operational.json'].jobMatchers[matcherId]) > 0 then
std.join(',', ['%(label)s%(op)s"%(value)s"' % matcher for matcher in dashboards['loki-operational.json'].jobMatchers[matcherId]]) + sep
else error 'no job matchers'
else if matcher == 'pod' then
if std.length(dashboards['loki-operational.json'].podMatchers[matcherId]) > 0 then
std.join(',', ['%(label)s%(op)s"%(value)s"' % matcher for matcher in dashboards['loki-operational.json'].podMatchers[matcherId]]) + sep
else error 'no pod matchers'
else error 'matcher must be either job or container',
local replaceClusterMatchers(expr) =
if dashboards['loki-operational.json'].showMultiCluster
// Replace the recording rules cluster label with the per-cluster label
then std.strReplace(
// Replace the cluster label for equality matchers with the per-cluster label
std.strReplace(
// Replace the cluster label for regex matchers with the per-cluster label
std.strReplace(
expr,
'cluster=~"$cluster"',
$._config.per_cluster_label + '=~"$cluster"'
),
'cluster="$cluster"',
$._config.per_cluster_label + '="$cluster"'
),
'cluster_job',
$._config.per_cluster_label + '_job'
)
else
std.strReplace(
std.strReplace(
std.strReplace(
expr,
', ' + $._config.per_cluster_label + '="$cluster"',
''
),
', ' + $._config.per_cluster_label + '=~"$cluster"',
''
),
$._config.per_cluster_label + '="$cluster",',
''
),
local replaceBackendMatchers(expr) =
std.strReplace(
std.strReplace(
std.strReplace(
expr,
'pod=~"backend.*"',
matcherStr('backend', matcher='pod', sep='')
),
'job="$namespace/backend",',
matcherStr('backend')
),
'job="$namespace/backend"',
std.rstripChars(matcherStr('backend'), ',')
),
local replaceQuerierMatchers(expr) =
std.strReplace(
std.strReplace(
std.strReplace(
expr,
'pod=~"querier.*"',
matcherStr('querier', matcher='pod', sep='')
),
'job="$namespace/querier",',
matcherStr('querier')
),
'job="$namespace/querier"',
std.rstripChars(matcherStr('querier'), ',')
),
local replaceMatchers(expr) =
std.strReplace(
std.strReplace(
std.strReplace(
std.strReplace(
std.strReplace(
std.strReplace(
std.strReplace(
std.strReplace(
std.strReplace(
std.strReplace(
std.strReplace(
std.strReplace(
expr,
'pod=~"ingester.*"',
matcherStr('ingester', matcher='pod', sep='')
),
'pod=~"distributor.*"',
matcherStr('distributor', matcher='pod', sep='')
),
'job="$namespace/cortex-gw",',
matcherStr('cortexgateway')
),
'job="$namespace/cortex-gw"',
std.rstripChars(matcherStr('cortexgateway'), ',')
),
'job=~"($namespace)/cortex-gw",',
matcherStr('cortexgateway')
),
'job="$namespace/distributor",',
matcherStr('distributor')
),
'job="$namespace/distributor"',
std.rstripChars(matcherStr('distributor'), ',')
),
'job=~"($namespace)/distributor",',
matcherStr('distributor')
),
'job=~"($namespace)/distributor"',
std.rstripChars(matcherStr('distributor'), ',')
),
'job="$namespace/ingester",',
matcherStr('ingester')
),
'job="$namespace/ingester"',
std.rstripChars(matcherStr('ingester'), ',')
),
'job=~"($namespace)/ingester",',
matcherStr('ingester'),
),
local replaceAllMatchers(expr) =
replaceBackendMatchers(
replaceQuerierMatchers(
replaceMatchers(expr)
)
),
local selectDatasource(ds) =
if ds == null || ds == '' then ds
else if ds == '$datasource' then '$datasource'
else '$loki_datasource',
local isRowHidden(row) =
std.member(dashboards['loki-operational.json'].hiddenRows, row),
local isPanelHidden(panelTitle) =
std.member(dashboards['loki-operational.json'].hiddenPanels, panelTitle),
local replaceCortexGateway(expr, replacement) = if $._config.internal_components then
expr
else
std.strReplace(
expr,
'job=~"$namespace/cortex-gw(-internal)?"',
matcherStr(replacement, matcher='job', sep='')
),
local removeInternalComponents(title, expr) = if (title == 'Queries/Second') then
replaceCortexGateway(expr, 'queryFrontend')
else if (title == 'Pushes/Second') then
replaceCortexGateway(expr, 'distributor')
else if (title == 'Push Latency') then
replaceCortexGateway(expr, 'distributor')
else
replaceAllMatchers(expr),
panels: [
p {
datasource: selectDatasource(super.datasource),
targets: if std.objectHas(p, 'targets') then [
e {
expr: removeInternalComponents(p.title, replaceClusterMatchers(e.expr)),
}
for e in p.targets
] else [],
panels: if std.objectHas(p, 'panels') then [
sp {
datasource: selectDatasource(super.datasource),
targets: if std.objectHas(sp, 'targets') then [
e {
expr: removeInternalComponents(p.title, replaceClusterMatchers(e.expr)),
}
for e in sp.targets
] else [],
panels: if std.objectHas(sp, 'panels') then [
ssp {
datasource: selectDatasource(super.datasource),
targets: if std.objectHas(ssp, 'targets') then [
e {
expr: removeInternalComponents(p.title, replaceClusterMatchers(e.expr)),
}
for e in ssp.targets
] else [],
}
for ssp in sp.panels
if !(isPanelHidden(ssp.title))
] else [],
}
for sp in p.panels
if !(isPanelHidden(sp.title))
] else [],
title: if !($._config.ssd.enabled && p.type == 'row') then p.title else
if p.title == 'Distributor' then 'Write Path'
else if p.title == 'Querier' then 'Read Path'
else p.title,
}
for p in super.panels
if !(p.type == 'row' && isRowHidden(p.title)) && !(isPanelHidden(p.title))
],
} +
$.dashboard('Loki / Operational', uid='operational')
// The queries in this dashboard don't make use of the cluster template label selector
// but we keep it here to allow selecting a namespace specific to a certain cluster, the
// namespace template variable selectors query uses the cluster value.
.addLog()
.addCluster()
.addNamespace()
.addTag(),
},
}