Host vitals label built on a custom host vital (BE + FE)#49240
Conversation
Adds a custom_host_vital label criterion: a host is a member when its stored value for the selected custom host vital equals the criterion value. Validated on create and batch/GitOps apply, evaluated in host-vitals membership, and protected against deleting a referenced vital. Wires the New label UI to the real custom_host_vitals list endpoint.
|
@coderabbitai full review |
✅ Action performedFull review finished. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## 44954-custom-host-vitals #49240 +/- ##
===========================================================
Coverage ? 67.96%
===========================================================
Files ? 3695
Lines ? 234802
Branches ? 12372
===========================================================
Hits ? 159587
Misses ? 60855
Partials ? 14360
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:
|
WalkthroughAdds custom host vitals as criteria for host-vitals labels. The frontend queries and presents custom vitals, encodes selections, validates their IDs, and includes them in create requests. The backend adds custom-vital criteria parsing, parameterized joins, existence validation, and membership recalculation coverage. Deletion protection now detects label references, and entity types use typed constants. Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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.
🧹 Nitpick comments (1)
server/datastore/mysql/custom_host_vitals.go (1)
240-276: 🗄️ Data Integrity & Integration | 🔵 Trivial | 💤 Low valueDelete-protection scan only checks top-level
CustomHostVitalID.The scan reads
criteria.CustomHostVitalIDdirectly without recursing intocriteria.And/criteria.Or. This is safe today only becauseparseHostVitalCriteria(server/fleet/labels.go) currently rejects And/Or at label create/update time, so no persisted label can have nested criteria. If nested criteria support is added later without updating this scan, a custom vital referenced only inside a nested branch could be deleted without protection. Worth a defensive TODO or test guard tied to that future change.🤖 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 `@server/datastore/mysql/custom_host_vitals.go` around lines 240 - 276, Add a defensive TODO beside the criteria scan in the custom host-vital delete-protection logic, documenting that any future support for nested criteria in parseHostVitalCriteria must make this scan recurse through And and Or branches. Keep the current top-level check unchanged while nested criteria remain rejected.
🤖 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 `@server/datastore/mysql/custom_host_vitals.go`:
- Around line 240-276: Add a defensive TODO beside the criteria scan in the
custom host-vital delete-protection logic, documenting that any future support
for nested criteria in parseHostVitalCriteria must make this scan recurse
through And and Or branches. Keep the current top-level check unchanged while
nested criteria remain rejected.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 52a051cb-5209-4d63-9b3d-5fe9c00d5ce5
📒 Files selected for processing (13)
frontend/interfaces/label.tsfrontend/pages/labels/NewLabelPage/NewLabelPage.tsxfrontend/pages/labels/NewLabelPage/helpers.tests.tsfrontend/pages/labels/NewLabelPage/helpers.tsfrontend/services/entities/labels.tsserver/datastore/mysql/custom_host_vitals.goserver/datastore/mysql/custom_host_vitals_test.goserver/datastore/mysql/labels_test.goserver/fleet/custom_host_vitals.goserver/fleet/hosts.goserver/fleet/labels.goserver/service/labels.goserver/service/labels_test.go
The help text now describes the selected criterion (IdP group, IdP department, or custom host vital) instead of listing the whole menu, which read as misleading when an IdP option was selected.
On Free tier, IdP criteria aren't available, so the disabled-type tooltip now tells the admin to add a custom host vital (and notes IdP group/department are Premium) instead of pointing them at IdP settings they can't reach. Premium wording (Product-approved) is unchanged.
Related issue: Resolves #48582
Host-vitals labels can currently only be keyed on IdP group/department, so admins can't build a label from a custom host vital. This adds a
custom_host_vitallabel criterion — a host is a member when its stored value for the selected vital equals the criterion value — wired through label create, batch/GitOps validation, membership evaluation, and delete-protection, plus the New label UI. Targets the44954-custom-host-vitalsfeature branch.Checklist for submitter
changes/,orbit/changes/oree/fleetd-chrome/changes.See Changes files for more information.
Will be added in feature branch.
Testing
Added/updated automated tests
QA'd all new/changed functionality manually
Created
Test label 1label with criteria: "Department = Engineering" (Departmentis a custom host vital).Set the host vital value to Engineering in two hosts:
Verified label membership contains those two hosts:
Summary by CodeRabbit
New Features
Bug Fixes