Fix fleet-scoped host vitals labels#46953
Conversation
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.
Tip: disable this comment in your organization's Code Review settings.
|
Need an answer fast? Review this PR in Change Stack to ask focused questions about the PR or a changed range. WalkthroughThis PR fixes a bug where host vitals labels matching IdP groups were not capturing hosts when scoped to fleets or teams. The root cause involved two issues: the cron's label-discovery filter excluded fleet-scoped labels, and the SQL join logic used RIGHT JOIN instead of INNER JOIN, allowing NULL host IDs when hosts were filtered by team. The fix updates the SQL join to INNER JOIN, modifies the cron to use a global-admin TeamFilter for label discovery, and adds comprehensive test coverage at datastore and cron integration levels to verify correct host membership across global and team-scoped labels. Possibly related PRs
🚥 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 docstrings
🧪 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.
Pull request overview
Fixes fleet/team-scoped host vitals labels for IdP-based criteria (e.g. IdP group/department) by ensuring the membership cron includes team labels and by correcting the IdP foreign-vitals SQL join so out-of-scope hosts don’t survive filtering (and don’t break label membership updates).
Changes:
- Change IdP foreign vitals join from
RIGHT JOINto an innerJOINto prevent NULL host IDs and cross-team leakage during fleet-scoped label membership updates. - Update the host vitals label membership cron to list labels using a global-admin
TeamFilter, so team-scoped host vitals labels are included. - Add/adjust regression tests (datastore + cron) and update expected generated SQL strings; add a user-visible changelog entry.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| server/fleet/hosts.go | Switch IdP foreign-vitals query join semantics and document the rationale. |
| cmd/fleet/cron.go | Ensure cron lists labels with a global-admin filter so team-scoped host vitals labels are processed. |
| server/service/labels_test.go | Update expected generated SQL string for IdP vitals label query. |
| server/service/integration_core_test.go | Update expected generated SQL strings for IdP vitals label queries in integration tests. |
| server/datastore/mysql/labels_test.go | Add datastore regression test covering global vs team-scoped IdP host vitals labels. |
| cmd/fleet/serve_test.go | Strengthen unit test to assert cron uses a user-scoped/global-admin filter when listing labels. |
| cmd/fleet/cron_test.go | Add cron integration test ensuring team-scoped IdP host vitals labels get populated. |
| changes/46869-idp-team-vitals-labels | Changelog entry describing the bugfix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #46953 +/- ##
==========================================
+ Coverage 67.02% 67.04% +0.01%
==========================================
Files 2859 2862 +3
Lines 224683 225040 +357
Branches 11614 11614
==========================================
+ Hits 150592 150869 +277
- Misses 60445 60501 +56
- Partials 13646 13670 +24
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Related issue: Resolves #46869
changes/,orbit/changes/oree/fleetd-chrome/changes.Testing
Summary by CodeRabbit
Bug Fixes
Tests