Skip to content

Improve custom host vital missing-value error message - #49640

Merged
nulmete merged 2 commits into
mainfrom
custom-host-vital-empty-value-err-msg
Jul 21, 2026
Merged

Improve custom host vital missing-value error message#49640
nulmete merged 2 commits into
mainfrom
custom-host-vital-empty-value-err-msg

Conversation

@nulmete

@nulmete nulmete commented Jul 21, 2026

Copy link
Copy Markdown
Member

Related issue: Resolves #44954

When a custom host vital referenced in a script or profile has no value set for a host, the delivery failure detail didn't name the vital, making it hard for admins to tell which one needed a value. The message now includes both the vital's name and its $FLEET_HOST_VITAL_<id> token.

Testing

  • Added/updated automated tests

  • QA'd all new/changed functionality manually

Summary by CodeRabbit

  • Bug Fixes
    • Improved missing custom host vital error messages by including both the vital name and its corresponding environment variable identifier.
    • Updated the wording to be clearer about why values can’t be populated when no value is set for the host.
    • Kept singular vs. plural messaging correct when one or multiple vital values are missing.

…d its variable

Include the custom host vital's name alongside its $FLEET_HOST_VITAL_<id>
token so the delivery failure detail is actionable for admins.
Copilot AI review requested due to automatic review settings July 21, 2026 12:55
@nulmete
nulmete marked this pull request as ready for review July 21, 2026 12:56
@nulmete
nulmete requested a review from a team as a code owner July 21, 2026 12:56

Copilot AI 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.

Pull request overview

Improves the admin-facing delivery failure detail when a referenced custom host vital has no per-host value, by including both the vital’s human name and its $FLEET_HOST_VITAL_<id> token. This makes it easier to identify which vital needs a value set on the host.

Changes:

  • Extend MissingCustomHostVitalValueError to carry vital names alongside IDs and render them in the error message.
  • Populate missing vital names during datastore expansion (ExpandCustomHostVitals).
  • Update/extend tests to assert the new error payload and message content.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
server/fleet/custom_host_vitals.go Adds MissingNames to the error type and updates the error string to include name (token).
server/fleet/custom_host_vitals_test.go Updates tests to validate the new error message format (single + multi).
server/datastore/mysql/custom_host_vitals.go Collects missing vital names during expansion and returns them in the error.
server/datastore/mysql/software_installers_test.go Extends integration test assertions to include MissingNames in the returned error.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +91 to 97
for i, id := range e.MissingIDs {
var name string
if i < len(e.MissingNames) {
name = e.MissingNames[i]
}
tokens = append(tokens, fmt.Sprintf("%s ($%s%d)", name, CustomHostVitalPrefix, id))
}
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 90f2c4b2-f82d-4fb8-9630-5635f4b22df9

📥 Commits

Reviewing files that changed from the base of the PR and between 7f95d5a and 5fe0af3.

📒 Files selected for processing (1)
  • server/fleet/custom_host_vitals.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • server/fleet/custom_host_vitals.go

Walkthrough

Custom host vital expansion now records names corresponding to missing vital IDs. MissingCustomHostVitalValueError stores these names and includes them with $FLEET_HOST_VITAL_<id> tokens in formatted messages. Unit and installer tests were updated for the enriched error data and message format.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: improving the custom host vital missing-value error message.
Description check ✅ Passed The description includes the related issue, the user-visible change, and testing confirmation.
Linked Issues check ✅ Passed The change matches #44954's requirement to identify missing custom host vitals by name and token in delivery errors.
Out of Scope Changes check ✅ Passed The modified files and tests are all directly related to the missing-value error behavior, with no obvious unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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 custom-host-vital-empty-value-err-msg

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.

@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.89%. Comparing base (bd8f1e8) to head (5fe0af3).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #49640      +/-   ##
==========================================
+ Coverage   67.85%   67.89%   +0.04%     
==========================================
  Files        3889     3889              
  Lines      247605   248324     +719     
  Branches    13022    13022              
==========================================
+ Hits       168004   168602     +598     
- Misses      64450    64523      +73     
- Partials    15151    15199      +48     
Flag Coverage Δ
backend 69.28% <100.00%> (+0.04%) ⬆️

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.

Copilot AI review requested due to automatic review settings July 21, 2026 13:17

Copilot AI 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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

server/fleet/custom_host_vitals.go:96

  • If MissingNames is empty/shorter than MissingIDs (e.g. callers that only set MissingIDs), the formatted token becomes " ($FLEET_HOST_VITAL_)" with a leading space and no name. Consider falling back to just the token when the name is missing/blank to keep the error message readable and resilient to partial struct initialization.
	for i, id := range e.MissingIDs {
		var name string
		if i < len(e.MissingNames) {
			name = e.MissingNames[i]
		}
		tokens = append(tokens, fmt.Sprintf("%s ($%s%d)", name, CustomHostVitalPrefix, id))

@sharon-fdm sharon-fdm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Claude-generated review -- minor items only, LGTM overall.

Also noting: missing change file (changes/ directory). This is a user-visible error message improvement, so it should have one for the changelog.

tokens = append(tokens, fmt.Sprintf("\"$%s%d\"", CustomHostVitalPrefix, id))
for i, id := range e.MissingIDs {
var name string
if i < len(e.MissingNames) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Minor: when the guard fails (or the name in the map was empty due to a deleted vital), name is "", producing a message like " ($FLEET_HOST_VITAL_42)" with a leading space and no name. Consider a fallback:

Suggested change
if i < len(e.MissingNames) {
if i < len(e.MissingNames) && e.MissingNames[i] != "" {
name = e.MissingNames[i]
} else {
name = fmt.Sprintf("$%s%d", CustomHostVitalPrefix, id)
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think this would be too defensive and it's not a real-world scenario for a vital to have an empty name (it's required for the insertion at the DB layer).

@nulmete

nulmete commented Jul 21, 2026

Copy link
Copy Markdown
Member Author

Claude-generated review -- minor items only, LGTM overall.

Also noting: missing change file (changes/ directory). This is a user-visible error message improvement, so it should have one for the changelog.

Changes file was already included as part of the feature (#44954), this is just a follow-up which will land with the entire feature.

@nulmete
nulmete requested a review from sharon-fdm July 21, 2026 13:47

@sharon-fdm sharon-fdm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@nulmete
nulmete merged commit 5d8296c into main Jul 21, 2026
45 checks passed
@nulmete
nulmete deleted the custom-host-vital-empty-value-err-msg branch July 21, 2026 13:54
nulmete added a commit that referenced this pull request Jul 21, 2026
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.

Add/edit/delete custom host vitals

3 participants