Skip to content

api: add active/expired/pending filter params to GET /silences - #5406

Open
mihir-dixit2k27 wants to merge 2 commits into
prometheus:mainfrom
mihir-dixit2k27:api/silence-state-filter
Open

api: add active/expired/pending filter params to GET /silences#5406
mihir-dixit2k27 wants to merge 2 commits into
prometheus:mainfrom
mihir-dixit2k27:api/silence-state-filter

Conversation

@mihir-dixit2k27

Copy link
Copy Markdown
Contributor

Fixes #5404

GET /api/v2/silences returns all silences with no way to filter by state. This means callers who only care about active silences have to fetch everything and filter client-side, which is the same problem that was solved for alerts with the existing active, silenced, inhibited, and unprocessed params on GET /alerts.

This PR adds three optional boolean query params that are active, expired, pending to GET /api/v2/silences. Omitting a param includes that state (default behaviour is unchanged). Passing false excludes it.

The filter is applied server-side after the existing label-matcher filter, before sorting.

[FEATURE] API: Add active, expired, and pending boolean filter parameters to GET /api/v2/silences to allow filtering silences by state server-side.

Signed-off-by: Mihir Dixit <dixitmihir1@gmail.com>
@mihir-dixit2k27
mihir-dixit2k27 requested a review from a team as a code owner July 27, 2026 09:57
@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 3ec3cffb-7805-4670-9de8-6e0d780fb0e6

📥 Commits

Reviewing files that changed from the base of the PR and between ad574d7 and 0c24e06.

📒 Files selected for processing (1)
  • api/v2/api.go

📝 Walkthrough

Walkthrough

The GET silences API adds active, expired, and pending boolean query parameters, propagates them through generated bindings and clients, and filters returned silences by state. Tests cover combinations of the three flags.

Changes

Silence state filters

Layer / File(s) Summary
API contract and request binding
api/v2/openapi.yaml, api/v2/restapi/embedded_spec.go, api/v2/restapi/operations/silence/get_silences_parameters.go
Defines the three boolean query parameters, defaults them to true, and binds supplied values into request parameters.
Client query propagation
api/v2/client/silence/get_silences_parameters.go, api/v2/restapi/operations/silence/get_silences_urlbuilder.go
Adds pointer fields, setters, defaults, and serialization for active, expired, and pending.
Server filtering and validation
api/v2/api.go, api/v2/api_test.go
Filters returned silences by state and tests active, pending, expired, and empty-result combinations.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant GetSilencesParams
  participant getSilencesHandler
  Client->>GetSilencesParams: Send state query flags
  GetSilencesParams->>getSilencesHandler: Bind active, expired, pending
  getSilencesHandler-->>Client: Return filtered silences
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately describes the new GET /silences state filters.
Description check ✅ Passed The description covers the issue, behavior, defaults, and release-note summary; only checklist extras are omitted.
Linked Issues check ✅ Passed The changes satisfy #5404 by adding active, expired, and pending boolean params with default-true, false-to-exclude behavior.
Out of Scope Changes check ✅ Passed All changes are directly related to GET /silences state filtering plus the necessary client, spec, and test updates.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@api/v2/api_test.go`:
- Around line 233-236: Strengthen the assertions in the active=false test case
around callHandler by requiring both got["expired"] and got["pending"] to be
true, replacing the current OR condition while preserving the active=false
assertion.

In `@api/v2/api.go`:
- Around line 705-723: Initialize filtered as a non-nil empty
open_api_models.GettableSilences before the filtering loop, so zero matches and
an empty source serialize as [] rather than null. In the same filter block,
guard the params.Active, params.Expired, and params.Pending pointer dereferences
before checking their values, preserving the existing state-filter behavior for
non-nil parameters.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 3e187dbb-f05d-4235-ac2f-ed68c107ed10

📥 Commits

Reviewing files that changed from the base of the PR and between 846bdbf and 4aa4154.

📒 Files selected for processing (7)
  • api/v2/api.go
  • api/v2/api_test.go
  • api/v2/client/silence/get_silences_parameters.go
  • api/v2/openapi.yaml
  • api/v2/restapi/embedded_spec.go
  • api/v2/restapi/operations/silence/get_silences_parameters.go
  • api/v2/restapi/operations/silence/get_silences_urlbuilder.go

Comment thread api/v2/api_test.go
Comment thread api/v2/api.go Outdated
Comment thread api/v2/api.go Outdated
Comment thread api/v2/api.go Outdated
Signed-off-by: Mihir Dixit <dixitmihir1@gmail.com>
@mihir-dixit2k27
mihir-dixit2k27 force-pushed the api/silence-state-filter branch from ad574d7 to 0c24e06 Compare July 27, 2026 18:23
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.

Api silences add parameter like alerts

2 participants