fix(ci): split rule groups into seperate files (#368)

- mitigate an issue that command line is too long for
  liquid-cli
This commit is contained in:
Roman Pertl 2023-07-15 18:05:25 +02:00 committed by GitHub
parent 68d45a0856
commit 0eb66a5d2c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 38 deletions

View file

@ -25,13 +25,27 @@ jobs:
run: |
gem install liquid-cli
cat _data/rules.yml | yq -I 0 -o json > _data/rules.json
cat test/template.yml | liquid "$(< _data/rules.json)" > test/rules.yml
for service in $(cat _data/rules.json | jq -r '.groups[].services[] | @base64'); do
subdir=test/rules/$(echo ${service} | base64 --decode | jq -r '.name | ascii_downcase | split(" ") | join("-")')
mkdir -p "${subdir}"
# groupName=$(echo "{% assign groupName = name | split: ' ' %}{% capture groupNameCamelcase %}{% for word in groupName %}{{ word | capitalize }} {% endfor %}{% endcapture %} {{ groupNameCamelcase | remove: ' ' | remove: '-' }}" | liquid $(echo ${service} | base64 --decode | jq -r '.name | ascii_downcase | split(" ") | join("-")'))
for exporter in $(echo ${service} | base64 --decode | jq -r '.exporters[] | @base64'); do
exporterName=$(echo ${exporter} | base64 --decode | jq -r '.slug')
cat dist/template.yml | liquid "$(echo ${exporter} | base64 --decode)" > ${subdir}/${exporterName}.yml
echo ${subdir}/${exporterName}.yml
done
done
rm _data/rules.json
- name: Check Prometheus alert rules
uses: peimanja/promtool-github-actions@master
with:
promtool_actions_subcommand: 'rules'
promtool_actions_files: 'test/rules.yml'
promtool_actions_files: 'test/rules/*/*.yml'
promtool_actions_comment: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

2
.gitignore vendored
View file

@ -3,4 +3,4 @@ _site/
.jekyll-cache/
.jekyll-metadata
_data/rules.json
test/rules.yml
test/rules/

View file

@ -1,17 +0,0 @@
Since some rules can be duplicated (multiple exporters), I added a prefix to rule name.
Error:
```
$ promtool check rules test/rules.yml
Checking rules.yml
29 duplicate rule(s) found.
Metric: CassandraClientRequestReadFailure
Label(s):
severity: critical
[...]
Might cause inconsistency while recording expressions.
```

View file

@ -1,18 +0,0 @@
groups:
- name: AllRules
rules:
{% for group in groups %}{% assign groupIndex = forloop.index %}{% for service in group.services %}{% assign serviceIndex = forloop.index %}{% for exporter in service.exporters %}{% assign exporterIndex = forloop.index %}{% for rule in exporter.rules %}
{% assign ruleName = rule.name | split: ' ' %}{% capture ruleNameCamelcase %}{% for word in ruleName %}{{ word | capitalize }} {% endfor %}{% endcapture %}
{% for comment in comments %}# {{ comment | strip }}
{% endfor %}- alert: {{ groupIndex }}_{{ serviceIndex }}_{{ exporterIndex }}_{{ ruleNameCamelcase | remove: ' ' }}
expr: '{{ rule.query }}'
for: {% if rule.for %}{{ rule.for }}{% else %}0m{% endif %}
labels:
severity: {{ rule.severity }}
annotations:
summary: {{ rule.name }} (instance {% raw %}{{ $labels.instance }}{% endraw %})
description: "{{ rule.description | replace: '"', '\"' }}\n VALUE = {% raw %}{{ $value }}{% endraw %}\n LABELS = {% raw %}{{ $labels }}{% endraw %}"
{% endfor %}{% endfor %}{% endfor %}{% endfor %}