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

Create Github actions to validate Loki and Promtail rules #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

the-smooth-operator
Copy link
Contributor

This Pull Requests adds 4 Github Actions for validating the syntax of Loki and Promtail recording and alerting rules.
Also sets the ground work for adding more test in the future.

I've tested the behavior and works well, failing when there are invalid rules and succeeding when they are valid.

@the-smooth-operator the-smooth-operator requested a review from a team September 6, 2021 10:13
run: mkdir -p validation/recording-rules

- name: Generate Loki recording rules
run: yq e '.spec' loki/recording-rules.yaml > validation/recording-rules/rules.yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this included by default in ubuntu-latest?

Copy link
Contributor

@biwwy0 biwwy0 Sep 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we wrap all rules in simple for loop in run: instead of creating 4 actions for different directories? Not sure how this will grow and if there will be more places where we'd add rules that need to be checked, which would require having to add them to github actions steps as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this included by default in ubuntu-latest?

It is included in Ubuntu latest. Otherwise it would not have worked

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we wrap all rules in simple for loop in run: instead of creating 4 actions for different directories? Not sure how this will grow and if there will be more places where we'd add rules that need to be checked, which would require having to add them to github actions steps as well.

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:

image

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.

if there will be more places where we'd add rules that need to be checked, which would require having to add them to github actions steps as well.

Even in the for loop case, when you add a new file, you need to add the filename to the for loop.
Unless we add even more logic for finding files with rules. That sounds like a lot of bash and complexity unneeded.

Anyway, I think you point in a valid one. Let's see what others think and reach consensus. I'm open to modify this.

Copy link
Contributor

Choose a reason for hiding this comment

The 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.
How about the idea at https://github.com/grafana/cortex-rules-action#pull-request-diff where it comments on the PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok 2 against 1, we have majority.
I'm going to test how to get all rules tested in one step in an elegant way. I'll give a try to the comments in the PR too.

Copy link
Contributor

@james-callahan james-callahan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run: mkdir -p validation/recording-rules

- name: Generate Loki recording rules
run: yq e '.spec' loki/recording-rules.yaml > validation/recording-rules/rules.yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What yq invocation is this?
Generally at BitGo we assume yq is https://github.com/kislyuk/yq, rather than http://mikefarah.github.io/yq/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took my some time to figure out that the yq included in Ubuntu is coming from http://mikefarah.github.io/yq/ so it has a slightly different syntax.

I'd favor using a different yq implementation which comes already with Ubuntu rather than installing another package for simplicity.


- name: Create tmp dir
run: mkdir -p validation/recording-rules

Copy link
Contributor

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.

- name: Lint rules
uses: grafana//cortex-rules-action@v0.8.0
env:
ACTION: lint
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lint

Lints a rules file(s). The linter's aim is not to verify correctness but to fix YAML and PromQL expression formatting within the rule file(s). The linting happens in-place within the specified file(s). Does not interact with your Cortex cluster.

I'm not sure linting here makes sense?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However it won't hurt IMO.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may: e.g. if it reformats the file; then the following check will have warnings with the wrong line numbers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants