Skip to content
Open
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
54 changes: 54 additions & 0 deletions .github/workflows/alerts-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Alerts-test-pgskipper-operator
on:
workflow_run:
workflows: ["Build Artifacts"]
types:
- completed
pull_request:
branches:
- all

env:
max_attempts: 30
delay: 10

permissions:
contents: read

jobs:
Run-Alerts-Test:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Check out repository code
uses: actions/checkout@v4

- name: Check yq version
run: yq --version

- name: Install Helm
run: |
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash

- name: Render rules file from helm chart
run: |
helm template pgskipper-montemplates ./charts/patroni-services/. --set metricCollector.install=true --set metricCollector.metricsProfile=dev --set metricCollector.prometheusMonitoring=true --set siteManager.install=true > ./tests/alerts-tests/rules.yaml
sed -n '/prometheus-rule.yml/,/---/p' -i ./tests/alerts-tests/rules.yaml
sed '0,/spec:/d' -i ./tests/alerts-tests/rules.yaml

- name: Check that all necessary tests exists
run: |
chmod +x ./tests/alerts-tests/tests-checker.sh
cd ./tests/alerts-tests/
./tests-checker.sh
continue-on-error: true

- name: Install vmalert-tool
run: |
wget https://github.com/VictoriaMetrics/VictoriaMetrics/releases/download/v1.122.4/vmutils-linux-amd64-v1.122.4-enterprise.tar.gz
tar -xvf vmutils-linux-amd64-v1.122.4-enterprise.tar.gz
chmod +x vmalert-tool-prod

- name: Run test
run: |
./vmalert-tool-prod unittest --files ./tests/alerts-tests/test.yaml
8 changes: 8 additions & 0 deletions charts/patroni-services/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ version: 0.1.0
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application.
appVersion: 1.16.0

dependencies:
# Prometheus alert rules
- name: metricCollector
condition: metricCollector.prometheusMonitoring
version: ~0
repository: "file://charts/metricCollector"

24 changes: 24 additions & 0 deletions charts/patroni-services/charts/metricCollector/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: metricCollector
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"
483 changes: 483 additions & 0 deletions charts/patroni-services/charts/metricCollector/templates/_helpers.tpl

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{{- if and (eq .Values.alertsPackVersion "v2") .Values.prometheusMonitoring }}
apiVersion: operator.victoriametrics.com/v1beta1
kind: VMRule
metadata:
name: prometheusrules
spec:
groups:

{{- $defaultConfig := fromYaml (include "defaultAlerts" . ) -}}
{{- $overrideConfig := .Values.alerts -}}
{{- $finalConfig := merge $overrideConfig $defaultConfig -}}
{{- $alertGroups := .Values.ruleGroups -}}

{{- range $defaultGroupName, $defaultGroup := $finalConfig }}
{{- $found := true }}
{{- if $alertGroups }}
{{- $found := false }}
{{- range $alertGroups }}
{{- if eq $defaultGroupName . }}
{{- $found := true }}
{{- end }}
{{- end }}
{{- else }}
{{- $found := true }}
{{- end }}

{{- if $found }}
- name: {{ $defaultGroupName }}
{{- if $defaultGroup.labels }}
labels:
{{- range $defaultLabelName, $defaultLabelValue := $defaultGroup.labels }}
{{ $defaultLabelName }}: {{ $defaultLabelValue }}
{{- end }}
{{- end }}
{{- if $defaultGroup.interval }}
interval: {{ $defaultGroup.interval }}
{{- end }}
{{- if $defaultGroup.concurrency }}
concurrency: {{ $defaultGroup.concurrency }}
{{- end }}
rules:
{{- range $defaultRuleName, $defaultRule := $defaultGroup.rules }}
- alert: {{ $defaultRuleName }}
expr: {{ $defaultRule.expr }}
{{- if $defaultRule.for }}
for: {{ $defaultRule.for }}
{{- end }}
labels:
{{- range $defaultLabelName, $defaultLabelValue := $defaultRule.labels }}
{{ $defaultLabelName }}: {{ $defaultLabelValue }}
{{- end }}
annotations:
{{- range $defaultAnnotationName, $defaultAnnotationValue := $defaultRule.annotations }}
{{ $defaultAnnotationName }}: {{ printf $defaultAnnotationValue | trimAll "\n" | toJson | replace "\\u0026" "&" | replace "\\u003e" ">" | nindent 14 }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
Empty file.
Loading