Files
archie/internal/releaseupdate/report_event.go
T
sam 30228f3449 refactor(archied): move the update relay to the process that owns updates
The dashboard's Run read the watchdog's phase-2 report off local disk and
put it on the activity stream. That is a host-local file read in the process
that is moving off the host: the watchdog restarts archied and leaves its
verdict beside archied, so archied is what can read it.

The daemon now polls and relays it, publishing the same event through the
same bus, so it persists with every other event and reaches whichever
dashboard is watching. The event builder moves to releaseupdate, which owns
Report and its verification; the dashboard keeps only what it needs to tell
an installer where to write.

The startup poll stays: the watchdog writes its result only once the process
answers /healthz, so a single read at boot can always miss the report
describing that very boot.

persistAndBroadcastEvents takes the daemon context and detaches it for the
insert, which is what it always did with context.Background() -- the last
events of a run are the ones an operator reads afterwards.
2026-09-09 23:55:20 +10:00

74 lines
2.9 KiB
Go

package releaseupdate
import (
"fmt"
"sort"
"strings"
"github.com/samcharles93/archie-core/internal/events"
)
// ReportEvent turns a phase-2 Report, plus its verification against
// the versions actually running, into the activity-stream event the
// dashboard renders. Unlike Telegram's formatPendingReport, this ships the
// structured Verification rather than pre-rendered prose, so the frontend
// controls presentation -- the two channels' operators read the same facts
// through different UIs, not necessarily the same sentence.
func ReportEvent(report Report, running map[string]string) events.Event {
verification := report.Verify(running)
drift := make([]map[string]any, 0, len(verification.Drift))
for _, d := range verification.Drift {
drift = append(drift, map[string]any{
"id": d.ID,
"claimed": d.Claimed,
"running": d.Running,
"running_is_previous": d.RunningIsPrevious,
})
}
return events.Event{
Kind: events.KindUpdateReport,
Detail: summarizeReport(report, verification),
Data: map[string]any{
"health_check": report.HealthCheck,
"rolled_back": report.RolledBack,
"previous": report.Previous,
"installed": report.Installed,
"confirmed": verification.Confirmed,
"drift": drift,
"unverified": verification.Unverified,
},
}
}
// summarizeReport is the one-line summary shown in the dashboard's
// activity feed, which renders event.Detail generically for every event
// kind (see ui/src/dashboard/dashboard.js activityRow). It condenses the
// same facts internal/channels/telegram/update.go's formatPendingReport
// spells out at length -- not a byte-identical wording, since the two
// surfaces render differently, but the same four outcomes: confirmed,
// drifted, unverified, or rolled back.
func summarizeReport(report Report, verification Verification) string {
if report.RolledBack {
return "Update failed its health check and was rolled back to the previous version."
}
if report.HealthCheck != "passed" {
return "Update failed its health check and could NOT be rolled back automatically -- manual intervention required."
}
if len(verification.Drift) > 0 {
ids := make([]string, 0, len(verification.Drift))
for _, d := range verification.Drift {
ids = append(ids, fmt.Sprintf("%s reports %s, not the installed %s", d.ID, d.Running, d.Claimed))
}
sort.Strings(ids)
return "Update did NOT take effect: " + strings.Join(ids, "; ") + "."
}
if len(verification.Confirmed) == 0 {
return "Update installed and health check passed, but the running version could not be verified -- please check manually before assuming the update worked."
}
text := "Update complete. Health check passed -- confirmed running on the new version (" + strings.Join(verification.Confirmed, ", ") + ")."
if len(verification.Unverified) > 0 {
text += " Not independently checked: " + strings.Join(verification.Unverified, ", ") + "."
}
return text
}