api: add active/expired/pending filter params to GET /silences - #5406
api: add active/expired/pending filter params to GET /silences#5406mihir-dixit2k27 wants to merge 2 commits into
Conversation
Signed-off-by: Mihir Dixit <dixitmihir1@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe 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. ChangesSilence state filters
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
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (7)
api/v2/api.goapi/v2/api_test.goapi/v2/client/silence/get_silences_parameters.goapi/v2/openapi.yamlapi/v2/restapi/embedded_spec.goapi/v2/restapi/operations/silence/get_silences_parameters.goapi/v2/restapi/operations/silence/get_silences_urlbuilder.go
Signed-off-by: Mihir Dixit <dixitmihir1@gmail.com>
ad574d7 to
0c24e06
Compare
Fixes #5404
GET /api/v2/silencesreturns 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 existingactive,silenced,inhibited, andunprocessedparams onGET /alerts.This PR adds three optional boolean query params that are
active,expired,pendingtoGET /api/v2/silences. Omitting a param includes that state (default behaviour is unchanged). Passingfalseexcludes 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.