PMM-15295 Warn on Nomad without public address. - #5849
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5849 +/- ##
==========================================
+ Coverage 43.59% 45.56% +1.97%
==========================================
Files 415 217 -198
Lines 43134 28116 -15018
==========================================
- Hits 18804 12811 -5993
+ Misses 22454 13920 -8534
+ Partials 1876 1385 -491 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🔗 Linked repositories identifiedCodeRabbit considers these linked repositories for cross-repo context during reviews:
Included review availability: Your plan provides up to 4 included reviews per hour; 2 remain after this review. Walkthrough
Merge Risk: ⚪ Minimal · up to This change warns operators when Nomad is enabled without the required public address, without altering service behavior or access controls. No actionable merge-blocking risk remains beyond normal checks and review. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Full details: Description checkExplanation The description includes the required ticket number and feature build, explains what, why, and how, documents behavior and testing, and identifies out-of-scope work. The API documentation checkbox is not required because this PR does not alter API endpoints. 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 |
yyyyyyyan
left a comment
There was a problem hiding this comment.
@JiriCtvrtka — This lands cleanly. The cross-check reuses the warns slice ParseEnvVars already returns rather than adding plumbing, errs stays untouched so boot behaviour is unchanged, and TestNomadWithoutPublicAddress exercises both sub-terms of the predicate in both directions plus the PMM_ENABLE_NOMAD=maybe row — that last one is the case easiest to forget. 1b8f7b4 also caught something subtle: the public address can come from Settings rather than the environment.
Two things I'd like to see before merge. They are the same observation from two sides.
The Nomad reference now contradicts the runtime. The page still tells operators the skip happens "with no error or warning", which is precisely what this PR changes:
pmm/documentation/docs/reference/nomad.md
Line 28 in 1b8f7b4
That page is where someone debugging an unexplained Nomad failure ends up, so leaving it saying there is nothing to look for in the log gives back most of what the warning buys. I checked the neighbours — env_var.md's "has no effect" and "Nomad does not start" both stay true — so this single sentence looks like the whole edit.
The check is environment-scoped and the comment above it is not. IsNomadEnabled() is pointer.GetBool(s.Nomad.Enabled) && s.PMMPublicAddress != "" over the merged settings (managed/models/settings.go:166), and UpdateSettings overwrites PMMPublicAddress only when the parsed pointer is non-nil (managed/models/settings_helpers.go:218). On an instance whose address was set through Configuration > Settings > Advanced settings — the route nomad.md:19 documents, restart included — PMM_ENABLE_NOMAD=1 alone makes this warning fire on every start while Nomad is up and healthy.
I would keep the check where it is: pmm-managed-init has no database, so the environment really is all it can see, and catching the common case at the earliest point is worth a false positive on the Settings route. The message already hedges for it. What I would change is the comment, so the next reader does not "correct" the message back to the unhedged form — suggestion inline. (If you would rather make it exact, UpdateSettingsFromEnv already has the merged settings in hand — models.UpdateSettings returns them and the result is currently discarded — and !settings.IsNomadEnabled() && pointer.GetBool(settings.Nomad.Enabled) would be precise there. It costs the pmm-managed-init line, which is the one an operator watching the container start sees first, so I do not think it is the better trade.)
| // Nomad needs the public address to build the URL agents connect back to, so enabling it | ||
| // without one leaves the Nomad server silently not started. |
There was a problem hiding this comment.
The first clause holds — advertise.rpc in managed/services/nomad/server.hcl is the public address, and the server certificate is named after it. It is the second clause I would reword. "Silently" is what this PR removes, and "without one" claims more than the condition below can support: it sees only the environment, so an address already stored in Settings keeps Nomad running while this still fires. 1b8f7b4 already taught the message that distinction; the comment is the last place holding the unhedged version, and it is the version a future reader will trust when tidying the string.
| // Nomad needs the public address to build the URL agents connect back to, so enabling it | |
| // without one leaves the Nomad server silently not started. | |
| // Nomad needs the public address to build the URL agents connect back to. Only the | |
| // environment is visible here, so an address held only in Settings warns anyway. |
Writing the guard as pointer.GetBool(envSettings.EnableNomad) && pointer.GetString(envSettings.PMMPublicAddress) == "" would help too — it makes this the visible mirror of IsNomadEnabled() rather than a second spelling of the same question.
Ticket number: PMM-15295
Feature build: SUBMODULES-0
What
Emit a configuration warning when
PMM_ENABLE_NOMADis set butPMM_PUBLIC_ADDRESSis not, instead of silently skipping the Nomad server.Why
Nomad needs both variables. With the flag alone,
Settings.IsNomadEnabled()returns false andsupervisordskips thenomad-servertemplate — no error, no warning. The container is healthy and PMM works, so nothing indicates why nothing can be executed.This cost real debugging time during SEP integration testing: SEP dispatches task execution through PMM's embedded Nomad, so the failure surfaces as "SEP cannot run anything", several layers away from one unset variable. The requirement is documented in
documentation/docs/reference/nomad.md, but the runtime said nothing.How
A post-loop cross-check in
ParseEnvVarsappending to the existingwarnslist — no new plumbing:The warning reaches the operator through the same channel as every other environment-variable warning:
pmm-managed-init/main.gologs it asConfiguration warning: %s, andserver.govias.l.WarnlnonUpdateSettingsFromEnv.This is a diagnostic, not a new failure mode. Only
warnsis appended to;errsis untouched, sopmm-managed-initdoes not exit and PMM starts exactly as before.Behaviour
Environment | Warning -- | -- PMM_ENABLE_NOMAD=1, no public address | yes PMM_ENABLE_NOMAD=1, PMM_PUBLIC_ADDRESS= (empty) | yes — IsNomadEnabled() also treats empty as disabled PMM_ENABLE_NOMAD=1 + public address | no PMM_ENABLE_NOMAD=0 | no Neither set | no Public address only | no PMM_ENABLE_NOMAD=maybe | no — the existing parse error already reports itTesting
TestNomadWithoutPublicAddressinmanaged/utils/envvars/parser_test.gocovers every row above. Statement and branch coverage of the new block is complete, and each sub-term of the predicate is exercised both true and false.go test ./managed/utils/envvars/...— passbin/golangci-lint run managed/utils/envvars/...— 0 issuesgo build ./managed/...,go vet— cleanOut of scope
Changing the requirement itself — Nomad genuinely needs the public address.