From 9ec884312d99d6543013b63eef72012cc1641f32 Mon Sep 17 00:00:00 2001 From: Debakel Orakel Date: Fri, 11 Sep 2026 09:33:50 +0200 Subject: [PATCH] Refactor component to use `projectsyn/jsonnet-libs`'s `alerts.libsonnet` We've moved the core logic of openshift4-monitoring-alert-patching.libsonnet and prom.generateRules() to projectsyn/jsonnet-libs (cf. projectsyn/jsonnet-libs#13). This commit updates the compnent to use that generic library. --- .gitignore | 1 + component/alertrules.jsonnet | 48 +++++++------------ .../ROOT/pages/references/parameters.adoc | 19 ++++++++ jsonnetfile.jsonnet | 16 +++++++ tests/defaults.yml | 7 +-- tests/legacy.yml | 7 +-- tests/noalertrules.yml | 17 +++++-- 7 files changed, 68 insertions(+), 47 deletions(-) create mode 100644 jsonnetfile.jsonnet diff --git a/.gitignore b/.gitignore index 0683651..b223314 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ /_public # Additional entries +jsonnetfile.json diff --git a/component/alertrules.jsonnet b/component/alertrules.jsonnet index 1482fb8..40de267 100644 --- a/component/alertrules.jsonnet +++ b/component/alertrules.jsonnet @@ -5,13 +5,6 @@ local kube = import 'lib/kube.libjsonnet'; local inv = kap.inventory(); local params = inv.parameters.topolvm; -local isOpenshift = std.startsWith(inv.parameters.facts.distribution, 'openshift'); - -assert - std.member(inv.applications, 'openshift4-monitoring') || - isOpenshift != true - : 'Component openshift4-monitoring is not available'; - // Upstream alerts to ignore local ignore_alerts = std.set( // Add set of alerts that should be ignored from `params.ignore_alerts` @@ -24,7 +17,7 @@ local alertrules = { name: 'topolvm-alert.rules', rules: [ { - alert: 'SYN_TopoLVMVolumeGroupAlmostFull', + alert: 'TopoLVMVolumeGroupAlmostFull', annotations: { description: ||| Utilization of volume group {{ $labels.device_class }} @@ -39,12 +32,10 @@ local alertrules = { 'for': '10m', labels: { severity: 'warning', - syn: 'true', - syn_component: 'topolvm', }, }, { - alert: 'SYN_TopoLVMVolumeGroupNearFull', + alert: 'TopoLVMVolumeGroupNearFull', annotations: { description: ||| Utilization of volume group {{ $labels.device_class }} @@ -59,8 +50,6 @@ local alertrules = { 'for': '1h', labels: { severity: 'warning', - syn: 'true', - syn_component: 'topolvm', }, }, ], @@ -68,27 +57,26 @@ local alertrules = { ], }; +local groups = std.filter( + function(g) std.length(g.rules) > 0, + [ + alertpatching.filterPatchRules(g, ignoreNames=ignore_alerts) + for g in alertrules.groups + ] +); + +local has_monitoring = std.member(inv.applications, 'prometheus') || std.member(inv.applications, 'openshift4-monitoring'); +local has_alerts = std.length(groups) > 0; + // Define outputs below -if isOpenshift then - { - '20_rules': kube._Object('monitoring.coreos.com/v1', 'PrometheusRule', 'syn-topolvm-rules') { +{ + [if has_monitoring && has_alerts then '20_rules']: + kube._Object('monitoring.coreos.com/v1', 'PrometheusRule', 'syn-topolvm-rules') { metadata+: { namespace: params.namespace, }, spec: { - groups: std.filter( - function(it) it != null, - [ - local r = alertpatching.filterPatchRules(g, ignore_alerts); - if std.length(r.rules) > 0 then r - for g in alertrules.groups - ] - ), + groups: groups, }, }, - } -else - std.trace( - 'Alert handling library not available, not deploying alertrules', - {} - ) +} diff --git a/docs/modules/ROOT/pages/references/parameters.adoc b/docs/modules/ROOT/pages/references/parameters.adoc index be7f5b6..1d0c3e9 100644 --- a/docs/modules/ROOT/pages/references/parameters.adoc +++ b/docs/modules/ROOT/pages/references/parameters.adoc @@ -89,6 +89,25 @@ parameters: volumeexpansion: true ---- +== `ignore_alerts` + +[horizontal] +type:: list +default:: [] + +List of alert rule names to be dropped. +Names are given without the `SYN_` prefix. + +=== Example + +[source,yaml] +---- +parameters: + topolvm: + ignore_alerts: + - TopoLVMVolumeGroupNearFull +---- + == `helmValues` [horizontal] diff --git a/jsonnetfile.jsonnet b/jsonnetfile.jsonnet new file mode 100644 index 0000000..b09f90e --- /dev/null +++ b/jsonnetfile.jsonnet @@ -0,0 +1,16 @@ +{ + version: 1, + dependencies: [ + { + source: { + git: { + remote: 'https://github.com/projectsyn/jsonnet-libs', + subdir: '', + }, + }, + version: 'main', + name: 'syn', + }, + ], + legacyImports: true, +} diff --git a/tests/defaults.yml b/tests/defaults.yml index 821b2b2..ddbcc8f 100644 --- a/tests/defaults.yml +++ b/tests/defaults.yml @@ -9,17 +9,12 @@ parameters: source: https://raw.githubusercontent.com/projectsyn/component-storageclass/v1.0.0/lib/storageclass.libsonnet output_path: vendor/lib/storageclass.libsonnet - type: https - source: https://raw.githubusercontent.com/appuio/component-openshift4-monitoring/v2.9.0/lib/openshift4-monitoring-alert-patching.libsonnet + source: https://raw.githubusercontent.com/appuio/component-openshift4-monitoring/master/lib/openshift4-monitoring-alert-patching.libsonnet output_path: vendor/lib/alert-patching.libsonnet facts: distribution: openshift4 - openshift4_monitoring: - alerts: - ignoreNames: [] - customAnnotations: {} - storageclass: defaults: {} defaultClass: ssd-local diff --git a/tests/legacy.yml b/tests/legacy.yml index 8f7cf2f..06b0ce2 100644 --- a/tests/legacy.yml +++ b/tests/legacy.yml @@ -9,17 +9,12 @@ parameters: source: https://raw.githubusercontent.com/projectsyn/component-storageclass/v1.0.0/lib/storageclass.libsonnet output_path: vendor/lib/storageclass.libsonnet - type: https - source: https://raw.githubusercontent.com/appuio/component-openshift4-monitoring/v2.9.0/lib/openshift4-monitoring-alert-patching.libsonnet + source: https://raw.githubusercontent.com/appuio/component-openshift4-monitoring/master/lib/openshift4-monitoring-alert-patching.libsonnet output_path: vendor/lib/alert-patching.libsonnet facts: distribution: openshift4 - openshift4_monitoring: - alerts: - ignoreNames: [] - customAnnotations: {} - storageclass: defaults: {} defaultClass: "" diff --git a/tests/noalertrules.yml b/tests/noalertrules.yml index 1a65979..ca38bc6 100644 --- a/tests/noalertrules.yml +++ b/tests/noalertrules.yml @@ -8,15 +8,22 @@ parameters: - type: https source: https://raw.githubusercontent.com/projectsyn/component-storageclass/v1.0.0/lib/storageclass.libsonnet output_path: vendor/lib/storageclass.libsonnet + - type: https + source: https://raw.githubusercontent.com/projectsyn/component-prometheus/master/lib/prometheus-alert-patching.libsonnet + output_path: vendor/lib/alert-patching.libsonnet facts: distribution: eks - openshift4_monitoring: - alerts: - ignoreNames: [] - customAnnotations: {} - storageclass: defaults: {} defaultClass: "" + + prometheus: + alerts: + ignoreNames: + - TopoLVMVolumeGroupAlmostFull + + topolvm: + ignore_alerts: + - TopoLVMVolumeGroupNearFull