Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Surface per-endpoint reasons in cluster "no healthy nodes" error

rcourtman0dd3f8bedbe8
diff --git a/pkg/proxmox/cluster_client.go b/pkg/proxmox/cluster_client.go
index b9039f1644..3d5f164237 100644
--- a/pkg/proxmox/cluster_client.go
+++ b/pkg/proxmox/cluster_client.go
@@ -480,11 +480,22 @@ func (cc *ClusterClient) getHealthyClient(ctx context.Context) (*Client, error)
// Mark it as healthy optimistically
cc.nodeHealth[cc.endpoints[0]] = true
} else {
- // Provide detailed error with endpoint status
+ // Provide detailed error with endpoint status. Surfacing the
+ // per-endpoint reason (already sanitized) preserves the original
+ // failure category so callers — and the connections aggregator's
+ // auth-error regex in particular — can distinguish "authentication
+ // failed" from "network unreachable" instead of seeing every
+ // cluster-wide failure as "unreachable".
unhealthyList := make([]string, 0, len(cc.endpoints))
+ endpointReasons := make([]string, 0, len(cc.endpoints))
for _, ep := range cc.endpoints {
if !cc.nodeHealth[ep] {
unhealthyList = append(unhealthyList, ep)
+ if reason := strings.TrimSpace(cc.lastError[ep]); reason != "" {
+ endpointReasons = append(endpointReasons, fmt.Sprintf("%s: %s", ep, reason))
+ } else {
+ endpointReasons = append(endpointReasons, fmt.Sprintf("%s: no recorded reason", ep))
+ }
}
}
log.Error().
@@ -492,7 +503,7 @@ func (cc *ClusterClient) getHealthyClient(ctx context.Context) (*Client, error)
Strs("unhealthyEndpoints", unhealthyList).
Int("totalEndpoints", len(cc.endpoints)).
Msg("All cluster endpoints are unhealthy - verify network connectivity and API accessibility from Pulse server")
- return nil, fmt.Errorf("no healthy nodes available in cluster %s (all %d endpoints unreachable: %v)", cc.name, len(cc.endpoints), unhealthyList)
+ return nil, fmt.Errorf("no healthy nodes available in cluster %s (%d endpoints failed: %s)", cc.name, len(cc.endpoints), strings.Join(endpointReasons, "; "))
}
}
diff --git a/pkg/proxmox/cluster_client_more_test.go b/pkg/proxmox/cluster_client_more_test.go
index 6bbff0a4dc..93a95dc9ba 100644
--- a/pkg/proxmox/cluster_client_more_test.go
+++ b/pkg/proxmox/cluster_client_more_test.go
@@ -284,3 +284,74 @@ func TestGetHealthyClientNoHealthyEndpointsError(t *testing.T) {
t.Fatalf("unexpected error: %v", err)
}
}
+
+// TestGetHealthyClientPreservesPerEndpointReason guards that the wrapped
+// "no healthy nodes available" error includes each endpoint's recorded
+// failure reason. Previously the wrapper only emitted endpoint URLs and
+// the literal phrase "endpoints unreachable", which silently turned auth
+// failures into "unreachable" upstream — the connections aggregator's
+// auth-error regex never matched, so a token rejected with 401 on every
+// endpoint surfaced as `state: "unreachable"` instead of `unauthorized`.
+func TestGetHealthyClientPreservesPerEndpointReason(t *testing.T) {
+ now := time.Now()
+
+ t.Run("all endpoints failed auth", func(t *testing.T) {
+ cc := &ClusterClient{
+ name: "homelab",
+ endpoints: []string{"https://192.168.0.5:8006", "https://192.168.0.134:8006"},
+ clients: map[string]*Client{},
+ nodeHealth: map[string]bool{
+ "https://192.168.0.5:8006": false,
+ "https://192.168.0.134:8006": false,
+ },
+ lastError: map[string]string{
+ "https://192.168.0.5:8006": "Authentication failed - check API token or credentials",
+ "https://192.168.0.134:8006": "Authentication failed - check API token or credentials",
+ },
+ lastHealthCheck: map[string]time.Time{
+ "https://192.168.0.5:8006": now,
+ "https://192.168.0.134:8006": now,
+ },
+ rateLimitUntil: make(map[string]time.Time),
+ }
+
+ _, err := cc.getHealthyClient(context.Background())
+ if err == nil {
+ t.Fatal("expected error when no healthy endpoints")
+ }
+ msg := err.Error()
+ if !strings.Contains(msg, "Authentication failed") {
+ t.Fatalf("expected per-endpoint auth reason in error, got: %v", msg)
+ }
+ if !strings.Contains(msg, "https://192.168.0.5:8006") || !strings.Contains(msg, "https://192.168.0.134:8006") {
+ t.Fatalf("expected both endpoints listed, got: %v", msg)
+ }
+ })
+
+ t.Run("endpoint with no recorded reason", func(t *testing.T) {
+ cc := &ClusterClient{
+ name: "homelab",
+ endpoints: []string{"node1"},
+ clients: map[string]*Client{},
+ nodeHealth: map[string]bool{
+ "node1": false,
+ },
+ lastError: map[string]string{}, // intentionally empty
+ lastHealthCheck: map[string]time.Time{"node1": now},
+ rateLimitUntil: make(map[string]time.Time),
+ }
+ // Need >1 endpoint to hit the multi-endpoint code path; add a second.
+ cc.endpoints = append(cc.endpoints, "node2")
+ cc.nodeHealth["node2"] = false
+ cc.lastHealthCheck["node2"] = now
+
+ _, err := cc.getHealthyClient(context.Background())
+ if err == nil {
+ t.Fatal("expected error when no healthy endpoints")
+ }
+ msg := err.Error()
+ if !strings.Contains(msg, "no recorded reason") {
+ t.Fatalf("expected fallback reason text, got: %v", msg)
+ }
+ })
+}