7c05b59708
gates / gates (push) Successful in 24s
179 Hungarian sentences were built deep inside a package with fmt.Errorf and printed by whoever caught them: too late to translate where they are shown, too early where they are made. Every one now carries its key across that gap. ZERO Hungarian error literals remain. util.MsgError does three things at once, each earned: - Error() is the Hungarian, byte for byte, so every un-converted printer is unchanged; - errors.Is answers for the kind AND for a wrapped cause (KindErrorf dropped the cause); - an error ARGUMENT renders recursively, so "formázás sikertelen: %w" translates whole. A foreign error — restic, docker, ssh, the stdlib — prints verbatim. It is not ours. 76 display sites go through errText, and TestNoErrErrorInPageOutput convicts any that do not. memoryVerdict returns an error rather than a sentence, so the deploy's 409 and the household's language come from one value; UpdateRefusal gained a Cause to carry it. Plurals, one rule, stated once: a key with .one/.other takes its COUNT first. Not a per-call-site flag — the producer somebody forgot would read "3 app is not running". The guard caught a real key collision (alert.deadapp.one) the day the rule landed. TWO DEFECTS FOUND IN MY OWN TOOLING, recorded rather than quietly fixed. The bulk converter silently dropped multi-line concatenations, damaging 7 producers — and the parity gate could not see it, because every surviving fragment WAS a real base literal while the CALL had lost text; two behaviour tests caught it. And the counting script was case-sensitive, so it said "0 left" while five remained. MinAgent: 0.131.0 (unchanged). No hub release needed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
104 lines
4.4 KiB
Go
104 lines
4.4 KiB
Go
package web
|
||
|
||
import (
|
||
"net/http"
|
||
"sort"
|
||
|
||
"gitea.dooplex.hu/admin/felhom-controller/internal/agentapi"
|
||
)
|
||
|
||
// Agent-backed host metrics (slice 9).
|
||
//
|
||
// The de-privileged controller (slice 8C) sees only its own cgroup, so it cannot read host
|
||
// health itself. This thin proxy forwards GET /api/host-metrics to the agent's GET /host/metrics
|
||
// and returns the host-wide view (cpu%/mem/load/uptime/cpu-temp + per-storage capacity) for the
|
||
// monitoring page. It reuses the same pinned agentapi.Client + {ok,data,error} envelope as the
|
||
// disk proxy (agent_disk_handlers.go). Read-only; no CSRF mutation.
|
||
|
||
// ServeHostMetricsAPI proxies GET /api/host-metrics → agent GET /host/metrics.
|
||
// Wired in main.go behind RequireAuth.
|
||
func (s *Server) ServeHostMetricsAPI(w http.ResponseWriter, r *http.Request) {
|
||
if s.isDebug() {
|
||
s.logger.Printf("[DEBUG] [web] ServeHostMetricsAPI: %s %s from %s", r.Method, r.URL.Path, r.RemoteAddr)
|
||
}
|
||
if r.Method != http.MethodGet {
|
||
writeDiskJSON(w, http.StatusMethodNotAllowed, false, "method not allowed", nil)
|
||
return
|
||
}
|
||
client, err := s.agentClient()
|
||
if err != nil {
|
||
// Unprovisioned guest / no local API configured — the UI shows "host metrics unavailable".
|
||
writeDiskJSON(w, http.StatusServiceUnavailable, false, s.errText(r, err), nil)
|
||
return
|
||
}
|
||
resp, err := client.HostMetrics(r.Context())
|
||
if err != nil {
|
||
s.logger.Printf("[ERROR] [web] host metrics via agent failed: %v", err)
|
||
writeDiskJSON(w, http.StatusBadGateway, false, s.errText(r, err), nil)
|
||
return
|
||
}
|
||
// The agent enumerates storages via `pvesm` in a non-deterministic order, so #host-storage-bars
|
||
// reordered on every poll (item 2). Stabilise the order Go-side and attach friendly Hungarian
|
||
// labels + a one-line purpose per entry — display-only; we NEVER rename the PVE storage ids.
|
||
enrichHostStorageTargets(resp.StorageTargets)
|
||
writeDiskJSON(w, http.StatusOK, true, "", resp)
|
||
}
|
||
|
||
// enrichHostStorageTargets sorts the host's storage targets into a stable, customer-meaningful
|
||
// order (user-data → system+apps → backup → other; alphabetical by id within a tier) and fills in
|
||
// a friendly label + purpose per entry. Mirrors the disk-overview's sortDisksForView contract:
|
||
// a Go-side ordering beats relying on the agent's enumeration order or template JS.
|
||
func enrichHostStorageTargets(targets []agentapi.StorageTarget) {
|
||
sort.SliceStable(targets, func(i, j int) bool {
|
||
if ri, rj := storageTypeRank(targets[i].Type), storageTypeRank(targets[j].Type); ri != rj {
|
||
return ri < rj
|
||
}
|
||
return targets[i].Name < targets[j].Name
|
||
})
|
||
for i := range targets {
|
||
label, purpose := storageLabelAndPurpose(targets[i])
|
||
targets[i].Label = label
|
||
targets[i].Purpose = purpose
|
||
}
|
||
}
|
||
|
||
// storageTypeRank orders storage by what the customer cares about: where their app data lives
|
||
// first, then the system/app disk, then backup targets. Lower sorts first.
|
||
func storageTypeRank(typ string) int {
|
||
switch typ {
|
||
case "usb", "local-dir":
|
||
return 0 // external user-data drives (where browsable app data lives)
|
||
case "lvmthin", "lvm":
|
||
return 1 // the internal SSD: OS + the guest/app volumes
|
||
case "local":
|
||
return 2 // builtin dir: templates + local vzdump backups
|
||
case "pbs", "nfs", "cifs":
|
||
return 3 // backup targets (offsite / network)
|
||
default:
|
||
return 4
|
||
}
|
||
}
|
||
|
||
// storageLabelAndPurpose maps a storage target to a friendly Hungarian label + one-line purpose.
|
||
// Falls back to the raw id for unrecognised types. The raw id stays in Name (rendered muted).
|
||
func storageLabelAndPurpose(t agentapi.StorageTarget) (string, string) {
|
||
switch t.Type {
|
||
case "usb":
|
||
return "Külső adattároló (USB)", "Az alkalmazások adatai (fájlok, médiatár) ezen a meghajtón vannak."
|
||
case "local-dir":
|
||
return "Külső adattároló", "Az alkalmazások adatai (fájlok, médiatár) ezen a meghajtón vannak."
|
||
case "lvmthin", "lvm":
|
||
return "Belső SSD – rendszer és alkalmazások", "Az operációs rendszer és a telepített alkalmazások tárhelye."
|
||
case "local":
|
||
return "Belső lemez – sablonok és helyi mentések", "Rendszersablonok és helyi biztonsági mentések."
|
||
case "pbs":
|
||
return "Távoli biztonsági mentés", "Titkosított, telephelyen kívüli biztonsági mentések."
|
||
case "nfs":
|
||
return "Hálózati mentés (NFS)", "Hálózati tárolón őrzött biztonsági mentések."
|
||
case "cifs":
|
||
return "Hálózati mentés (SMB)", "Hálózati tárolón őrzött biztonsági mentések."
|
||
default:
|
||
return t.Name, ""
|
||
}
|
||
}
|