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

feat: topk check #985

Closed
wants to merge 6 commits into from
Closed

Conversation

wbollock
Copy link

This adds a new check to warn against the use of topk or bottomk in
recording rules. This is an anti-pattern as these operators lead to high
churn as the time series the recording rule generates will change
frequently as the conditions for topk/bottomk adjust.

It is enabled by default with a warning severity. It will only fire for
recording rules, not alerting rules.

Resolves #820

This adds a new check to warn against the use of `topk` or `bottomk` in
recording rules. This is an anti-pattern as these operators lead to high
churn as the time series the recording rule generates will change
frequently as the conditions for topk/bottomk adjust.

It is enabled by default with a warning severity. It will only fire for
recording rules, not alerting rules.

Resolves cloudflare#820
@wbollock wbollock requested a review from prymitive as a code owner May 24, 2024 15:36
@wbollock wbollock marked this pull request as draft May 24, 2024 15:40
@wbollock wbollock marked this pull request as ready for review May 24, 2024 16:22
a simple regex will correctly capture usage as a function better
@prymitive
Copy link
Collaborator

prymitive commented May 29, 2024

There is nothing wrong with using topk() in rules as long as the rule doesn't just return topk() results verbatim. Consider this query: min(topk(10, ...)) > 5000 it returns no labels and so will produce stable results.
Just looking for any topk use in a query is not enough to produce useful results here.

On top of that this code uses regex matchers to find uses of topk string, instead of looking for actual usage of topk() function using the AST. That's fragile and prone to false positives so sorry, but I won't be adding it.

@wbollock
Copy link
Author

wbollock commented Jun 4, 2024

no worries, that makes sense. thanks for looking

@wbollock wbollock closed this Jun 4, 2024
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.

Add pint check to disallow topk or bottomk in recording rules
2 participants