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

Add id-labels flag #3

Merged
merged 5 commits into from
Aug 28, 2023
Merged

Add id-labels flag #3

merged 5 commits into from
Aug 28, 2023

Conversation

gbbirkisson
Copy link

@gbbirkisson gbbirkisson commented Aug 27, 2023

Add flag to set global id-labels on generated recording and alert rules:

$ sloth generate -i slo.yaml --id-labels=env=dev

These labels will be used for generated queries and added as labels as well. This will result in recording rules looking like this:

expr: |
  slo:sli_error:ratio_rate5m{env="dev", sloth_id="???", sloth_service="???", sloth_slo="???"}
  / on(sloth_id, sloth_slo, sloth_service) group_left
  slo:error_budget:ratio{env="dev", sloth_id="???", sloth_service="???", sloth_slo="???"}
labels:
  env: dev
  sloth_id: ???
  sloth_service: ???
  sloth_slo: ???

Alerts will also inherit these id labels:

alert: Alertname
expr: |
  (
      max(slo:sli_error:ratio_rate5m{env="dev", sloth_id="???", sloth_service="???", sloth_slo="???"} > (14.4 * 0.9)) without (sloth_window)
      and
      max(slo:sli_error:ratio_rate1h{env="dev", sloth_id="???", sloth_service="???", sloth_slo="???"} > (14.4 * 0.9)) without (sloth_window)
  )
  or
  (
      max(slo:sli_error:ratio_rate30m{env="dev", sloth_id="???", sloth_service="???", sloth_slo="???"} > (6 * 0.9)) without (sloth_window)
      and
      max(slo:sli_error:ratio_rate6h{env="dev", sloth_id="???", sloth_service="???", sloth_slo="???"} > (6 * 0.9)) without (sloth_window)
  )
labels:
  env: dev

@gbbirkisson gbbirkisson self-assigned this Aug 27, 2023
Copy link

@thor thor left a comment

Choose a reason for hiding this comment

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

SGTM. Tempted to create a separate struct for handling the labels as extra labels and ID labels seem to go together most of the time, but I don't think that's a blocker here. 🚀

@torvald torvald self-requested a review August 28, 2023 07:17
Copy link

@torvald torvald left a comment

Choose a reason for hiding this comment

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

Nice! This will do! It will not fix the issue were the tier label changes, I think, I presume we need to alter the queries for that, ignoring tier, or a set of ignoreLabels. But one thing at a time. 👏 :shipit:

@gbbirkisson gbbirkisson merged commit cb76276 into main Aug 28, 2023
24 checks passed
@gbbirkisson gbbirkisson deleted the gbbirkisson/id-labels branch August 28, 2023 10:04
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.

3 participants