Repository navigation
fix(correlation): correlate image pulls by image, not by stack-name token - #82
Conversation
Adds Image string to the Entry struct, entryJSON wire type, MarshalJSON literal, and UnmarshalJSON assignment so the field survives agent→server JSON transport. Also adds a composite GORM index (idx_entries_service_image) on Service+Image to support efficient pull-correlation queries. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Populate types.Entry.Image in both buildEntry (image and container events) and buildCollapsedContainerEntry using the existing normalizeImageRef helper, enabling image-based incident correlation. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ScoreCauses now takes a node argument and filters candidates by node_name, and matches pull/delete events by image (against images the trigger services actually run) rather than by the synthetic service token — fixing false correlations when a shared image name collides with a real stack name. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Update all external call sites of correlation.ScoreCauses to supply the new node string parameter (3rd arg) introduced in the updated signature. Rules.go passes the trigger entry's NodeName; webhook_uptime.go passes "" to preserve cross-node matching for webhook triggers. Also adds a comment to imagesForServices clarifying it is intentionally not time-windowed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Four rules_test.go tests set the webhook-down trigger's NodeName to "webhook" (a monitor node), leaving the docker/systemd cause entries on a different infra node. The new node-scoping in ScoreCauses (node_name = trigger OR node_name = '') excluded those cross-node candidates, breaking correlation. Updated each trigger entry to share the infra node so the scope matches — preserving the original test intent while reflecting the intended node-scoped behavior. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Webhook entries always carry NodeName="webhook" (a synthetic, node-agnostic value). Passing that as the node scope to ScoreCauses excluded all real docker/systemd cause candidates (which live on actual agent nodes like "media-node"). Fix by passing "" in handleMonitorDown and upgradeToConfirmed so all hosts are searched when the trigger is a webhook-down event. Revert the 4 masking NodeName changes from 4c410b2 that made tests pass by aligning the down-trigger's node with the cause node; with the empty-node fix in place, the realistic "webhook" trigger node now correctly finds cross-host cause candidates. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Warning Review limit reached
More reviews will be available in 40 minutes and 30 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ 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: Repository UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds an ChangesEntry.Image field, image-based correlation, and node-agnostic webhook handling
Sequence Diagram(s)sequenceDiagram
rect rgba(100, 149, 237, 0.5)
Note over DockerWatcher,DB: Agent side — image capture
DockerWatcher->>DockerWatcher: buildEntry / buildCollapsedContainerEntry
DockerWatcher->>DB: persist Entry{Image: normalizeImageRef(...)}
end
rect rgba(144, 238, 144, 0.5)
Note over IncidentRule,DB: Server side — image-scoped correlation
IncidentRule->>ScoreCauses: services, node="", at, triggerComposeService
ScoreCauses->>imagesForServices: services, node
imagesForServices->>DB: SELECT DISTINCT image WHERE service IN services (excl. pull/delete)
DB-->>imagesForServices: ["postgres"]
imagesForServices-->>ScoreCauses: ["postgres"]
ScoreCauses->>DB: pull/delete candidates WHERE image IN ["postgres"]
DB-->>ScoreCauses: []CauseCandidate
ScoreCauses-->>IncidentRule: scored & ranked causes
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 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 |
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 `@shared/types/events.go`:
- Line 13: Remove the redundant standalone index declaration from the Service
field in the events struct. The `index` tag on the Service field is redundant
since the composite index `idx_entries_service_image` already includes the
service column as its first element, which efficiently covers queries filtering
only by service. Keep only the composite index tag
`index:idx_entries_service_image,priority:1` and remove the `index` tag to
reduce storage overhead and index maintenance burden.
🪄 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: Repository UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: bc3217c3-00a1-456c-93cc-1a3c146ae463
📒 Files selected for processing (10)
agent/internal/docker/watcher.goagent/internal/docker/watcher_test.goserver/internal/correlation/correlation.goserver/internal/correlation/correlation_test.goserver/internal/correlation/score.goserver/internal/correlation/score_test.goserver/internal/handlers/webhook_uptime.goserver/internal/incidents/rules.goshared/types/events.goshared/types/events_test.go
The composite idx_entries_service_image has service as its leading column (priority:1), so it already covers service-only filters via leftmost-prefix. The standalone index tag was redundant. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Summary
Image-pull (and delete) events were correlated to the wrong stack when an image is used by services in multiple stacks. Root cause: the agent neutralizes a shared-image pull by setting
Entry.Serviceto the image's short name (e.g.postgres), which lives in the same namespace as real compose-project (stack) names, andcorrelation.ScoreCausesmatched pull candidates by bareservicestring equality — so the pull attached to any incident whose stack was merely named like the image.This fix decouples pull correlation from the fragile
Servicetoken:Entry.Image— new normalized image field, threaded through the type's custom JSON so it crosses the agent→server wire. The agent stamps it on container events (attrs["image"]) and image events (the pulled ref), normalized vianormalizeImageRef(postgres:16,docker.io/library/postgres:16→postgres).ScoreCausesnow matches dockerpull/deletecandidates byimage ∈ {images the trigger stack actually runs}(derived from that stack's container entries viaimagesForServices), instead of byservice. A shared pull correlates to exactly the stacks that run the image, and never to an unrelated same-named stack. This also fixes tag/digest reference divergence for free.NodeName: "webhook"), preserving cross-host monitor→cause correlation.Test Plan
go test ./...— shared 4 / agent 104 / server 470 pass;go vet ./...andgo build ./...cleanTestScoreCauses_PullCorrelatesToStackThatRunsImage— shared pull attaches to a stack that runs the imageTestScoreCauses_PullDoesNotCorrelateToStackThatDoesNotRunImage— sharedpostgrespull does not attach to a same-named stack that runsredisTestScoreCauses_ScopesToTriggerNode— candidates on a different node are excludedTestBuildEntry_ImagePullSetsNormalizedImage/TestBuildEntry_ContainerEventSetsNormalizedImage— agent stamps normalizedImagepostgres:16shared by two stacks, a pull no longer appears as a cause/context on an unrelatedpostgres-named stack's incident.Migration note
The new
imagecolumn + composite indexidx_entries_service_imageare added via GORM AutoMigrate. Existing rows getNULLimage (graceful): a stack whose only container entries predate the migration won't correlate pulls until a fresh container event records a populatedImage— strictly better than the prior mis-correlation.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Tests