@@ -69,12 +69,20 @@ local utils = import 'mixin-utils/utils.libsonnet';
69
69
rules: [
70
70
{
71
71
// Convenience rule to get the number of replicas for both a deployment and a statefulset.
72
+ // Multi-zone deployments are grouped together removing the "zone-X" suffix.
72
73
record: 'cluster_namespace_deployment:actual_replicas:count' ,
73
74
expr: |||
74
- sum by (cluster, namespace, deployment) (kube_deployment_spec_replicas)
75
- or
76
75
sum by (cluster, namespace, deployment) (
77
- label_replace(kube_statefulset_replicas, "deployment", "$1", "statefulset", "(.*)")
76
+ label_replace(
77
+ kube_deployment_spec_replicas,
78
+ # The question mark in "(.*?)" is used to make it non-greedy, otherwise it
79
+ # always matches everything and the (optional) zone is not removed.
80
+ "deployment", "$1", "deployment", "(.*?)(?:-zone-[a-z])?"
81
+ )
82
+ )
83
+ or
84
+ sum by (cluster, namespace, deployment) (
85
+ label_replace(kube_statefulset_replicas, "deployment", "$1", "statefulset", "(.*?)(?:-zone-[a-z])?")
78
86
)
79
87
||| ,
80
88
},
@@ -188,7 +196,7 @@ local utils = import 'mixin-utils/utils.libsonnet';
188
196
expr: |||
189
197
ceil(
190
198
(sum by (cluster, namespace) (
191
- cortex_ingester_tsdb_storage_blocks_bytes{job=~".+/ingester"}
199
+ cortex_ingester_tsdb_storage_blocks_bytes{job=~".+/ingester.* "}
192
200
) / 4)
193
201
/
194
202
avg by (cluster, namespace) (
@@ -199,18 +207,25 @@ local utils = import 'mixin-utils/utils.libsonnet';
199
207
},
200
208
{
201
209
// Convenience rule to get the CPU utilization for both a deployment and a statefulset.
210
+ // Multi-zone deployments are grouped together removing the "zone-X" suffix.
202
211
record: 'cluster_namespace_deployment:container_cpu_usage_seconds_total:sum_rate' ,
203
212
expr: |||
204
213
sum by (cluster, namespace, deployment) (
205
214
label_replace(
206
- node_namespace_pod_container:container_cpu_usage_seconds_total:sum_rate,
207
- "deployment", "$1", "pod", "(.*)-(?:([0-9]+)|([a-z0-9]+)-([a-z0-9]+))"
215
+ label_replace(
216
+ node_namespace_pod_container:container_cpu_usage_seconds_total:sum_rate,
217
+ "deployment", "$1", "pod", "(.*)-(?:([0-9]+)|([a-z0-9]+)-([a-z0-9]+))"
218
+ ),
219
+ # The question mark in "(.*?)" is used to make it non-greedy, otherwise it
220
+ # always matches everything and the (optional) zone is not removed.
221
+ "deployment", "$1", "deployment", "(.*?)(?:-zone-[a-z])?"
208
222
)
209
223
)
210
224
||| ,
211
225
},
212
226
{
213
227
// Convenience rule to get the CPU request for both a deployment and a statefulset.
228
+ // Multi-zone deployments are grouped together removing the "zone-X" suffix.
214
229
record: 'cluster_namespace_deployment:kube_pod_container_resource_requests_cpu_cores:sum' ,
215
230
expr: |||
216
231
# This recording rule is made compatible with the breaking changes introduced in kube-state-metrics v2
@@ -223,8 +238,13 @@ local utils = import 'mixin-utils/utils.libsonnet';
223
238
(
224
239
sum by (cluster, namespace, deployment) (
225
240
label_replace(
226
- kube_pod_container_resource_requests_cpu_cores,
227
- "deployment", "$1", "pod", "(.*)-(?:([0-9]+)|([a-z0-9]+)-([a-z0-9]+))"
241
+ label_replace(
242
+ kube_pod_container_resource_requests_cpu_cores,
243
+ "deployment", "$1", "pod", "(.*)-(?:([0-9]+)|([a-z0-9]+)-([a-z0-9]+))"
244
+ ),
245
+ # The question mark in "(.*?)" is used to make it non-greedy, otherwise it
246
+ # always matches everything and the (optional) zone is not removed.
247
+ "deployment", "$1", "deployment", "(.*?)(?:-zone-[a-z])?"
228
248
)
229
249
)
230
250
)
@@ -234,8 +254,13 @@ local utils = import 'mixin-utils/utils.libsonnet';
234
254
(
235
255
sum by (cluster, namespace, deployment) (
236
256
label_replace(
237
- kube_pod_container_resource_requests{resource="cpu"},
238
- "deployment", "$1", "pod", "(.*)-(?:([0-9]+)|([a-z0-9]+)-([a-z0-9]+))"
257
+ label_replace(
258
+ kube_pod_container_resource_requests{resource="cpu"},
259
+ "deployment", "$1", "pod", "(.*)-(?:([0-9]+)|([a-z0-9]+)-([a-z0-9]+))"
260
+ ),
261
+ # The question mark in "(.*?)" is used to make it non-greedy, otherwise it
262
+ # always matches everything and the (optional) zone is not removed.
263
+ "deployment", "$1", "deployment", "(.*?)(?:-zone-[a-z])?"
239
264
)
240
265
)
241
266
)
@@ -261,18 +286,25 @@ local utils = import 'mixin-utils/utils.libsonnet';
261
286
},
262
287
{
263
288
// Convenience rule to get the Memory utilization for both a deployment and a statefulset.
289
+ // Multi-zone deployments are grouped together removing the "zone-X" suffix.
264
290
record: 'cluster_namespace_deployment:container_memory_usage_bytes:sum' ,
265
291
expr: |||
266
292
sum by (cluster, namespace, deployment) (
267
293
label_replace(
268
- container_memory_usage_bytes,
269
- "deployment", "$1", "pod", "(.*)-(?:([0-9]+)|([a-z0-9]+)-([a-z0-9]+))"
294
+ label_replace(
295
+ container_memory_usage_bytes,
296
+ "deployment", "$1", "pod", "(.*)-(?:([0-9]+)|([a-z0-9]+)-([a-z0-9]+))"
297
+ ),
298
+ # The question mark in "(.*?)" is used to make it non-greedy, otherwise it
299
+ # always matches everything and the (optional) zone is not removed.
300
+ "deployment", "$1", "deployment", "(.*?)(?:-zone-[a-z])?"
270
301
)
271
302
)
272
303
||| ,
273
304
},
274
305
{
275
306
// Convenience rule to get the Memory request for both a deployment and a statefulset.
307
+ // Multi-zone deployments are grouped together removing the "zone-X" suffix.
276
308
record: 'cluster_namespace_deployment:kube_pod_container_resource_requests_memory_bytes:sum' ,
277
309
expr: |||
278
310
# This recording rule is made compatible with the breaking changes introduced in kube-state-metrics v2
@@ -285,8 +317,13 @@ local utils = import 'mixin-utils/utils.libsonnet';
285
317
(
286
318
sum by (cluster, namespace, deployment) (
287
319
label_replace(
288
- kube_pod_container_resource_requests_memory_bytes,
289
- "deployment", "$1", "pod", "(.*)-(?:([0-9]+)|([a-z0-9]+)-([a-z0-9]+))"
320
+ label_replace(
321
+ kube_pod_container_resource_requests_memory_bytes,
322
+ "deployment", "$1", "pod", "(.*)-(?:([0-9]+)|([a-z0-9]+)-([a-z0-9]+))"
323
+ ),
324
+ # The question mark in "(.*?)" is used to make it non-greedy, otherwise it
325
+ # always matches everything and the (optional) zone is not removed.
326
+ "deployment", "$1", "deployment", "(.*?)(?:-zone-[a-z])?"
290
327
)
291
328
)
292
329
)
@@ -296,8 +333,13 @@ local utils = import 'mixin-utils/utils.libsonnet';
296
333
(
297
334
sum by (cluster, namespace, deployment) (
298
335
label_replace(
299
- kube_pod_container_resource_requests{resource="memory"},
300
- "deployment", "$1", "pod", "(.*)-(?:([0-9]+)|([a-z0-9]+)-([a-z0-9]+))"
336
+ label_replace(
337
+ kube_pod_container_resource_requests{resource="memory"},
338
+ "deployment", "$1", "pod", "(.*)-(?:([0-9]+)|([a-z0-9]+)-([a-z0-9]+))"
339
+ ),
340
+ # The question mark in "(.*?)" is used to make it non-greedy, otherwise it
341
+ # always matches everything and the (optional) zone is not removed.
342
+ "deployment", "$1", "deployment", "(.*?)(?:-zone-[a-z])?"
301
343
)
302
344
)
303
345
)
0 commit comments