Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameter alerts.excludeNamespaces to exclude specific namespaces from base alerts #186

Merged
merged 1 commit into from
Oct 18, 2023
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 class/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ parameters:
- kube-.*
- openshift-.*
- syn.*
excludeNamespaces: []
ignoreNames:
- AlertmanagerReceiversNotConfigured
- CannotRetrieveUpdates
Expand Down
21 changes: 20 additions & 1 deletion component/rules.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,30 @@ local annotateRules = {
local renderedNamespaceSelector =
std.join('|', com.renderArray(params.alerts.includeNamespaces));

local renderedExcludesSelector =
std.join('|', com.renderArray(params.alerts.excludeNamespaces));

local renderedSelector =
local hasNsSel = std.length(renderedNamespaceSelector) > 0;
local hasExcSel = std.length(renderedExcludesSelector) > 0;
(
if hasNsSel then
'namespace=~"(%s)"' % renderedNamespaceSelector
else ''

) + (
if hasNsSel && hasExcSel then ',' else ''
) + (
if std.length(renderedExcludesSelector) > 0 then
'namespace!~"(%s)"' % renderedExcludesSelector
else ''
);

local patchExpr(expr) =
std.strReplace(
expr,
'namespace=~"(openshift-.*|kube-.*|default)"',
'namespace=~"(%s)"' % renderedNamespaceSelector
renderedSelector
);

local rulePatches =
Expand Down
32 changes: 31 additions & 1 deletion docs/modules/ROOT/pages/references/parameters.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ default:: https://github.com/appuio/component-openshift4-monitoring/blob/master/

List of namespace patterns to use for alerts which have `namespace=~"(openshift-.\*|kube-.*|default)"` in the upstream rule.
The component generates a regex pattern from the list by concatenating all elements into a large OR-regex.
To inject the custom regex, the component searches for the exact string `namespace=~"(openshift-.\*|kube-.*|default)"` in field `expr` of each alert rule and replaces it with the regex generated from the parameter.
To inject the custom regex, the component searches for the exact string `namespace=~"(openshift-.\*|kube-.*|default)"` in field `expr` of each alert rule and replaces it with the regex generated from this parameter and parameter `excludeNamespaces`.

The component processes the list with `com.renderArray()` to allow users to drop entries in the hierarchy.

Expand All @@ -372,6 +372,36 @@ includeNamespaces:

The component will generate namespace selector `namespace=~"(default|syn.*)"` from this input configuration.

=== `excludeNamespaces`

[horizontal]
type:: list
default:: `[]`

List of namespace patterns to exclude for alerts which have `namespace=~"(openshift-.\*|kube-.*|default)"` in the upstream rule.
The component generates a regex pattern from the list by concatenating all elements into a large OR-regex.
To inject the custom regex, the component searches for the exact string `namespace=~"(openshift-.\*|kube-.*|default)"` in field `expr` of each alert rule and replaces it with the regex generated from this parameter and parameter `includeNamespaces`.

The component processes the list with `com.renderArray()` to allow users to drop entries in the hierarchy.

IMPORTANT: The component doesn't validate that the list entries are valid regex patterns.

==== Example

We assume that the input config has patterns `default` and `openshift.*` and `syn.*` for `includeNamespaces` and `openshift-adp` for `excludeNamespaces`:

[source,yaml]
----
includeNamespaces:
- default
- openshift.*
- syn.*
excludeNamespaces:
- openshift-adp
----

The component will generate namespace selector `namespace=~"(default|openshift.*|syn.*)",namespace!~"(openshift-adp)"` from this input configuration.

=== `ignoreNames`

[horizontal]
Expand Down
2 changes: 2 additions & 0 deletions tests/custom-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ parameters:
manifests_version: release-4.13

alerts:
excludeNamespaces:
- openshift-adp
patchRules:
'*':
HighOverallControlPlaneMemory:
Expand Down
Loading
Loading