Cleanup stale metrics and event subscriptions#889
Conversation
41bec4e to
1892ef5
Compare
|
Warning Review limit reached
More reviews will be available in 52 minutes and 50 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughAdds BMC.GetEventSubscription and a Redfish implementation that treats HTTP 404 as “not present”; controller validates stored metrics/events subscription links and clears stale status links so missing subscriptions are recreated; mock-server delete helper and an integration test simulate and verify external deletion recovery. ChangesEvent Subscription Staleness Detection
Sequence DiagramsequenceDiagram
participant Controller as BMCReconciler
participant BMCClient as RedfishBaseBMC
participant Redfish as RedfishEventService
participant Mock as MockServer
Controller->>BMCClient: GetEventSubscription(ctx, metricsURI)
BMCClient->>Redfish: ev.GetEventSubscription(metricsURI)
Redfish-->>BMCClient: 404 (not found) / subscription object
BMCClient-->>Controller: (false,nil) or (true,nil)
alt subscription not found
Controller->>Controller: clear status link (status patch)
Controller->>BMCClient: CreateEventSubscription(...)
BMCClient->>Redfish: CreateEventSubscription(...)
Redfish-->>BMCClient: new subscription URI
BMCClient-->>Controller: new URI
else subscription exists
Controller-->>Controller: keep status link
end
Note over Mock,Redfish: MockServer.DeleteSubscription removes member from subscription collection to simulate external deletion
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
xkonni
left a comment
There was a problem hiding this comment.
good, fixes issue, minor optimizations possible.
1892ef5 to
5c3f881
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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 `@bmc/mock/server/server.go`:
- Around line 1313-1321: The code can silently overwrite an existing collection
with an empty one when type assertions fail or dataFS.ReadFile/json.Unmarshal
fail; update the loading logic around the variables col, cached, Collection,
dataFS.ReadFile, json.Unmarshal and collectionKey so that: (1) when hasOverride
is true but cached is not a Collection, do NOT replace col (leave original
cached value or bail); (2) when ReadFile returns an error or json.Unmarshal
fails, do not overwrite col with the empty default—propagate/handle the error or
keep the prior value; and (3) before the persistence step that writes col (the
save at the persistence call around collection handling), add a guard to only
persist when col is valid (e.g., col.ID is non-empty or len(col.Members) > 0);
if invalid, skip saving and return/log an error so you cannot accidentally wipe
members.
In `@internal/controller/bmc_controller.go`:
- Around line 567-580: Update the error string in the patch failure to reference
the BMC status rather than "server status": when handling
bmcObj.Status.MetricsReportSubscriptionLink and calling r.Status().Patch(ctx,
bmcObj, client.MergeFrom(bmcBase)), change the fmt.Errorf message used on error
return to something like "failed to patch BMC status to clear stale metrics
subscription link: %w" so it correctly references bmcObj (BMC) and its status.
- Around line 595-608: The error message used when the status patch fails
incorrectly references "server status"; update the fmt.Errorf call in the block
handling bmcObj.Status.EventsSubscriptionLink (around GetEventSubscription and
r.Status().Patch) to say "failed to patch BMC status to clear stale events
subscription link" so it correctly names the BMC status and use the existing
variables (bmcObj, bmcBase) and error wrapping as-is.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 11823367-8cf1-4fb0-bc23-9df7749fba1a
📒 Files selected for processing (5)
bmc/bmc.gobmc/mock/server/server.gobmc/redfish.gointernal/controller/bmc_controller.gointernal/controller/bmc_controller_test.go
5c3f881 to
bfda8c6
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
bfda8c6 to
543c877
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
bmc/redfish.go (1)
1182-1201: 💤 Low valueOptional: deduplicate the event-service preamble.
GetEventSubscriptionrepeats theGetService→EventService→ServiceEnabled→ev.GetEventSubscription(uri)sequence already present inDeleteEventSubscription(lines 1203-1218). A small helper returning(*schemas.EventDestination, error)would centralize theServiceEnabledguard and 404 handling.🤖 Prompt for 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. In `@bmc/redfish.go` around lines 1182 - 1201, Extract the repeated GetService → EventService → ServiceEnabled check and the ev.GetEventSubscription(uri) call (including the 404 handling that checks for *schemas.Error with HTTPReturnedStatusCode == http.StatusNotFound) into a new helper (e.g. getEventDestination or fetchEventSubscription) that returns (*schemas.EventDestination, error); then update GetEventSubscription and DeleteEventSubscription to call that helper and act on the returned destination (nil vs non-nil) or error, preserving the existing error wrapping semantics and the special-case 404 -> nil behavior.
🤖 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.
Nitpick comments:
In `@bmc/redfish.go`:
- Around line 1182-1201: Extract the repeated GetService → EventService →
ServiceEnabled check and the ev.GetEventSubscription(uri) call (including the
404 handling that checks for *schemas.Error with HTTPReturnedStatusCode ==
http.StatusNotFound) into a new helper (e.g. getEventDestination or
fetchEventSubscription) that returns (*schemas.EventDestination, error); then
update GetEventSubscription and DeleteEventSubscription to call that helper and
act on the returned destination (nil vs non-nil) or error, preserving the
existing error wrapping semantics and the special-case 404 -> nil behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: cb25bc9b-02a0-4779-8aed-e43e050cb151
📒 Files selected for processing (5)
bmc/bmc.gobmc/mock/server/server.gobmc/redfish.gointernal/controller/bmc_controller.gointernal/controller/bmc_controller_test.go
🚧 Files skipped from review as they are similar to previous changes (4)
- bmc/bmc.go
- internal/controller/bmc_controller_test.go
- internal/controller/bmc_controller.go
- bmc/mock/server/server.go
Signed-off-by: Alan Sergeant <alan.sergeant@sap.com>
543c877 to
53f3be8
Compare
|
@asergeant01 can you please rebase this PR? |
Fixes #886
Summary by CodeRabbit
New Features
Bug Fixes
Tests