Skip to content
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
/_public

# Additional entries
jsonnetfile.json
48 changes: 18 additions & 30 deletions component/alertrules.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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 }}
Expand All @@ -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 }}
Expand All @@ -59,36 +50,33 @@ local alertrules = {
'for': '1h',
labels: {
severity: 'warning',
syn: 'true',
syn_component: 'topolvm',
},
},
],
},
],
};

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') {
{
Comment thread
simu marked this conversation as resolved.
Resolved
[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',
{}
)
}
19 changes: 19 additions & 0 deletions docs/modules/ROOT/pages/references/parameters.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
16 changes: 16 additions & 0 deletions jsonnetfile.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
version: 1,
dependencies: [
{
source: {
git: {
remote: 'https://github.com/projectsyn/jsonnet-libs',
subdir: '',
},
},
version: 'main',
name: 'syn',
},
],
legacyImports: true,
}
7 changes: 1 addition & 6 deletions tests/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions tests/legacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ""
Expand Down
17 changes: 12 additions & 5 deletions tests/noalertrules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading