Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion class/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ parameters:
backupcommandannotation: k8up.syn.tools/backupcommand
tz: Europe/Zurich
alert_rule_filters:
namespace: namespace=~"syn.*"
namespace:
match_re: "syn.*"
prometheus_push_gateway: 'http://platform-prometheus-pushgateway.syn-synsights.svc:9091'
monitoring_enabled: true
charts:
Expand Down
26 changes: 24 additions & 2 deletions component/monitoring.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,29 @@ local service_monitor = com.namespaced(params.namespace, {
},
});

local alert_selector(filters) =
local op = {
exclude: '!=',
exclude_re: '!~',
match: '=',
match_re: '=~',
};
local selector(sel) = [
{
op: op[s],
val: sel[s],
}
for s in std.objectFields(sel)
];
if filters != null then
local selectors = std.mapWithKey(
function(key, sel) ([ '%s%s"%s"' % [ key, s.op, s.val ] for s in selector(sel) ]),
filters
);
std.join(',', std.flattenArrays([ selectors[f] for f in std.objectFields(selectors) ]))
else
'';

local alert_rules = com.namespaced(params.namespace, {
apiVersion: 'monitoring.coreos.com/v1',
kind: 'PrometheusRule',
Expand All @@ -50,8 +73,7 @@ local alert_rules = com.namespaced(params.namespace, {
annotations: {
message: 'Last backup for PVC {{ $labels.pvc }} in namespace {{ $labels.instance }} had {{ $value }} errors',
},
expr: 'baas_backup_restic_last_errors{%s} > 0' %
com.getValueOrDefault(params.alert_rule_filters, 'namespace', ''),
expr: 'baas_backup_restic_last_errors{%s} > 0' % alert_selector(params.alert_rule_filters),
'for': '1m',
labels: {
severity: 'critical',
Expand Down