Echecs de mise a jour visibles : filtre Erreurs, compteur, detail par stack
- les stacks dont la derniere mise a jour a echoue (planification, bouton global ou manuelle) apparaissent dans le filtre « Erreurs », avec le message d'erreur sur la ligne et un compteur « mise(s) a jour en echec » ; point rouge du serveur dans la barre laterale - le resume d'une execution globale nomme les stacks en echec ; chaque echec est journalise avec son message (logs du conteneur) - un echec est efface par une execution « deja a jour » ou par une analyse qui trouve la stack a jour (il restait affiche indefiniment sinon) - Summary.failed dans /api/fleet et /api/summary Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LNfwm4pAXGnjhTkuJbvAZ5
This commit is contained in:
1 parent
b5aad6dbd3
commit
ac197bae7a
9 files changed
+120
-7
No files matched your search
@@ -140,7 +140,7 @@ function Shell({ me, reloadMe }: { me: Me; reloadMe: () => Promise<unknown> }) {
|
|||||||
const scans = Object.values(s.scans);
|
const scans = Object.values(s.scans);
|
||||||
if (!s.enabled) return "off";
|
if (!s.enabled) return "off";
|
||||||
if (scans.some((x) => x.error)) return "err";
|
if (scans.some((x) => x.error)) return "err";
|
||||||
if (scans.some((x) => x.stacks.some((st) => st.status === "error"))) return "err";
|
if (scans.some((x) => x.stacks.some((st) => st.status === "error" || (!!st.applied && !st.applied.ok && !st.excluded)))) return "err";
|
||||||
if (scans.some((x) => x.stacks.some((st) => st.status === "updates"))) return "upd";
|
if (scans.some((x) => x.stacks.some((st) => st.status === "updates"))) return "upd";
|
||||||
if (scans.length === 0) return "off";
|
if (scans.length === 0) return "off";
|
||||||
return "ok";
|
return "ok";
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ const statusLabel: Record<StackStatus, string> = {
|
|||||||
error: "Erreur",
|
error: "Erreur",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Derniere mise a jour (manuelle, programmee ou globale) en echec. */
|
||||||
|
export const failedApply = (st: Stack) => !!st.applied && !st.applied.ok && !st.excluded;
|
||||||
|
|
||||||
export function FleetView({ me, fleet, current, run, onEdit, onAdd, onKey }: Props) {
|
export function FleetView({ me, fleet, current, run, onEdit, onAdd, onKey }: Props) {
|
||||||
const [filter, setFilter] = useState<Filter>("all");
|
const [filter, setFilter] = useState<Filter>("all");
|
||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
@@ -73,11 +76,12 @@ export function FleetView({ me, fleet, current, run, onEdit, onAdd, onKey }: Pro
|
|||||||
const unreachable = servers.reduce((n, s) => n + Object.values(s.scans).filter((sc) => sc.error).length, 0);
|
const unreachable = servers.reduce((n, s) => n + Object.values(s.scans).filter((sc) => sc.error).length, 0);
|
||||||
const scanning = servers.some((s) => Object.values(s.scans).some((sc) => sc.running));
|
const scanning = servers.some((s) => Object.values(s.scans).some((sc) => sc.running));
|
||||||
const autoCount = all.filter((x) => x.auto).length;
|
const autoCount = all.filter((x) => x.auto).length;
|
||||||
|
const failCount = all.filter(failedApply).length;
|
||||||
const q = search.trim().toLowerCase();
|
const q = search.trim().toLowerCase();
|
||||||
|
|
||||||
const keep = (st: Stack) => {
|
const keep = (st: Stack) => {
|
||||||
if (filter === "updates" && (st.status !== "updates" || st.excluded)) return false;
|
if (filter === "updates" && (st.status !== "updates" || st.excluded)) return false;
|
||||||
if (filter === "problems" && st.status !== "error") return false;
|
if (filter === "problems" && st.status !== "error" && !failedApply(st)) return false;
|
||||||
return !q || st.name.toLowerCase().includes(q) || st.dir.toLowerCase().includes(q) || (st.services ?? []).some((s) => s.image.toLowerCase().includes(q));
|
return !q || st.name.toLowerCase().includes(q) || st.dir.toLowerCase().includes(q) || (st.services ?? []).some((s) => s.image.toLowerCase().includes(q));
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -101,6 +105,7 @@ export function FleetView({ me, fleet, current, run, onEdit, onAdd, onKey }: Pro
|
|||||||
<span className="stat">{plural(all.length, "stack")}</span>
|
<span className="stat">{plural(all.length, "stack")}</span>
|
||||||
<span className={`stat ${count("updates") ? "warn" : ""}`}>{plural(count("updates"), "mise")} à jour à faire</span>
|
<span className={`stat ${count("updates") ? "warn" : ""}`}>{plural(count("updates"), "mise")} à jour à faire</span>
|
||||||
{count("error") > 0 && <span className="stat err">{plural(count("error"), "erreur")}</span>}
|
{count("error") > 0 && <span className="stat err">{plural(count("error"), "erreur")}</span>}
|
||||||
|
{failCount > 0 && <span className="stat err">{plural(failCount, "mise")} à jour en échec</span>}
|
||||||
{unreachable > 0 && <span className="stat err">{plural(unreachable, "connexion")} en échec</span>}
|
{unreachable > 0 && <span className="stat err">{plural(unreachable, "connexion")} en échec</span>}
|
||||||
{count("stopped") > 0 && <span className="stat">{plural(count("stopped"), "arrêtée")}</span>}
|
{count("stopped") > 0 && <span className="stat">{plural(count("stopped"), "arrêtée")}</span>}
|
||||||
{autoCount > 0 && <span className="stat auto">{plural(autoCount, "stack")} en auto</span>}
|
{autoCount > 0 && <span className="stat auto">{plural(autoCount, "stack")} en auto</span>}
|
||||||
@@ -352,7 +357,7 @@ function TargetBlock({ server, target, scan, me, keep, filtering, onCheck, onApp
|
|||||||
<small className="muted">{st.dir}</small>
|
<small className="muted">{st.dir}</small>
|
||||||
</span>
|
</span>
|
||||||
<span className="stack-meta muted">
|
<span className="stack-meta muted">
|
||||||
{applying ? "pull, down puis up -d…" : st.status === "error" ? <span className="error-text clip" title={st.error}>{st.error}</span> : total > 0 ? (late > 0 ? `${late}/${plural(total, "image")} à mettre à jour` : plural(total, "image")) : ""}
|
{applying ? "pull, down puis up -d…" : st.status === "error" ? <span className="error-text clip" title={st.error}>{st.error}</span> : failedApply(st) ? <span className="error-text clip" title={st.applied?.message}>Échec de la mise à jour : {st.applied?.message}</span> : total > 0 ? (late > 0 ? `${late}/${plural(total, "image")} à mettre à jour` : plural(total, "image")) : ""}
|
||||||
</span>
|
</span>
|
||||||
{me.admin && st.status === "updates" && !applying && !st.excluded && (
|
{me.admin && st.status === "updates" && !applying && !st.excluded && (
|
||||||
<button className="primary" disabled={scan?.running} onClick={(e) => (e.stopPropagation(), onApply(st))} title="pull, down puis up -d">
|
<button className="primary" disabled={scan?.running} onClick={(e) => (e.stopPropagation(), onApply(st))} title="pull, down puis up -d">
|
||||||
|
|||||||
@@ -176,6 +176,8 @@ export interface Summary {
|
|||||||
stopped: number;
|
stopped: number;
|
||||||
unreachable: number;
|
unreachable: number;
|
||||||
scanning: number;
|
scanning: number;
|
||||||
|
/** Stacks (hors exclues) dont la derniere mise a jour a echoue. */
|
||||||
|
failed: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Fleet {
|
export interface Fleet {
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package fleet
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// scriptRunner repond la ligne A fournie pour chaque mise a jour.
|
||||||
|
type scriptRunner struct{ line string }
|
||||||
|
|
||||||
|
func (r *scriptRunner) Run(_ context.Context, _ string, _ int, _ string, _ []string, out func(string)) error {
|
||||||
|
out(r.line)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Un echec de mise a jour est compte (Summary.Failed), garde par l'analyse
|
||||||
|
// tant que la stack n'est pas a jour, efface par un « deja a jour » ou par une
|
||||||
|
// analyse qui trouve la stack a jour ; le message global nomme les stacks.
|
||||||
|
func TestApplyFailureVisibility(t *testing.T) {
|
||||||
|
hostPoll = 5 * time.Millisecond
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
run := &scriptRunner{line: "A\tfail\tup -d : port is already allocated"}
|
||||||
|
m, err := Open(ctx, t.TempDir(), run, 1)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
srv, _ := m.Add(Server{Name: "s1", Host: "h1", Enabled: true, Targets: []Target{{User: "root"}}})
|
||||||
|
tid := srv.Targets[0].ID
|
||||||
|
m.scans[Key(srv.ID, tid)] = &Scan{Stacks: []Stack{{Dir: "/home/a", Name: "a", Status: StatusUpdates}}}
|
||||||
|
|
||||||
|
ok, _, msg := m.applyAndWait(srv.ID, tid, "/home/a", AutoHostBy)
|
||||||
|
if ok || msg != "up -d : port is already allocated" {
|
||||||
|
t.Fatalf("echec attendu : %v %q", ok, msg)
|
||||||
|
}
|
||||||
|
if s := m.Summary(); s.Failed != 1 {
|
||||||
|
t.Fatalf("Failed = %d", s.Failed)
|
||||||
|
}
|
||||||
|
if _, msg := tally([]HostStackResult{{Name: "a", OK: false}, {Name: "b", OK: true, Skipped: true}}); msg != "2 stack(s) : 0 relancee(s), 1 sans changement, 1 en echec : a" {
|
||||||
|
t.Fatalf("message : %q", msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Analyse : la stack a toujours une mise a jour -> l'echec reste.
|
||||||
|
scan := func(state string) {
|
||||||
|
m.mu.Lock()
|
||||||
|
p := newScanParser(m.scans[Key(srv.ID, tid)])
|
||||||
|
for _, l := range []string{"S\t/home/a\tcompose.yml", "V\t/home/a\tweb\tnginx\taaa\tbbb\t" + state, "D\t/home/a"} {
|
||||||
|
p.Line(l)
|
||||||
|
}
|
||||||
|
p.Finish()
|
||||||
|
m.mu.Unlock()
|
||||||
|
}
|
||||||
|
scan("update")
|
||||||
|
if s := m.Summary(); s.Failed != 1 {
|
||||||
|
t.Fatalf("echec perdu a l'analyse : %d", s.Failed)
|
||||||
|
}
|
||||||
|
// « deja a jour » efface l'echec.
|
||||||
|
run.line = "A\tskip\tdeja a jour : aucune nouvelle image"
|
||||||
|
if ok, skipped, _ := m.applyAndWait(srv.ID, tid, "/home/a", AutoHostBy); !ok || !skipped {
|
||||||
|
t.Fatal("skip attendu")
|
||||||
|
}
|
||||||
|
if s := m.Summary(); s.Failed != 0 {
|
||||||
|
t.Fatalf("echec non efface par skip : %d", s.Failed)
|
||||||
|
}
|
||||||
|
// Nouvel echec, puis analyse qui trouve la stack a jour : efface.
|
||||||
|
run.line = "A\tfail\tpull : denied"
|
||||||
|
m.applyAndWait(srv.ID, tid, "/home/a", AutoHostBy)
|
||||||
|
scan("ok")
|
||||||
|
if s := m.Summary(); s.Failed != 0 {
|
||||||
|
t.Fatalf("echec non efface par l'analyse : %d", s.Failed)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -244,17 +244,29 @@ func (m *Manager) runHostAuto(serverID string, at time.Time) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
slog.Info("mise a jour globale programmee", "server", serverID, "result", msg)
|
slog.Info("mise a jour globale programmee", "server", serverID, "result", msg)
|
||||||
|
logFailures("mise a jour globale programmee", serverID, results)
|
||||||
}
|
}
|
||||||
|
|
||||||
// tally resume les resultats d'une execution globale.
|
// logFailures journalise le detail de chaque stack en echec.
|
||||||
|
func logFailures(what, serverID string, results []HostStackResult) {
|
||||||
|
for _, r := range results {
|
||||||
|
if !r.OK {
|
||||||
|
slog.Warn(what+" : echec", "server", serverID, "dir", r.Dir, "msg", r.Message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// tally resume les resultats d'une execution globale ; les stacks en echec
|
||||||
|
// sont nommees dans le message.
|
||||||
func tally(results []HostStackResult) (ok bool, msg string) {
|
func tally(results []HostStackResult) (ok bool, msg string) {
|
||||||
ok = true
|
ok = true
|
||||||
restarted, skipped, failed := 0, 0, 0
|
restarted, skipped := 0, 0
|
||||||
|
var failed []string
|
||||||
for _, r := range results {
|
for _, r := range results {
|
||||||
switch {
|
switch {
|
||||||
case !r.OK:
|
case !r.OK:
|
||||||
ok = false
|
ok = false
|
||||||
failed++
|
failed = append(failed, r.Name)
|
||||||
case r.Skipped:
|
case r.Skipped:
|
||||||
skipped++
|
skipped++
|
||||||
default:
|
default:
|
||||||
@@ -264,7 +276,11 @@ func tally(results []HostStackResult) (ok bool, msg string) {
|
|||||||
if len(results) == 0 {
|
if len(results) == 0 {
|
||||||
return true, "aucune stack a mettre a jour (lancer une analyse ?)"
|
return true, "aucune stack a mettre a jour (lancer une analyse ?)"
|
||||||
}
|
}
|
||||||
return ok, fmt.Sprintf("%d stack(s) : %d relancee(s), %d sans changement, %d en echec", len(results), restarted, skipped, failed)
|
msg = fmt.Sprintf("%d stack(s) : %d relancee(s), %d sans changement, %d en echec", len(results), restarted, skipped, len(failed))
|
||||||
|
if len(failed) > 0 {
|
||||||
|
msg += " : " + strings.Join(failed, ", ")
|
||||||
|
}
|
||||||
|
return ok, msg
|
||||||
}
|
}
|
||||||
|
|
||||||
// applyAndWait lance la mise a jour d'une stack et attend son resultat ; une
|
// applyAndWait lance la mise a jour d'une stack et attend son resultat ; une
|
||||||
|
|||||||
@@ -170,6 +170,9 @@ func (m *Manager) Summary() Summary {
|
|||||||
if st.Excluded {
|
if st.Excluded {
|
||||||
sum.Excluded++
|
sum.Excluded++
|
||||||
}
|
}
|
||||||
|
if st.Applied != nil && !st.Applied.OK && !st.Excluded {
|
||||||
|
sum.Failed++
|
||||||
|
}
|
||||||
switch st.Status {
|
switch st.Status {
|
||||||
case StatusUpdates:
|
case StatusUpdates:
|
||||||
if !st.Excluded {
|
if !st.Excluded {
|
||||||
@@ -530,6 +533,11 @@ func (m *Manager) runApply(srv Server, t Target, dir, by string) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if skipped {
|
if skipped {
|
||||||
|
// Rien a faire : un echec precedent n'a plus lieu d'etre affiche.
|
||||||
|
if st.Applied != nil && !st.Applied.OK {
|
||||||
|
r := res
|
||||||
|
st.Applied = &r
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r := res
|
r := res
|
||||||
|
|||||||
@@ -102,6 +102,8 @@ type Summary struct {
|
|||||||
Stopped int `json:"stopped"`
|
Stopped int `json:"stopped"`
|
||||||
Unreachable int `json:"unreachable"`
|
Unreachable int `json:"unreachable"`
|
||||||
Scanning int `json:"scanning"`
|
Scanning int `json:"scanning"`
|
||||||
|
// Failed : stacks (hors exclues) dont la derniere mise a jour a echoue.
|
||||||
|
Failed int `json:"failed"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@@ -66,6 +66,10 @@ func (p *scanParser) Line(line string) {
|
|||||||
}
|
}
|
||||||
if old, ok := p.prev[st.Dir]; ok {
|
if old, ok := p.prev[st.Dir]; ok {
|
||||||
st.Applied = old.Applied
|
st.Applied = old.Applied
|
||||||
|
// Echec de mise a jour devenu sans objet : la stack est a jour.
|
||||||
|
if st.Status == StatusUpToDate && st.Applied != nil && !st.Applied.OK {
|
||||||
|
st.Applied = nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
p.seen[st.Dir] = true
|
p.seen[st.Dir] = true
|
||||||
p.merge(st)
|
p.merge(st)
|
||||||
|
|||||||
@@ -96,6 +96,9 @@ func (m *Manager) UpdateAll(user string) (int, error) {
|
|||||||
r := GlobalStackResult{ServerID: p.srv.ID, Server: p.srv.Name,
|
r := GlobalStackResult{ServerID: p.srv.ID, Server: p.srv.Name,
|
||||||
HostStackResult: HostStackResult{Target: j.t.ID, User: j.t.User, Dir: j.stack.Dir, Name: j.stack.Name}}
|
HostStackResult: HostStackResult{Target: j.t.ID, User: j.t.User, Dir: j.stack.Dir, Name: j.stack.Name}}
|
||||||
r.OK, r.Skipped, r.Message = m.applyAndWait(p.srv.ID, j.t.ID, j.stack.Dir, by)
|
r.OK, r.Skipped, r.Message = m.applyAndWait(p.srv.ID, j.t.ID, j.stack.Dir, by)
|
||||||
|
if !r.OK {
|
||||||
|
slog.Warn("mise a jour globale : echec", "server", p.srv.Name, "dir", j.stack.Dir, "msg", r.Message)
|
||||||
|
}
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
g.Results = append(g.Results, r)
|
g.Results = append(g.Results, r)
|
||||||
g.Done++
|
g.Done++
|
||||||
|
|||||||
Reference in new issue
Block a user