fix(update): verify an update took effect instead of trusting the report (#530)
A pending update report used to be relayed verbatim. It is entirely self-reported: scripts/archie-update-watchdog decides "passed" from `curl -sf $HEALTH_URL/healthz`, which only proves that *a* daemon is answering, then copies the version the installer *intended* (ARCHIE_UPDATE_INSTALLED_GATEWAY) into the report. If the new binary never made it into service, the previous daemon answers the probe just as happily, so the message read "Update complete: daemon 1.9.8 -> 1.9.0. Health check passed - archie-core is healthy on the new version" about a version that was not running. That shipped: /update reported success and the next task hit the exact bug the update was meant to fix (#468). Report.Verify now checks the claims against the versions components report for *themselves* -- archied's compiled-in gatewayVersion, which no installer can talk it out of -- and partitions every claimed component into Confirmed, Drift or Unverified. What changed in MEANING: - A passed health check used to mean "the new version is running". It now means only "something answered"; the version claim is a separate, separately-checked assertion. - "Update complete ... healthy on the new version" used to be the only success wording. There are now three outcomes, because collapsing them is how the false success happened: confirmed, unconfirmed ("I could not confirm which version is actually running"), and contradicted ("Update did NOT take effect"). - An unverifiable component is NOT a failing one. Absent, empty, "unknown" (the watchdog's own default) and "dev" (an unstamped build) all mean "we could not check", never "it is wrong" -- treating them as drift would turn healthy updates whose bookkeeping went missing into reported failures. Verification covers the daemon only, deliberately. archied's compiled-in runtimeVersion records what its own pipeline stamped, not what the agent container runs, so vouching for the agent would be the same kind of guess this change exists to remove. The agent is therefore Unverified on every successful update, and the success message names it as unchecked rather than letting the confirmed daemon silently vouch for it. Drift detail is attached per component: one component can sit on the version the update meant to replace while another is on some third version, and a single explanatory sentence would state a falsehood about one of them. Regression tests were confirmed to fail against the pre-fix code, reproducing the exact false-success string, and each new guard was mutation-tested. The drift-ordering test's component count is load-bearing and documented: Go rotates small maps rather than permuting them, so 8 components let an unsorted implementation pass ~12% of the time while 9 fails it outright. Refs #522, #468
This commit is contained in:
1 parent
e19ff3a1de
commit
2873cbba82
7 files changed
+677
-23
No files matched your search
@@ -96,6 +96,7 @@ func setupTelegramGateway(ctx context.Context, s telegramSetup) (start func(), o
|
||||
},
|
||||
}
|
||||
tg.UpdateReportPath = updateReportPath(cfg.WorkDir, cfg.BotUser)
|
||||
tg.RunningVersions = daemonRunningVersions
|
||||
tg.Reload = makeTelegramReload(s)
|
||||
|
||||
sessionStore := s.SessionStore
|
||||
@@ -120,6 +121,22 @@ func setupTelegramGateway(ctx context.Context, s telegramSetup) (start func(), o
|
||||
}, true
|
||||
}
|
||||
|
||||
// daemonRunningVersions reports the component versions this process can
|
||||
// vouch for from its own build, for checking a pending update report against
|
||||
// (see releaseupdate.Report.Verify).
|
||||
//
|
||||
// Only the daemon is listed, and that is the whole point: gatewayVersion is
|
||||
// compiled into this binary, so if an installer claims it put a version into
|
||||
// service and this value disagrees, the installer is wrong. runtimeVersion
|
||||
// is deliberately NOT reported for the agent -- it records the agent version
|
||||
// archied's own release pipeline stamped, not the version the agent
|
||||
// container is actually running, and the two diverge in exactly the
|
||||
// situation this check exists to detect. An unverifiable component is left
|
||||
// out so it is reported as unchecked rather than as confirmed.
|
||||
func daemonRunningVersions() map[string]string {
|
||||
return map[string]string{releaseupdate.ComponentDaemon: gatewayVersion}
|
||||
}
|
||||
|
||||
func configureTelegramUpdates(tg *telegram.Gateway, s telegramSetup) {
|
||||
if updates := makeUpdateService(s); updates != nil {
|
||||
tg.Updates = updates
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
"github.com/samcharles93/archie-core/internal/installtype"
|
||||
"github.com/samcharles93/archie-core/internal/releaseupdate"
|
||||
)
|
||||
|
||||
// TestMakeUpdateServiceWiresInstallType is the regression test for
|
||||
@@ -26,3 +27,22 @@ func TestMakeUpdateServiceWiresInstallType(t *testing.T) {
|
||||
t.Errorf("Service.InstallType = %q, want installtype.Type() = %q", service.InstallType, installtype.Type())
|
||||
}
|
||||
}
|
||||
|
||||
// TestDaemonRunningVersionsVouchesOnlyForItself: the point of checking a
|
||||
// pending update report against running versions is that the value checked
|
||||
// against is ground truth. This process's own compiled-in version is; the
|
||||
// agent's is not, because runtimeVersion records what archied's release
|
||||
// pipeline stamped, not what the agent container is actually running.
|
||||
// Including a guess here would recreate the false success the check exists
|
||||
// to catch, so its absence is the assertion.
|
||||
func TestDaemonRunningVersionsVouchesOnlyForItself(t *testing.T) {
|
||||
running := daemonRunningVersions()
|
||||
|
||||
if got := running[releaseupdate.ComponentDaemon]; got != gatewayVersion {
|
||||
t.Errorf("running[%q] = %q, want gatewayVersion = %q", releaseupdate.ComponentDaemon, got, gatewayVersion)
|
||||
}
|
||||
if _, ok := running[releaseupdate.ComponentAgent]; ok {
|
||||
t.Errorf("running vouches for %q, which this process cannot verify: %#v",
|
||||
releaseupdate.ComponentAgent, running)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user