mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-09-25 04:33:03 +00:00
Canonicalize Patrol health finding keys
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -1346,9 +1346,17 @@ func (p *PatrolService) dispatchPatrolInvestigations(result *AIAnalysisResult) {
|
||||
// and pbs-job-failed is NOT backup-failed; mapping those would point the
|
||||
// verifier at the wrong resource model.
|
||||
var findingKeyAliases = map[string]string{
|
||||
"high-cpu": "cpu-high",
|
||||
"high-memory": "memory-high",
|
||||
"high-disk": "disk-high",
|
||||
"container-health-check-failed": "health-check-failed",
|
||||
"container-health-failed": "health-check-failed",
|
||||
"container-health-failing": "health-check-failed",
|
||||
"container-unhealthy": "health-check-failed",
|
||||
"failing-health-check": "health-check-failed",
|
||||
"health-check-failing": "health-check-failed",
|
||||
"healthcheck-failed": "health-check-failed",
|
||||
"high-cpu": "cpu-high",
|
||||
"high-memory": "memory-high",
|
||||
"high-disk": "disk-high",
|
||||
"unhealthy-container": "health-check-failed",
|
||||
}
|
||||
|
||||
func normalizeFindingKey(key string) string {
|
||||
|
||||
@@ -1718,6 +1718,36 @@ func TestPatrolFindingAdapterDistinguishesSameRunCreationFromExistingRereport(t
|
||||
}
|
||||
}
|
||||
|
||||
func TestPatrolFindingAdapterCanonicalizesContainerHealthKeyVariantsAcrossRuns(t *testing.T) {
|
||||
ps := NewPatrolService(nil, nil)
|
||||
firstInput := tools.PatrolFindingInput{
|
||||
ResourceID: "app-container-1", ResourceName: "api", ResourceType: "app-container",
|
||||
Key: "health-check-failed", Severity: "warning", Category: "reliability",
|
||||
Title: "Container health check is failing", Description: "The container is unhealthy.",
|
||||
Impact: "Requests may fail.", Recommendation: "Inspect the health check.",
|
||||
Evidence: "Current provider health is unhealthy.",
|
||||
}
|
||||
|
||||
firstRun := newPatrolFindingCreatorAdapterState(ps, patrolRuntimeState{})
|
||||
findingID, isNew, err := firstRun.CreateFinding(firstInput)
|
||||
if err != nil || !isNew {
|
||||
t.Fatalf("first report = (%q, %t, %v), want a new finding", findingID, isNew, err)
|
||||
}
|
||||
|
||||
secondInput := firstInput
|
||||
secondInput.Key = "container-health-failing"
|
||||
secondInput.Title = "Container health is failing while running"
|
||||
secondRun := newPatrolFindingCreatorAdapterState(ps, patrolRuntimeState{})
|
||||
secondRun.GetActiveFindings("", "")
|
||||
reportedID, secondIsNew, err := secondRun.CreateFinding(secondInput)
|
||||
if err != nil || secondIsNew || reportedID != findingID {
|
||||
t.Fatalf("variant report = (%q, %t, %v), want existing %q", reportedID, secondIsNew, err, findingID)
|
||||
}
|
||||
if active := ps.findings.GetActive(FindingSeverityInfo); len(active) != 1 || active[0].ID != findingID || active[0].Key != "health-check-failed" {
|
||||
t.Fatalf("active findings = %+v, want one canonical health-check finding", active)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPatrolFindingAdapterTreatsStoppedContainerStateAsAlertOwned(t *testing.T) {
|
||||
ps := NewPatrolService(nil, nil)
|
||||
state := newPatrolRuntimeState(models.StateSnapshot{
|
||||
|
||||
@@ -448,11 +448,17 @@ func TestReconcileStaleFindings_VerificationCapDefersExcessCandidates(t *testing
|
||||
|
||||
func TestNormalizeFindingKey_CanonicalAliases(t *testing.T) {
|
||||
cases := map[string]string{
|
||||
"high-cpu": "cpu-high",
|
||||
"High_Memory": "memory-high",
|
||||
"high disk": "disk-high",
|
||||
"cpu-high": "cpu-high",
|
||||
"backup-stale": "backup-stale",
|
||||
"high-cpu": "cpu-high",
|
||||
"High_Memory": "memory-high",
|
||||
"high disk": "disk-high",
|
||||
"cpu-high": "cpu-high",
|
||||
"backup-stale": "backup-stale",
|
||||
"container-health-failing": "health-check-failed",
|
||||
"container-health-check-failed": "health-check-failed",
|
||||
"healthcheck-failed": "health-check-failed",
|
||||
"failing-health-check": "health-check-failed",
|
||||
"container-unhealthy": "health-check-failed",
|
||||
"unhealthy-container": "health-check-failed",
|
||||
// Non-aliased keys pass through normalization unchanged.
|
||||
"pbs-job-failed": "pbs-job-failed",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user