Skip to content

Commit 0d56371

Browse files
author
Andrew Reed
authored
Merge pull request #385 from replicatedhq/longhorn-accumulate-analyzers
Accumulate all longhorn pass results
2 parents c119a16 + c95dc48 commit 0d56371

File tree

2 files changed

+98
-1
lines changed

2 files changed

+98
-1
lines changed

pkg/analyze/longhorn.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func longhorn(analyzer *troubleshootv1beta2.LonghornAnalyze, getCollectedFileCon
131131
}
132132
}
133133

134-
return results, nil
134+
return simplifyLonghornResults(results), nil
135135
}
136136

137137
func analyzeLonghornNodeSchedulable(node *longhornv1beta1.Node) *AnalyzeResult {
@@ -243,3 +243,25 @@ func analyzeLonghornReplicaChecksums(volumeName string, checksums []map[string]s
243243

244244
return result
245245
}
246+
247+
// Keep warn/error results. Return a single pass result if there are no warn/errors.
248+
func simplifyLonghornResults(results []*AnalyzeResult) []*AnalyzeResult {
249+
out := []*AnalyzeResult{}
250+
251+
for _, result := range results {
252+
if result.IsPass {
253+
continue
254+
}
255+
out = append(out, result)
256+
}
257+
258+
if len(out) == 0 {
259+
out = append(out, &AnalyzeResult{
260+
Title: "Longhorn Health Status",
261+
IsPass: true,
262+
Message: "Longhorn is healthy",
263+
})
264+
}
265+
266+
return out
267+
}

pkg/analyze/longhorn_test.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,3 +382,78 @@ func TestAnalyzeLonghornReplicaChecksums(t *testing.T) {
382382
})
383383
}
384384
}
385+
386+
func TestSimplifyLonghornResults(t *testing.T) {
387+
tests := []struct {
388+
name string
389+
input []*AnalyzeResult
390+
expect []*AnalyzeResult
391+
}{
392+
{
393+
name: "All pass",
394+
input: []*AnalyzeResult{
395+
{
396+
Title: "Replica 1",
397+
IsPass: true,
398+
Message: "Replica 1 ok",
399+
},
400+
{
401+
Title: "Node 1",
402+
IsPass: true,
403+
Message: "Node 1 ok",
404+
},
405+
},
406+
expect: []*AnalyzeResult{
407+
{
408+
Title: "Longhorn Health Status",
409+
IsPass: true,
410+
Message: "Longhorn is healthy",
411+
},
412+
},
413+
},
414+
{
415+
name: "Mixed results",
416+
input: []*AnalyzeResult{
417+
{
418+
Title: "Replica 1",
419+
IsPass: true,
420+
Message: "Replica 1 ok",
421+
},
422+
{
423+
Title: "Replica 2",
424+
IsWarn: true,
425+
Message: "Replica 1 is down",
426+
},
427+
{
428+
Title: "Node 1",
429+
IsPass: true,
430+
Message: "Node 1 ok",
431+
},
432+
{
433+
Title: "Node 2",
434+
IsFail: true,
435+
Message: "Node 2 is down",
436+
},
437+
},
438+
expect: []*AnalyzeResult{
439+
{
440+
Title: "Replica 2",
441+
IsWarn: true,
442+
Message: "Replica 1 is down",
443+
},
444+
{
445+
Title: "Node 2",
446+
IsFail: true,
447+
Message: "Node 2 is down",
448+
},
449+
},
450+
},
451+
}
452+
for _, test := range tests {
453+
t.Run(test.name, func(t *testing.T) {
454+
got := simplifyLonghornResults(test.input)
455+
456+
assert.Equal(t, test.expect, got)
457+
})
458+
}
459+
}

0 commit comments

Comments
 (0)