-
Notifications
You must be signed in to change notification settings - Fork 13
Create Github actions to validate Loki and Promtail rules #32
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
on: pull_request | ||
permissions: | ||
contents: read | ||
pull-requests: read | ||
jobs: | ||
validate_loki_recording_rules: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Create tmp dir | ||
run: mkdir -p validation/recording-rules | ||
|
||
- name: Generate Loki recording rules | ||
run: yq e '.spec' loki/recording-rules.yaml > validation/recording-rules/rules.yaml | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this included by default in ubuntu-latest? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we wrap all rules in simple for loop in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It is included in Ubuntu latest. Otherwise it would not have worked There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I like the idea of having separate jobs for separate files. This allows, when a job fails, to know what is broken looking at the action name. See this screenshot for an example: Other issue with wrapping in into a loop, is that it will require adding more bash. I'd try to use as less bash as possible to simplify maintenance.
Even in the for loop case, when you add a new file, you need to add the filename to the for loop. Anyway, I think you point in a valid one. Let's see what others think and reach consensus. I'm open to modify this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I'd like the one step so that we can make this cover all rules automatically. However I agree with making what failed more obvious. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok 2 against 1, we have majority. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It took my some time to figure out that the I'd favor using a different |
||
|
||
- name: Lint rules | ||
uses: grafana//[email protected] | ||
env: | ||
ACTION: lint | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm not sure linting here makes sense? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. However it won't hurt IMO. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It may: e.g. if it reformats the file; then the following |
||
RULES_DIR: validation/recording-rules/ | ||
|
||
- name: Check rules | ||
uses: grafana//[email protected] | ||
env: | ||
ACTION: check | ||
RULES_DIR: validation/recording-rules/ | ||
|
||
validate_loki_alerting_rules: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Create tmp dir | ||
run: mkdir -p validation/alerting-rules | ||
|
||
- name: Generate Loki alerting rules | ||
run: yq e '.spec' loki/alerting-rules.yaml > validation/alerting-rules/rules.yaml | ||
|
||
- name: Lint rules | ||
uses: grafana//[email protected] | ||
env: | ||
ACTION: lint | ||
RULES_DIR: validation/alerting-rules/ | ||
|
||
- name: Check rules | ||
uses: grafana//[email protected] | ||
env: | ||
ACTION: check | ||
RULES_DIR: validation/alerting-rules/ | ||
|
||
validate_promtail_recording_rules: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Create tmp dir | ||
run: mkdir -p validation/recording-rules | ||
|
||
- name: Generate Loki recording rules | ||
run: yq e '.spec' promtail/recording-rules.yaml > validation/recording-rules/rules.yaml | ||
|
||
- name: Lint rules | ||
uses: grafana//[email protected] | ||
env: | ||
ACTION: lint | ||
RULES_DIR: validation/recording-rules/ | ||
|
||
- name: Check rules | ||
uses: grafana//[email protected] | ||
env: | ||
ACTION: check | ||
RULES_DIR: validation/recording-rules/ | ||
|
||
validate_promtail_alerting_rules: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Create tmp dir | ||
run: mkdir -p validation/alerting-rules | ||
|
||
- name: Generate Loki alerting rules | ||
run: yq e '.spec' promtail/alerting-rules.yaml > validation/alerting-rules/rules.yaml | ||
|
||
- name: Lint rules | ||
uses: grafana//[email protected] | ||
env: | ||
ACTION: lint | ||
RULES_DIR: validation/alerting-rules/ | ||
|
||
- name: Check rules | ||
uses: grafana//[email protected] | ||
env: | ||
ACTION: check | ||
RULES_DIR: validation/alerting-rules/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider a step like
kustomize build . | kustomize cfg grep kind=PrometheusRule | kustomize cfg merge validation/recording-rules
This would not only test that the kustomization is valid; but it would apply any patches we decide to include in the repository.