-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathconfig.libsonnet
302 lines (288 loc) · 11.3 KB
/
config.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
290
291
292
293
294
295
296
297
298
299
300
301
302
local utils = (import 'github.com/grafana/jsonnet-libs/mixin-utils/utils.libsonnet');
local thanos = (import '../services/observatorium-metrics.libsonnet').thanos;
local var = import 'utils.jsonnet';
{
thanos: (import 'github.com/thanos-io/thanos/mixin/config.libsonnet') {
local t = self,
targetGroups+:: {
namespace: 'thanos_status',
},
// Filter the namespaces in thanos-recieve-controller dashboard
hierarchies+:: {
namespace: 'thanos_status',
},
overview+:: {
title: '%(prefix)sOverview' % t.dashboard.prefix,
},
query+:: {
selector: 'job=~"%s.*|%s.*"' % [thanos.query.config.name, thanos.rulerQuery.config.name],
},
store+:: {
selector: 'job=~"%s.*"' % thanos.stores.config.name,
},
receive+:: {
local hashrings = ['%s.*' % thanos.receivers.hashrings[hashring].config.name for hashring in std.objectFields(thanos.receivers.hashrings)],
selector: 'job=~"%s"' % std.join('|', hashrings),
},
receiveController+:: {
selector: 'job="%s"' % thanos.receiveController.config.name,
receiveSelector: t.receive.selector,
},
rule+:: {
selector: 'job=~"%s.*|%s.*"' % [thanos.rule.config.name, thanos.metricFederationRule.config.name],
},
compact+:: {
selector: 'job="%s"' % thanos.compact.config.name,
},
dashboard+:: {
instance_name_filter: var.instance_name_filter,
},
},
obsctlReloader: {
_config+:: {
obsctlReloaderSelector: 'job="rules-obsctl-reloader"',
},
},
alertmanager: (import 'github.com/prometheus/alertmanager/doc/alertmanager-mixin/config.libsonnet') {
title: 'Alertmanager / Overview',
_config+:: {
alertmanagerClusterLabels: 'namespace,job',
alertmanagerNameLabels: 'pod',
alertmanagerCriticalIntegrationsRegEx: 'slack|pagerduty|email|webhook',
alertmanagerSelector: 'job="observatorium-alertmanager"',
},
},
loki: {
local withDatasource = function(ds) ds + (
if ds.name == 'datasource' then {
regex: '${OBSERVATORIUM_DATASOURCE_REGEX}',
current: {
selected: true,
text: '${OBSERVATORIUM_API_DATASOURCE}',
value: '${OBSERVATORIUM_API_DATASOURCE}',
},
} else {}
),
local withNamespace = function(ns) ns + (
if ns.label == 'namespace' then {
datasource: {
type: 'prometheus',
uid: '${datasource}',
},
current: {
selected: true,
text: '${OBSERVATORIUM_API_NAMESPACE}',
value: '${OBSERVATORIUM_API_NAMESPACE}',
},
definition: 'label_values(kube_pod_info, namespace)',
query: {
query: 'label_values(kube_pod_info, namespace)',
refId: 'StandardVariableQuery',
},
regex: 'observatorium-logs|mst-.+',
} else {}
),
local withLatencyAxis = function(p) p + (
if std.length(std.findSubstr('atency', p.title)) != 0 then {
yaxes: [
y {
format: 's',
}
for y in p.yaxes
],
} else {}
),
local defaultLokiTags = function(t)
std.uniq(t + ['observatorium', 'observatorium-logs']),
local replaceMatchers = function(replacements)
function(p) p {
targets: [
t {
expr: std.foldl(function(x, rp) std.strReplace(x, rp.from, rp.to), replacements, t.expr),
}
for t in p.targets
if std.objectHas(p, 'targets')
],
},
// dropPanels removes unnecessary panels from the loki-operational dashboard
// that are of obsolete usage on our AWS-based deployment environment.
local dropPanels = function(panels, dropList)
[
p
for p in panels
if !std.member(dropList, p.title)
],
// mapPanels applies recursively a set of functions over all panels.
// Note: A Grafana dashboard panel can include other panels.
// Example: Replace job label in expression and add axis units for all panels.
local mapPanels = function(funcs, panels)
[
// Transform the current panel by applying all transformer funcs.
// Keep the last version after foldl ends.
std.foldl(function(agg, fn) fn(agg), funcs, p) + (
// Recursively apply all transformer functions to any
// children panels.
if std.objectHas(p, 'panels') then {
panels: mapPanels(funcs, p.panels),
} else {}
)
for p in panels
],
// mapTemplateParameters applies a static list of transformer functions to
// all dashboard template parameters. The static list includes:
// - RHOBS cluster-prometheus as datasource based on RHOBS environment.
// - filtered list of namespaces based on selected RHOBS cluster.
local mapTemplateParameters = function(ls)
[
std.foldl(function(x, fn) fn(x), [withDatasource, withNamespace], item)
for item in ls
if item.name != 'cluster'
],
prometheusRules+: {
groups: [
g {
rules: [
r {
expr: std.strReplace(r.expr, 'cluster, ', ''),
record: std.strReplace(r.record, 'cluster_', ''),
}
for r in g.rules
],
}
for g in super.groups
],
},
grafanaDashboards+: {
// Exclude the following dashboards
'loki-deletion.json':: super['loki-deletion.json'],
'loki-mixin-recording-rules.json':: super['loki-mixin-recording-rules.json'],
'loki-reads-resources.json':: super['loki-reads-resources.json'],
'loki-writes-resources.json':: super['loki-writes-resources.json'],
'loki-retention.json'+: {
local dropList = ['Logs'],
local replacements = [
{ from: 'cluster=~"$cluster",', to: '' },
{ from: 'container="compactor"', to: 'container="observatorium-loki-compactor"' },
{ from: 'job=~"($namespace)/compactor"', to: 'job="observatorium-loki-compactor"' },
],
uid: 'RetCujSHzC8gd9i5fck9a3v9n2EvTzA',
tags: defaultLokiTags(super.tags),
rows: [
r {
panels: mapPanels([replaceMatchers(replacements)], r.panels),
}
for r in dropPanels(super.rows, dropList)
],
// Adapt dashboard template parameters:
// - Match default selected datasource to RHOBS cluster.
// - Match namespaces to RHOBS cluster namespaces
templating+: {
list: mapTemplateParameters(super.list),
},
},
'loki-chunks.json'+: {
uid: 'GtCujSHzC8gd9i5fck9a3v9n2EvTzA',
tags: defaultLokiTags(super.tags),
showMultiCluster:: false,
namespaceQuery:: 'label_values(kube_pod_info, namespace)',
namespaceType:: 'query',
labelsSelector:: 'job="observatorium-loki-ingester"',
// Adapt dashboard template parameters:
// - Match default selected datasource to RHOBS cluster.
// - Match namespaces to RHOBS cluster namespaces
templating+: {
list: mapTemplateParameters(super.list),
},
},
'loki-operational.json'+: {
local sjm = super.jobMatchers,
uid: 'E2CAJBcLcg3NNfd2jLKe4fhQpf2LaU',
tags: defaultLokiTags(super.tags),
showAnnotations:: false,
showLinks:: false,
showMultiCluster:: false,
namespaceQuery:: 'label_values(kube_pod_info, namespace)',
namespaceType:: 'query',
jobMatchers:: {
cortexgateway:: sjm.cortexgateway,
distributor:: [utils.selector.eq('job', 'observatorium-loki-distributor')],
ingester:: [utils.selector.eq('job', 'observatorium-loki-ingester')],
querier:: [utils.selector.eq('job', 'observatorium-loki-querier')],
},
// Adapt dashboard panels to:
// - Use RHOBS related job label selectors instead of mixin defaults.
// - Add seconds as time unit for all latency panels
// - Drop all rows not relevant for the RHOBS Loki deployment (e.g. GCS, BigTable)
local dropList = ['Consul', 'Big Table', 'GCS', 'Dynamo', 'Azure Blob', 'Cassandra'],
local replacements = [
// TODO: This substitution is needed because the 'replaceClusterMatchers' function in upstream lib 'loki-operational.libsonnet' misses 'cluster=~"$cluster"' substitution.
// Remove this substitution when it has been added to upstream.
{ from: 'cluster=~"$cluster",', to: '' },
{ from: 'job=~"$namespace/cortex-gw(-internal)?",', to: '' },
{ from: 'kube_pod_container_status_restarts_total{ ', to: 'kube_pod_container_status_restarts_total{container=~"observatorium-loki.+", ' },
{ from: ' * 1e3', to: '' },
{ from: 'pod=~"distributor.*"', to: 'pod=~".*distributor.*"' },
{ from: 'pod=~"ingester.*"', to: 'pod=~".*ingester.*"' },
{ from: 'pod=~"querier.*"', to: 'pod=~".*querier.*"' },
{ from: 'job=~"$namespace/ingester",', to: 'job="observatorium-loki-ingester",' },
],
panels: mapPanels([replaceMatchers(replacements), withLatencyAxis], dropPanels(super.panels, dropList)),
// Adapt dashboard template parameters:
// - Match default selected datasource to RHOBS cluster.
// - Match namespaces to RHOBS cluster namespaces
templating+: {
list: mapTemplateParameters(super.list),
},
},
'loki-reads.json'+: {
local dropList = ['BigTable', 'Ingester - Zone Aware'],
uid: '62q5jjYwhVSaz4Mcrm8tV3My3gcKED',
tags: defaultLokiTags(super.tags),
showMultiCluster:: false,
namespaceQuery:: 'label_values(kube_pod_info, namespace)',
namespaceType:: 'query',
matchers:: {
cortexgateway:: [],
queryFrontend:: [utils.selector.eq('job', 'observatorium-loki-query-frontend')],
querier:: [utils.selector.eq('job', 'observatorium-loki-querier')],
ingester:: [utils.selector.eq('job', 'observatorium-loki-ingester')],
ingesterZoneAware:: [],
querierOrIndexGateway:: [],
},
rows: [
r {
title: std.strReplace(r.title, 'Frontend (query-frontend)', 'API'),
}
for r in dropPanels(super.rows, dropList)
],
// Adapt dashboard template parameters:
// - Match default selected datasource to RHOBS cluster.
// - Match namespaces to RHOBS cluster namespaces
templating+: {
list: mapTemplateParameters(super.list),
},
},
'loki-writes.json'+: {
local dropList = ['Ingester - Zone Aware'],
uid: 'F6nRYKuXmFVpVSFQmXr7cgXy5j7UNr',
tags: defaultLokiTags(super.tags),
showMultiCluster:: false,
namespaceQuery:: 'label_values(kube_pod_info, namespace)',
namespaceType:: 'query',
matchers:: {
cortexgateway:: [],
distributor:: [utils.selector.eq('job', 'observatorium-loki-distributor')],
ingester:: [utils.selector.eq('job', 'observatorium-loki-ingester')],
ingester_zone:: [],
},
rows: dropPanels(super.rows, dropList),
// Adapt dashboard template parameters:
// - Match default selected datasource to RHOBS cluster.
// - Match namespaces to RHOBS cluster namespaces
templating+: {
list: mapTemplateParameters(super.list),
},
},
},
},
}