Skip to content

feat: allow configuring alert rules - #209

Merged
chanchiwai-ray merged 1 commit into
canonical:mainfrom
ioanalazea:fix-208-alert
Sep 9, 2026
Merged

chanchiwai-ray merged 1 commit into
canonical:mainfrom
ioanalazea:fix-208-alert

Conversation

@ioanalazea

@ioanalazea ioanalazea commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Add an alert_rules config option for overriding Prometheus alerts rules.
Fixes: #208

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds operator-level support for overriding Prometheus alert rule for: durations by alert name, addressing deployments that need shorter/longer “for” windows without editing shipped rule files.

Changes:

  • Introduces alert_for_duration charm config (comma-separated AlertName=duration pairs) and validation/parsing helpers.
  • Updates charm config-change flow to render alert rule YAML with configured for: overrides before COS integration reads them.
  • Adds unit tests for the new config validation and for rendering overrides into rule YAML.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/validate_config.py Adds alert-name discovery from shipped rule YAML, validation for alert_for_duration, and parsing into a dict.
src/charm.py Validates the new config option and renders rule YAML with overridden for: durations on config changes.
charmcraft.yaml Exposes alert_for_duration config with documentation and examples.
tests/unit/test_validate_config.py Adds unit tests for validation/parsing of alert_for_duration.
tests/unit/test_charm.py Extends config-change tests and adds a test that rendered rule YAML reflects the override.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/charm.py Outdated
Comment thread src/charm.py Outdated
Comment thread charmcraft.yaml Outdated

@jneo8 jneo8 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi @ioanalazea

Thanks for the contribution.

I am thinking instead of alert_for_duration, expose one alert_rules option holding a full rules document that replaces the shipped set may be a better solution here. we do not want to add a new option per field (severity, thresholds, extra alerts).

two points:

  1. Validation before publishing. Invalid rules aren't caught locally; Prometheus drops the whole relation blob, silently killing alerts for every app on that grafana-agent.
  2. A warning in the description: the reload cancels currently-firing alerts and reports removed ones to Alertmanager as resolved

@ioanalazea ioanalazea changed the title feat: allow configuring alert rule durations feat: allow configuring alert rules Aug 27, 2026
@ioanalazea

Copy link
Copy Markdown
Contributor Author

Hi @ioanalazea

Thanks for the contribution.

I am thinking instead of alert_for_duration, expose one alert_rules option holding a full rules document that replaces the shipped set may be a better solution here. we do not want to add a new option per field (severity, thresholds, extra alerts).

two points:

  1. Validation before publishing. Invalid rules aren't caught locally; Prometheus drops the whole relation blob, silently killing alerts for every app on that grafana-agent.
  2. A warning in the description: the reload cancels currently-firing alerts and reports removed ones to Alertmanager as resolved

Hello,

Thanks for the feedback. I agree that having such a config option would be better, so I have updated my PR with the proposed changes.

I have addressed both points. For point 2, I added a message to the description of the config option.

For point 1, I wanted to elaborate a little. Initially, I considered adding a validation function to the exporter code to validate the proposed YAML. However, I don't think that would be feasible in the long term. For this reason, my idea is to use cos-tool to validate the Prometheus alerts instead and log an error message in the charm.
As you have mentioned, without this validation Prometheus would just silently drop the alerts and not set them, so the user would not be informed.

Looking forward to any feedback.

Thanks a lot!

@jneo8 jneo8 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall is good.
For this change functional test is required.
Let me know if you need any help during the implementation of functional test.

Comment thread src/charm.py
@ioanalazea
ioanalazea force-pushed the fix-208-alert branch 4 times, most recently from b1812b8 to f73adb2 Compare September 1, 2026 19:43
Comment thread src/validate_config.py
@ioanalazea
ioanalazea force-pushed the fix-208-alert branch 2 times, most recently from afe09ad to 77ca2ad Compare September 2, 2026 11:02
@chanchiwai-ray

Copy link
Copy Markdown
Contributor

Overall, lgtm, but test_configure_alert_rules is failing. Note Commits must have verified signatures., please check this doc https://docs.github.com/en/authentication/managing-commit-signature-verification

@ioanalazea
ioanalazea force-pushed the fix-208-alert branch 3 times, most recently from e3ebd89 to 11c3c67 Compare September 4, 2026 05:49
Add an alert_rules config option for overriding the currently
shipped Prometheus alerts.

Fixes: canonical#208
Signed-off-by: Ioana Lazea <ioana.lazea@canonical.com>
@ioanalazea

Copy link
Copy Markdown
Contributor Author

Overall, lgtm, but test_configure_alert_rules is failing. Note Commits must have verified signatures., please check this doc https://docs.github.com/en/authentication/managing-commit-signature-verification

Thank you for the feedback. That seemed like a race condition where assert triggered before the file was removed. I added block_until to fix that.
The tests still failed but because machine is in error state.

@chanchiwai-ray chanchiwai-ray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wait for the test to pass

@jneo8 jneo8 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM thanks @ioanalazea

@chanchiwai-ray
chanchiwai-ray merged commit f6e53e6 into canonical:main Sep 9, 2026
41 of 50 checks passed
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.

[FR] Add charm config to override Prometheus alert rules

4 participants