Skip to content

Units larger than h in GrafanaAlertRuleGroup#.spec.rules[*].for are rejected on apply #2189

@Baarsgaard

Description

@Baarsgaard

Describe the bug
When exporting Alerts and AlertGroups from Grafana in order to populate a GrafanaAlertRuleGroup CR, we see that when specific values are picked for pending period( .spec.rules[*].for) like 24h, Grafana will export it as 1d.
At the time of writing, years, weeks, and days are not supported in the .spec.rules[*].for field.

Version
v5.19.4

To Reproduce
Steps to reproduce the behavior:

  1. Open a Grafana v11.5.3 or later
  2. Create or modify an alert rule
  3. Set the pending period to 24h
  4. Save and Export the alert, notice it should have converted the pending period to 1d
  5. Apply the rule as a CRD
  6.  # grafanaalertrulegroups.grafana.integreatly.org "grafana-health" was not valid:
     # * spec.rules[0].for: Invalid value: "1d": spec.rules[0].for in body should match '^([0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$'
    

Expected behavior
Following the above steps, the CRD should be succesfully applied and synchronized with matching instances.

Suspect component/Location where the bug might be occurring

// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$"

Runtime (please complete the following information):

  • OS: Linux
  • Grafana Operator Version: v5.19.4
  • Environment: Kubernetes 1.31
  • Deployment type: Helm
  • Other: N/A

Additional context
It might be worth it to remove ns, us, µs, ms as they do not make much sense as alert delays and add d and w. and omit y as that does not make much sense either.

Metadata

Metadata

Assignees

Labels

good first issueGood for newcomerstriage/acceptedIndicates an issue or PR is ready to be actively worked on.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions