From 12adcc5abc8a823b9410e6efe5a7f4d1f4c24352 Mon Sep 17 00:00:00 2001 From: "juvenal.diaz" Date: Wed, 4 Nov 2026 13:22:07 -0600 Subject: [PATCH] Distinguish recent Gitea disconnects from active failures --- cmd/jeannie-core/main.go | 6 ++--- cmd/jeannie-core/main_test.go | 15 +++++++++++ docs/app-ops.md | 11 ++++++++ docs/templates/app-ops.md.tmpl | 11 ++++++++ lib/jeannie/commands.sh | 46 ++++++++++++++++++++++++++++------ scripts/report-ui | 4 +-- 6 files changed, 80 insertions(+), 13 deletions(-) diff --git a/cmd/jeannie-core/main.go b/cmd/jeannie-core/main.go index b097e72..c0db7c7 100644 --- a/cmd/jeannie-core/main.go +++ b/cmd/jeannie-core/main.go @@ -370,14 +370,14 @@ func includeReportRow(row reportRow, only string) bool { case "warnings": return row.Status == "warn" case "problems": - return row.Status == "fail" || row.Status == "warn" + return row.Status == "fail" || row.Status == "warn" || row.Status == "info" default: return true } } func renderReportText(out io.Writer, title string, rows []reportRow, details bool, only string) { - counts := map[string]int{"fail": 0, "warn": 0, "ok": 0, "skip": 0} + counts := map[string]int{"fail": 0, "warn": 0, "info": 0, "ok": 0, "skip": 0} for _, row := range rows { counts[row.Status]++ } @@ -387,7 +387,7 @@ func renderReportText(out io.Writer, title string, rows []reportRow, details boo if profile := os.Getenv("LAB_CLUSTER_PROFILE"); profile != "" { fmt.Fprintf(out, "profile=%s runtime=%s kubeconfig=%s\n", profile, os.Getenv("LAB_CLUSTER_RUNTIME"), os.Getenv("KUBECONFIG_PATH")) } - fmt.Fprintf(out, "fail=%d warn=%d ok=%d skip=%d\n", counts["fail"], counts["warn"], counts["ok"], counts["skip"]) + fmt.Fprintf(out, "fail=%d warn=%d info=%d ok=%d skip=%d\n", counts["fail"], counts["warn"], counts["info"], counts["ok"], counts["skip"]) if len(rows) == 0 { switch only { diff --git a/cmd/jeannie-core/main_test.go b/cmd/jeannie-core/main_test.go index 1f8ba39..f0863bd 100644 --- a/cmd/jeannie-core/main_test.go +++ b/cmd/jeannie-core/main_test.go @@ -32,6 +32,21 @@ func TestReportRenderProblemsOnly(t *testing.T) { } } +func TestRecentInformationalEventDoesNotSuggestFix(t *testing.T) { + input := "info\tRecent events\tGitea client disconnects\tHTTP checks pass; no fix indicated\tdetail\t\t\t\n" + var output bytes.Buffer + if err := runReportRender([]string{"--title", "Status", "--only", "problems"}, strings.NewReader(input), &output); err != nil { + t.Fatal(err) + } + got := output.String() + if !strings.Contains(got, "info=1") || !strings.Contains(got, "no fix indicated") { + t.Fatalf("recent event missing from report:\n%s", got) + } + if strings.Contains(got, "Next Fix") || strings.Contains(got, "Highest Impact Focus") { + t.Fatalf("informational event was treated as a failure:\n%s", got) + } +} + func TestReportRenderHidesOKGraphAndQuery(t *testing.T) { input := "ok\tArea\tHealthy\tok\tdetail\tfix\tgraph\tquery\n" diff --git a/docs/app-ops.md b/docs/app-ops.md index 2c8119f..25718bd 100644 --- a/docs/app-ops.md +++ b/docs/app-ops.md @@ -1,5 +1,16 @@ # Application Operations +## Current status and recent events + +Status examines Gitea and Traefik logs from the last five minutes by default; +`LAB_STATUS_LOG_SINCE` overrides the interval. A few Gitea client disconnects +are informational only when its container, local HTTP, and public HTTP checks +pass. Other log errors, repeated disconnects, or failed checks remain warnings +and point to `doctor-gitea`. Information alone does not select a heal action. +The AI stack can explain warning evidence, but its output is an unverified +hypothesis and does not decide status or authorize healing. Health checks are +point-in-time observations and cannot prove all requests succeeded. + ## OCI backup scheduling Run `./jeannie backup oci schedule` as the Debian operator to install the daily diff --git a/docs/templates/app-ops.md.tmpl b/docs/templates/app-ops.md.tmpl index 62780e2..057f9d2 100644 --- a/docs/templates/app-ops.md.tmpl +++ b/docs/templates/app-ops.md.tmpl @@ -1,5 +1,16 @@ # Application Operations +## Current status and recent events + +Status examines Gitea and Traefik logs from the last five minutes by default; +`LAB_STATUS_LOG_SINCE` overrides the interval. A few Gitea client disconnects +are informational only when its container, local HTTP, and public HTTP checks +pass. Other log errors, repeated disconnects, or failed checks remain warnings +and point to `doctor-gitea`. Information alone does not select a heal action. +The AI stack can explain warning evidence, but its output is an unverified +hypothesis and does not decide status or authorize healing. Health checks are +point-in-time observations and cannot prove all requests succeeded. + ## OCI backup scheduling Run `./jeannie backup oci schedule` as the Debian operator to install the daily diff --git a/lib/jeannie/commands.sh b/lib/jeannie/commands.sh index 26a55d4..b0076dd 100644 --- a/lib/jeannie/commands.sh +++ b/lib/jeannie/commands.sh @@ -1637,16 +1637,18 @@ status_disk_pressure() { } status_traefik_error_rates() { - local since="${LAB_STATUS_LOG_SINCE:-30m}" + local since="${LAB_STATUS_LOG_SINCE:-5m}" local sample local count_502 local count_404 - sample="$(kubectl --kubeconfig "${KUBECONFIG_PATH}" -n traefik logs -l app.kubernetes.io/name=traefik --since="${since}" --tail=2000 2>/dev/null || true)" - if [[ -z "${sample}" ]]; then - echo "no recent Traefik logs available" >&2 + if ! sample="$(kubectl --kubeconfig "${KUBECONFIG_PATH}" -n traefik logs -l app.kubernetes.io/name=traefik --since="${since}" --tail=2000 2>&1)"; then + echo "Unable to read Traefik logs; service state is unknown." >&2 return 1 fi + if [[ -z "${sample}" ]]; then + return 0 + fi count_502="$(grep -Eac '(^|[^0-9])50[234]([^0-9]|$)|level=error' <<<"${sample}" || true)" count_404="$(grep -Eac '(^|[^0-9])404([^0-9]|$)' <<<"${sample}" || true)" @@ -1658,7 +1660,7 @@ status_traefik_error_rates() { } status_gitea_recent_errors() { - local since="${LAB_STATUS_LOG_SINCE:-30m}" + local since="${LAB_STATUS_LOG_SINCE:-5m}" local container="${GITEA_CONTAINER_NAME:-homelab-gitea}" local sample local matches @@ -1672,14 +1674,42 @@ status_gitea_recent_errors() { return 1 fi - sample="$(sudo docker logs --since "${since}" "${container}" 2>&1 || true)" + if ! sample="$(sudo docker logs --since "${since}" --tail 2000 "${container}" 2>&1)"; then + echo "Unable to read Gitea logs; service state is unknown." >&2 + return 1 + fi matches="$(grep -Eai 'error|panic|fatal|authentication failed|denied| 50[0-9] ' <<<"${sample}" | tail -10 || true)" if [[ -n "${matches}" ]]; then + local all_matches count + all_matches="$(grep -Eai 'error|panic|fatal|authentication failed|denied| 50[0-9] ' <<<"${sample}" || true)" + count="$(printf '%s\n' "${all_matches}" | wc -l | tr -d ' ')" + if ((count <= 3)) && ! grep -Eavi 'broken pipe|connection reset by peer' <<<"${all_matches}" >/dev/null && \ + status_container_running "${container}" >/dev/null 2>&1 && \ + status_http_ok "http://127.0.0.1:${LAB_GITEA_HTTP_PORT:-3000}/" >/dev/null 2>&1 && \ + status_gitea_public_ok >/dev/null 2>&1; then + printf 'Recent client disconnects (%s in %s); Gitea container and HTTP checks currently pass. No fix indicated; monitor for recurrence.\n%s\n' "${count}" "${since}" "${matches}" + return 3 + fi printf '%s\n' "${matches}" >&2 return 1 fi } +status_cascade_recent_gitea() { + local output status=0 + output="$(status_gitea_recent_errors 2>&1)" || status=$? + if truthy "${JEANNIE_REPORT_MODE:-false}"; then + case "${status}" in + 0) report_ui_emit ok "${STATUS_CURRENT_SECTION:-Status}" "Gitea recent errors" "ok" ;; + 3) report_ui_emit info "Recent events" "Gitea client disconnects" "$(printf '%s\n' "${output}" | report_ui_first_line)" "${output}" ;; + *) report_ui_emit warn "${STATUS_CURRENT_SECTION:-Status}" "Gitea recent errors" "$(printf '%s\n' "${output}" | report_ui_first_line)" "${output}" "./jeannie doctor-gitea" ;; + esac + elif (( status != 0 )); then + printf '%s\n' "${output}" + fi + return 0 +} + status_registry_ok() { status_http_ok "http://${LAB_REGISTRY_ENDPOINT:-192.168.100.73:30500}/v2/" } @@ -1900,7 +1930,7 @@ status_cascade_report() { status_cascade_warn "Node pressure" status_node_pressure status_cascade_warn "Disk usage" status_disk_pressure status_cascade_warn "Traefik 5xx/404 signals" status_traefik_error_rates - status_cascade_warn "Gitea recent errors" status_gitea_recent_errors + status_cascade_recent_gitea status_section "Platform And Apps" status_cascade_check "Local registry" status_registry_ok || failures=$((failures + 1)) @@ -3005,7 +3035,7 @@ doctor_homelab() { report_ui_check warn "Operations" "Backup freshness" "./jeannie backup" "" "" backup_status report_ui_check warn "Operations" "Disk usage" "df -h / /data" "" "" status_disk_pressure report_ui_check warn "Operations" "Pod restart pressure" "kubectl get pods -A" "" "" status_pod_restart_pressure - report_ui_check warn "Operations" "Traefik 5xx/404 signals" "kubectl -n traefik logs -l app.kubernetes.io/name=traefik --since=30m" "" "" status_traefik_error_rates + report_ui_check warn "Operations" "Traefik 5xx/404 signals" "kubectl -n traefik logs -l app.kubernetes.io/name=traefik --since=5m" "" "" status_traefik_error_rates report_ui_render "Post-Migration Homelab Doctor" report_ui_cleanup diff --git a/scripts/report-ui b/scripts/report-ui index 0286978..62b30cf 100644 --- a/scripts/report-ui +++ b/scripts/report-ui @@ -11,7 +11,7 @@ REPORT_UI_ROWS_FILE="" report_ui_usage_flags() { cat <<'EOF' Report UI flags: - --all Show ok, skip, warning, and failing items. + --all Show ok, informational, skip, warning, and failing items. --details Show the compact report plus detail fields. --json Print structured JSON. --no-local-rca Do not ask the local AI gateway for the focused RCA summary. @@ -221,7 +221,7 @@ Active cluster profile: ${LAB_CLUSTER_PROFILE:-unknown}; runtime: ${LAB_CLUSTER_ Task: 1. Pick the single highest-impact issue to focus first. -2. Describe only evidence-supported causes; state when the cause is unknown. Give evidence, immediate mitigation, and long-term redesign. +2. Describe only evidence-supported causes; state when the cause is unknown. Give evidence, immediate mitigation, and long-term redesign. Never claim a past log proves a service is currently broken. Never invent service topology or commands. 3. Return exactly four bullets: Focus, Root cause, Mitigation, Redesign. 4. For Kubernetes pod/node issues, prefer read-only Holmes triage before mutation. 5. Keep it concise and practical. Do not invent commands not implied by the fix field.