feat(api): emit SSE events for the HTTP API check endpoint - #2066
Conversation
- Publish scan_started, scan_completed, and scan_failed events during check runs - Add event broadcaster and pre-built scan data to check handler - Introduce NewScanStartedData helper for redacted policy flags - Update route registration and handler tests to use the event broadcaster
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe check API now emits ChangesCheck scan event flow
Sequence Diagram(s)sequenceDiagram
participant CheckAPIClient
participant CheckHandler
participant EventBroadcaster
participant CheckFunc
CheckAPIClient->>CheckHandler: submit check request
CheckHandler->>EventBroadcaster: publish scan_started
CheckHandler->>CheckFunc: execute check
alt check fails
CheckFunc-->>CheckHandler: return error
CheckHandler->>EventBroadcaster: publish scan_failed
CheckHandler-->>CheckAPIClient: return HTTP 500
else check succeeds
CheckFunc-->>CheckHandler: return container results
CheckHandler->>EventBroadcaster: publish scan_completed with counts
CheckHandler-->>CheckAPIClient: return success
end
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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 |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 26 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## main #2066 +/- ##
==========================================
+ Coverage 72.25% 72.32% +0.06%
==========================================
Files 120 120
Lines 13333 13365 +32
==========================================
+ Hits 9634 9666 +32
Misses 3277 3277
Partials 422 422
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@internal/api/handlers/check/handler.go`:
- Around line 151-159: Update the scan failure event construction in the check
handler’s eventBroadcaster.Publish path to avoid sending err.Error() through
ScanFailedData. Publish the same generic client-safe failure message used by the
HTTP response, or an intentionally mapped safe description, while retaining the
full err details in the existing server log.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 7cb1da4a-b66f-4d25-984b-9032602ada9e
📒 Files selected for processing (7)
internal/actions/actions.gointernal/api/handlers/check/handler.gointernal/api/handlers/check/handler_test.gointernal/api/handlers/events/events.gointernal/api/routes/check.gointernal/api/routes/check_test.gointernal/flags/flags_test.go
- Add SSE Events section to check endpoint documentation - Add SSE Events section to update endpoint documentation - Document scan and update event broadcasting conditions in events endpoint
- Replace raw error string with generic message to prevent information leakage - Update test assertion to match sanitized error message
This PR adds SSE event emission for POST /v1/check, so SSE subscribers are notified when a check-only run completes.
Problem
The
/v1/eventsSSE endpoint only emits events for updates. A registry check triggered via POST/v1/checkproduces no SSE event and leaves API consumers with limited options for determining when the check is completed.Solution
Added
scan_started,scan_completed, andscan_failedevent types for check runs.The construction of the redacted configuration information that is provided by the
scan_startedevent was also refactored to centralize the mapping and reduce repetition for future additions of SSE events.Changes
scan_started,scan_completed, andscan_failedSSE events to thePOST /v1/checkhandler.ScanStartedDataconstruction into a shared helper used by both the update and check routes.EventBroadcaster.Summary by CodeRabbit
New Features
/v1/check:scan_started,scan_completed, andscan_failed.Bug Fixes
scan_startedpayload is now constructed from redacted update parameters.scan_failednow returns the fixed message:"failed to check for updates".Documentation
Tests