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

ruler: add filtering support for prometheus rules api #11817

Merged
merged 6 commits into from Feb 5, 2024

Conversation

ashwanthgoli
Copy link
Contributor

@ashwanthgoli ashwanthgoli commented Jan 29, 2024

What this PR does / why we need it:
Adds rule_name, rule_group, file and type query parameters for filtering the response of /prometheus/api/v1/rules endpoint. Replicates mimir's functionality: grafana/mimir#5291

  • all of them are optional.
  • type paremeter accepts either alert or record
  • rule_name, rule_group, file can accept multiple values and they filter the response accordingly.

There is a minor change in behavior: /prometheus/api/v1/rules endpoint will no longer return empty rule groups which is inline with both prometheus and mimir. This is not a breaking change since rule groups with no rules fail validation and cannot be created.

Which issue(s) this PR fixes:
Fixes #9295

Special notes for your reviewer:

Checklist

  • Reviewed the CONTRIBUTING.md guide (required)
  • Documentation added
  • Tests updated
  • CHANGELOG.md updated
    • If the change is worth mentioning in the release notes, add add-to-release-notes label
  • Changes that require user attention or interaction to upgrade are documented in docs/sources/setup/upgrade/_index.md
  • For Helm chart changes bump the Helm chart version in production/helm/loki/Chart.yaml and update production/helm/loki/CHANGELOG.md and production/helm/loki/README.md. Example PR
  • If the change is deprecating or removing a configuration option, update the deprecated-config.yaml and deleted-config.yaml files respectively in the tools/deprecated-config-checker directory. Example PR

@github-actions github-actions bot added the type/docs Issues related to technical documentation; the Docs Squad uses this label across many repositories label Jan 30, 2024
@ashwanthgoli ashwanthgoli changed the title ruler: add filtering support by file/group/rule ruler: add filtering support for prometheus rules api Jan 30, 2024
@ashwanthgoli ashwanthgoli marked this pull request as ready for review January 30, 2024 07:55
@ashwanthgoli ashwanthgoli requested a review from a team as a code owner January 30, 2024 07:55
@ashwanthgoli ashwanthgoli force-pushed the ashwanth/rules-api-support-filters branch from 27fbd62 to 8add210 Compare January 30, 2024 11:06
Copy link
Collaborator

@kavirajk kavirajk left a comment

Choose a reason for hiding this comment

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

LGTM. just one minor recommendation. 👍


func (r *Ruler) getLocalRules(userID string, req *RulesRequest) ([]*GroupStateDesc, error) {
var (
getRecordingRules = true
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would prefer to create and switch these flags more direct way.

  1. start with both false.
  2. case AlertingRule => alertRule=true
  3. case RecordingRule => recordingRule=true
  4. case AnyRule => alerRule=true; recordingRule=true

This way it's more intuitive IMHO.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also one other question. Do you think we also should support exclude_alerts=<bool>, just like prometheus rules endpoint does.
https://prometheus.io/docs/prometheus/latest/querying/api/#rules

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i'll add exclude_alerts in a follow-up

Copy link
Collaborator

@kavirajk kavirajk left a comment

Choose a reason for hiding this comment

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

Nice work 👍

@ashwanthgoli ashwanthgoli merged commit 69919a3 into main Feb 5, 2024
9 checks passed
@ashwanthgoli ashwanthgoli deleted the ashwanth/rules-api-support-filters branch February 5, 2024 10:32
rhnasc pushed a commit to inloco/loki that referenced this pull request Apr 12, 2024
**What this PR does / why we need it**:
Adds `rule_name`, `rule_group`, `file` and `type` query parameters for
filtering the response of `/prometheus/api/v1/rules` endpoint.
Replicates mimir's functionality:
grafana/mimir#5291

- all of them are optional.
- `type` paremeter accepts either `alert` or `record`
- `rule_name`, `rule_group`, `file` can accept multiple values and they
filter the response accordingly.




There is a minor change in behavior: `/prometheus/api/v1/rules` endpoint
will no longer return empty rule groups which is inline with both
[prometheus](https://github.com/prometheus/prometheus/pull/12270/files#diff-315f251cdd7e93fcec1e7e9505744da1d1828f30d2b61d1f4ce963fa26bf1909R1403)
and
[mimir](https://github.com/grafana/mimir/pull/5291/files#diff-e5424c21c0e827bd1c9d3f669ed605897696bdc27993bc8bfd7113eba787b49dR1120).
This is not a breaking change since rule groups with [no rules fail
validation](https://github.com/grafana/loki/blob/27fbd62505f4412e3cb9180b1a5a66518bba9752/pkg/ruler/base/manager.go#L295)
and cannot be created.

**Which issue(s) this PR fixes**:
Fixes grafana#9295

**Special notes for your reviewer**:

**Checklist**
- [x] Reviewed the
[`CONTRIBUTING.md`](https://github.com/grafana/loki/blob/main/CONTRIBUTING.md)
guide (**required**)
- [x] Documentation added
- [x] Tests updated
- [x] `CHANGELOG.md` updated
- [ ] If the change is worth mentioning in the release notes, add
`add-to-release-notes` label
- [ ] Changes that require user attention or interaction to upgrade are
documented in `docs/sources/setup/upgrade/_index.md`
- [ ] For Helm chart changes bump the Helm chart version in
`production/helm/loki/Chart.yaml` and update
`production/helm/loki/CHANGELOG.md` and
`production/helm/loki/README.md`. [Example
PR](grafana@d10549e)
- [ ] If the change is deprecating or removing a configuration option,
update the `deprecated-config.yaml` and `deleted-config.yaml` files
respectively in the `tools/deprecated-config-checker` directory.
[Example
PR](grafana@0d4416a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/XXL type/docs Issues related to technical documentation; the Docs Squad uses this label across many repositories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement filters for the Ruler api/v1/rules prometheus compatible API
2 participants