@@ -326,6 +326,26 @@ local patchedRules = [
326
326
},
327
327
];
328
328
329
+ local addedRules = [
330
+ {
331
+ name: 'prometheus' ,
332
+ rules: [
333
+ {
334
+ alert: 'PrometheusScrapeBodySizeLimitHit' ,
335
+ expr: 'increase(prometheus_target_scrapes_exceeded_body_size_limit_total{job=~"prometheus-k8s|prometheus-user-workload"}[5m])>0' ,
336
+ 'for' : '15m' ,
337
+ labels: {
338
+ severity: 'warning' ,
339
+ },
340
+ annotations: {
341
+ description: 'Prometheus {{$labels.namespace}}/{{$labels.pod}} has dropped {{ printf "%.0f" $value }} targets because some scraped targets have exceeded the body size limit.' ,
342
+ summary: 'Prometheus has dropped targets because some scraped targets have exceeded the body size limit.' ,
343
+ },
344
+ },
345
+ ],
346
+ },
347
+ ];
348
+
329
349
local openShiftRunbook(runbook) =
330
350
'https://github.com/openshift/runbooks/blob/master/' + runbook;
331
351
@@ -389,7 +409,10 @@ local patchOrExcludeRuleGroup(group, groupSet, operation) =
389
409
if std.length (groupSet) == 0 then
390
410
[group.rules]
391
411
else if (group.name == groupSet[0 ].name) then
392
- [patchOrExcludeRule(rule, groupSet[0 ].rules, operation) for rule in group.rules]
412
+ if operation == 'add' then
413
+ [group.rules + groupSet[0 ].rules]
414
+ else
415
+ [patchOrExcludeRule(rule, groupSet[0 ].rules, operation) for rule in group.rules]
393
416
else
394
417
[] + patchOrExcludeRuleGroup(group, groupSet[1 :], operation);
395
418
@@ -423,6 +446,20 @@ local patchOrExcludeRuleGroup(group, groupSet, operation) =
423
446
},
424
447
},
425
448
449
+ addRule(o): o {
450
+ [if (o.kind == 'PrometheusRule' ) then 'spec' ]+: {
451
+ groups: std.map (
452
+ function (group)
453
+ group {
454
+ rules: std.flattenArrays (
455
+ patchOrExcludeRuleGroup(group, addedRules, 'add' )
456
+ ),
457
+ },
458
+ super .groups,
459
+ ),
460
+ },
461
+ },
462
+
426
463
addRunbookUrls(o): o {
427
464
[if (o.kind == 'PrometheusRule' ) then 'spec' ]+: k8sMixinUtils.mapRuleGroups(addRunbookUrl),
428
465
},
@@ -450,9 +487,14 @@ local patchOrExcludeRuleGroup(group, groupSet, operation) =
450
487
for k in std.objectFields (o)
451
488
},
452
489
490
+ addRules(o): {
491
+ [k]: $.addRule(o[k])
492
+ for k in std.objectFields (o)
493
+ },
494
+
453
495
// shorthand for rule patching, rule excluding, and runbook_url removal
454
496
sanitizeAlertRules(o): {
455
- [k]: $.addRunbookUrls($.removeRunbookUrls($.patchRule($.excludeRule(o[k]))))
497
+ [k]: $.addRunbookUrls($.removeRunbookUrls($.addRule($. patchRule($.excludeRule(o[k]) ))))
456
498
for k in std.objectFields (o)
457
499
},
458
500
}
0 commit comments