Skip to content

Host vitals label built on a custom host vital (BE + FE)#49240

Merged
nulmete merged 4 commits into
44954-custom-host-vitalsfrom
48582-new-label-custom-host-vitals
Jul 14, 2026
Merged

Host vitals label built on a custom host vital (BE + FE)#49240
nulmete merged 4 commits into
44954-custom-host-vitalsfrom
48582-new-label-custom-host-vitals

Conversation

@nulmete

@nulmete nulmete commented Jul 13, 2026

Copy link
Copy Markdown
Member

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_vital label 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 the 44954-custom-host-vitals feature branch.

Checklist for submitter

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/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 1 label with criteria: "Department = Engineering" (Department is a custom host vital).

Screenshot 2026-07-13 at 11 15 17 PM

Set the host vital value to Engineering in two hosts:

Screenshot 2026-07-13 at 11 14 42 PM Screenshot 2026-07-13 at 11 14 47 PM

Verified label membership contains those two hosts:

Screenshot 2026-07-13 at 11 14 28 PM

Summary by CodeRabbit

  • New Features

    • Added support for creating host-vitals labels using custom host vitals.
    • Custom host vital criteria now support filtering, label membership updates, and label specification application.
    • Added clearer value prompts and validation for selected custom vitals.
  • Bug Fixes

    • Prevented deletion of custom host vitals referenced by labels.
    • Invalid or unknown custom vital references are now rejected during label creation and application.

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.
@nulmete

nulmete commented Jul 13, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.83333% with 28 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (44954-custom-host-vitals@32ccf45). Learn more about missing BASE report.

Files with missing lines Patch % Lines
server/datastore/mysql/custom_host_vitals.go 75.86% 4 Missing and 3 partials ⚠️
frontend/pages/labels/NewLabelPage/helpers.ts 76.00% 6 Missing ⚠️
server/service/labels.go 72.72% 3 Missing and 3 partials ⚠️
server/fleet/custom_host_vitals.go 0.00% 5 Missing ⚠️
frontend/services/entities/labels.ts 0.00% 4 Missing ⚠️
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           
Flag Coverage Δ
backend 69.65% <72.72%> (?)
frontend 58.77% <66.66%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds 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

  • fleetdm/fleet issue 44954: Covers the broader host-vitals label integration that this change implements for custom host vitals.

Possibly related PRs

  • fleetdm/fleet#48706: Adds the custom-host-vitals datastore CRUD that this change extends with label-reference deletion protection.
  • fleetdm/fleet#48821: Shares custom-host-vitals deletion-protection and validation plumbing extended by this change.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes cover custom host vital criteria parsing, validation, membership, delete protection, and frontend enablement/selection as requested.
Out of Scope Changes check ✅ Passed The diff appears focused on the custom host vital label feature, with no obvious unrelated or out-of-scope changes.
Title check ✅ Passed The title is concise and accurately captures the main change: adding custom host vital support to host vitals labels across BE and FE.
Description check ✅ Passed The description covers the issue, change summary, automated tests, and manual QA; some template checklist sections are omitted, but the core info is present.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 48582-new-label-custom-host-vitals

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
server/datastore/mysql/custom_host_vitals.go (1)

240-276: 🗄️ Data Integrity & Integration | 🔵 Trivial | 💤 Low value

Delete-protection scan only checks top-level CustomHostVitalID.

The scan reads criteria.CustomHostVitalID directly without recursing into criteria.And/criteria.Or. This is safe today only because parseHostVitalCriteria (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

📥 Commits

Reviewing files that changed from the base of the PR and between 32ccf45 and c1ffe1b.

📒 Files selected for processing (13)
  • frontend/interfaces/label.ts
  • frontend/pages/labels/NewLabelPage/NewLabelPage.tsx
  • frontend/pages/labels/NewLabelPage/helpers.tests.ts
  • frontend/pages/labels/NewLabelPage/helpers.ts
  • frontend/services/entities/labels.ts
  • server/datastore/mysql/custom_host_vitals.go
  • server/datastore/mysql/custom_host_vitals_test.go
  • server/datastore/mysql/labels_test.go
  • server/fleet/custom_host_vitals.go
  • server/fleet/hosts.go
  • server/fleet/labels.go
  • server/service/labels.go
  • server/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.
@nulmete nulmete marked this pull request as ready for review July 14, 2026 02:30
@nulmete nulmete requested review from a team as code owners July 14, 2026 02:30
@nulmete nulmete merged commit 65dfc6a into 44954-custom-host-vitals Jul 14, 2026
40 checks passed
@nulmete nulmete deleted the 48582-new-label-custom-host-vitals branch July 14, 2026 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants