Skip to content

rules: add unknown state for unevaluated alerting rules#17282

Merged
juliusv merged 4 commits intoprometheus:mainfrom
SRasaikar:srasaikar/Issue_#4510
Oct 17, 2025
Merged

rules: add unknown state for unevaluated alerting rules#17282
juliusv merged 4 commits intoprometheus:mainfrom
SRasaikar:srasaikar/Issue_#4510

Conversation

@SRasaikar
Copy link
Contributor

Which issue(s) does the PR fix:

Fixes #4510

Does this PR introduce a user-facing change?

[ENHANCEMENT] Rules: Add "unknown" state for alerting rules that haven't been evaluated yet. This provides better visibility into the state of newly created or recently reloaded rules.

Description

This PR introduces a new StateUnknown state for alerting rules that haven't been evaluated yet. Previously, unevaluated rules would show as "inactive" which could be misleading as it suggests the rule has been evaluated and found no matching alerts.

Changes:

  1. Backend (Go):

    • Added StateUnknown constant with value -1 to the AlertState enum
    • Modified AlertingRule.State() to return StateUnknown when the rule's evaluation timestamp is zero (indicating it hasn't been evaluated)
    • Updated AlertState.String() to handle the new unknown state
    • Updated tests to set evaluation timestamp to ensure existing behavior is maintained
  2. Frontend (Mantine UI):

    • Extended RuleState type to include "unknown"
    • Updated alerts page to:
      • Track and display unknown state counts
      • Show appropriate badges for rules in unknown state
      • Include unknown state in the filter options
      • Apply proper styling to panels containing rules in unknown state

Benefits:

  • Better observability: Users can now distinguish between rules that haven't been evaluated yet and rules that have been evaluated but have no active alerts
  • Improved UX: The UI now clearly indicates when rules are in an unknown state, helping users understand the system's current state better
  • Backwards compatible: The change doesn't break existing functionality as the unknown state is only returned for unevaluated rules

Testing:

The existing test suite has been updated to accommodate the new state. The test now sets the evaluation timestamp to ensure that the existing test cases continue to work as expected.

Note on implementation:

The implementation checks if evaluationTimestamp is zero to determine if a rule has been evaluated. This is a reliable indicator as the timestamp is set during each evaluation cycle.

Signed-off-by: Sahil Rasaikar <sahil.rasaikar@gmail.com>
Signed-off-by: Sahil Rasaikar <sahil.rasaikar@gmail.com>
Signed-off-by: Sahil Rasaikar <sahil.rasaikar@gmail.com>
@SRasaikar SRasaikar requested a review from juliusv as a code owner October 5, 2025 11:50
Copy link
Member

@juliusv juliusv left a comment

Choose a reason for hiding this comment

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

Looks pretty good, thanks. A few comments. And I assume you tested it and it works? :)

… String method to match constant order.

Signed-off-by: Sahil Rasaikar <sahil.rasaikar@gmail.com>
@SRasaikar
Copy link
Contributor Author

SRasaikar commented Oct 8, 2025

Looks pretty good, thanks. A few comments. And I assume you tested it and it works? :)

Yep I did test the changes , Please find the screenshots below:

Before Evaluation / Initial State:

Rule health unknown:
Rule health unknown

Alert state unknown:
Alert state unknown

After Standard Interval:

Rule after default evaluation:
Rule after default evaluation

Alert after default evaluation:
Alert after default evaluation

After Extended Interval:

Rule after extended evaluation:
Rule after extended evaluation

Alert after extended evaluation:
Alert after extended evaluation

Also, Thank you very much for the review.

@SRasaikar SRasaikar requested a review from juliusv October 14, 2025 14:43
@SRasaikar
Copy link
Contributor Author

@beorn7 , can i have a review here, also for next time what's the correct way to ask for reviews?

Thanks.

@juliusv
Copy link
Member

juliusv commented Oct 17, 2025

Thanks, looks good now! 👍

@beorn7 , can i have a review here, also for next time what's the correct way to ask for reviews?

I think you did everything correct - we're just sometimes slow with reviews because there are a lot of things happening (in the project and elsewhere in life), and the people reviewing PRs are mostly doing this on a volunteer basis and a bit random in their prioritization.

@juliusv juliusv merged commit da17fe5 into prometheus:main Oct 17, 2025
28 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.

Distinguish not-yet-evaluated alert from empty alert

2 participants