Skip to content

Commit 4ec552d

Browse files
committed
add alert for scrape body size exceeding limit
1 parent b3aa278 commit 4ec552d

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

assets/prometheus-k8s/prometheus-rule.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,14 @@ spec:
245245
for: 5m
246246
labels:
247247
severity: critical
248+
- alert: PrometheusScrapeBodySizeLimitHit
249+
annotations:
250+
description: Prometheus {{$labels.namespace}}/{{$labels.pod}} has dropped
251+
{{ printf "%.0f" $value }} targets because some scraped targets have exceeded
252+
the body size limit.
253+
summary: Prometheus has dropped targets because some scraped targets have
254+
exceeded the body size limit.
255+
expr: increase(prometheus_target_scrapes_exceeded_body_size_limit_total{job=~"prometheus-k8s|prometheus-user-workload"}[5m])>0
256+
for: 15m
257+
labels:
258+
severity: warning

jsonnet/utils/sanitize-rules.libsonnet

+44-2
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,26 @@ local patchedRules = [
326326
},
327327
];
328328

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+
329349
local openShiftRunbook(runbook) =
330350
'https://github.com/openshift/runbooks/blob/master/' + runbook;
331351

@@ -389,7 +409,10 @@ local patchOrExcludeRuleGroup(group, groupSet, operation) =
389409
if std.length(groupSet) == 0 then
390410
[group.rules]
391411
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]
393416
else
394417
[] + patchOrExcludeRuleGroup(group, groupSet[1:], operation);
395418

@@ -423,6 +446,20 @@ local patchOrExcludeRuleGroup(group, groupSet, operation) =
423446
},
424447
},
425448

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+
426463
addRunbookUrls(o): o {
427464
[if (o.kind == 'PrometheusRule') then 'spec']+: k8sMixinUtils.mapRuleGroups(addRunbookUrl),
428465
},
@@ -450,9 +487,14 @@ local patchOrExcludeRuleGroup(group, groupSet, operation) =
450487
for k in std.objectFields(o)
451488
},
452489

490+
addRules(o): {
491+
[k]: $.addRule(o[k])
492+
for k in std.objectFields(o)
493+
},
494+
453495
// shorthand for rule patching, rule excluding, and runbook_url removal
454496
sanitizeAlertRules(o): {
455-
[k]: $.addRunbookUrls($.removeRunbookUrls($.patchRule($.excludeRule(o[k]))))
497+
[k]: $.addRunbookUrls($.removeRunbookUrls($.addRule($.patchRule($.excludeRule(o[k])))))
456498
for k in std.objectFields(o)
457499
},
458500
}

0 commit comments

Comments
 (0)