Skip to content

Commit

Permalink
read for both velero pod kinds
Browse files Browse the repository at this point in the history
Signed-off-by: Archit Sharma <[email protected]>
  • Loading branch information
arcolife committed Nov 3, 2023
1 parent 7ab1ee7 commit edfc4ab
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
21 changes: 12 additions & 9 deletions pkg/analyze/velero.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,16 @@ func (a *AnalyzeVelero) veleroStatus(analyzer *troubleshootv1beta2.VeleroAnalyze

logsDir := GetVeleroLogsDirectory()
logsGlob := filepath.Join(logsDir, "node-agent*", "*.log")
logs, err := findFiles(logsGlob, excludeFiles)

nodeAgentlogs, err := findFiles(logsGlob, excludeFiles)
if err != nil {
return nil, errors.Wrapf(err, "failed to find velero logs files under %s", logsDir)
}

results = append(results, analyzeLogs(logs)...)
veleroLogsGlob := filepath.Join(logsDir, "velero*", "*.log")
veleroLogs, err := findFiles(veleroLogsGlob, excludeFiles)

results = append(results, analyzeLogs(nodeAgentlogs, "node-agent*")...)
results = append(results, analyzeLogs(veleroLogs, "velero*")...)
results = append(results, analyzeBackups(backups)...)
results = append(results, analyzeBackupStorageLocations(backupStorageLocations)...)
results = append(results, analyzeDeleteBackupRequests(deleteBackupRequests)...)
Expand Down Expand Up @@ -595,30 +598,30 @@ func analyzeVolumeSnapshotLocations(volumeSnapshotLocations []*velerov1.VolumeSn
return results
}

func analyzeLogs(logs map[string][]byte) []*AnalyzeResult {
func analyzeLogs(logs map[string][]byte, kind string) []*AnalyzeResult {
results := []*AnalyzeResult{}
if len(logs) > 0 {
for _, logBytes := range logs {
for key, logBytes := range logs {
logContent := string(logBytes)
result := &AnalyzeResult{
Title: fmt.Sprintf("Velero logs for pod [node-agent]"),
Title: fmt.Sprintf("Velero logs for pod [%s]", key),
}
if strings.Contains(logContent, "permission denied") {
result.IsWarn = true
result.Message = fmt.Sprintf("Found 'permission denied' in node-agent* pod log file(s)")
result.Message = fmt.Sprintf("Found 'permission denied' in %s pod log file(s)", kind)
results = append(results, result)
continue
}

if strings.Contains(logContent, "error") || strings.Contains(logContent, "panic") || strings.Contains(logContent, "fatal") {
result.IsWarn = true
result.Message = fmt.Sprintf("Found error|panic|fatal in node-agent* pod log file(s)")
result.Message = fmt.Sprintf("Found error|panic|fatal in %s pod log file(s)", kind)
results = append(results, result)
}
}

results = append(results, &AnalyzeResult{
Title: "Velero Logs analysis",
Title: fmt.Sprintf("Velero Logs analysis for kind [%s]", kind),
IsPass: true,
Message: fmt.Sprintf("Found %d log files", len(logs)),
})
Expand Down
35 changes: 29 additions & 6 deletions pkg/analyze/velero_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,7 @@ func TestAnalyzeVelero_VolumeSnapshotLocations(t *testing.T) {
func TestAnalyzeVelero_Logs(t *testing.T) {
type args struct {
logs map[string][]byte
kind string
}
tests := []struct {
name string
Expand All @@ -871,39 +872,58 @@ func TestAnalyzeVelero_Logs(t *testing.T) {
name: "no logs",
args: args{
logs: map[string][]byte{},
kind: "node-agent*",
},
want: []*AnalyzeResult{},
},
{
name: "logs - no errors",
name: "logs - no errors in node-agent* pods",
args: args{
logs: map[string][]byte{
"node-agent-m6n9j": []byte("level=info msg=... backup=velero/sample-app controller=podvolumebacku"),
},
kind: "node-agent*",
},
want: []*AnalyzeResult{
{
Title: "Velero Logs analysis",
Title: "Velero Logs analysis for kind [node-agent*]",
Message: "Found 1 log files",
IsPass: true,
},
},
},
{
name: "logs - errors",
name: "logs - no errors in velero* pods",
args: args{
logs: map[string][]byte{
"velero-788ff7c9dd-mslfl": []byte("level=info msg=BackupStorageLocations... controller=backup-storage-location"),
},
kind: "velero*",
},
want: []*AnalyzeResult{
{
Title: "Velero Logs analysis for kind [velero*]",
Message: "Found 1 log files",
IsPass: true,
},
},
},
{
name: "logs - errors in node-agent* pods",
args: args{
logs: map[string][]byte{
"node-agent-m6n9j": []byte("level=error msg=... backup=velero/sample-app controller=podvolumebacku"),
},
kind: "node-agent*",
},
want: []*AnalyzeResult{
{
Title: "Velero logs for pod [node-agent]",
Title: "Velero logs for pod [node-agent-m6n9j]",
Message: "Found error|panic|fatal in node-agent* pod log file(s)",
IsWarn: true,
},
{
Title: "Velero Logs analysis",
Title: "Velero Logs analysis for kind [node-agent*]",
Message: "Found 1 log files",
IsPass: true,
},
Expand All @@ -912,8 +932,11 @@ func TestAnalyzeVelero_Logs(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := analyzeLogs(tt.args.logs); !reflect.DeepEqual(got, tt.want) {
if got := analyzeLogs(tt.args.logs, tt.args.kind); !reflect.DeepEqual(got, tt.want) {
t.Errorf("analyzeLogs() = %v, want %v", got, tt.want)
gotJSON, _ := json.MarshalIndent(got, "", " ")
wantJSON, _ := json.MarshalIndent(tt.want, "", " ")
t.Logf("\nGot: %s\nWant: %s", gotJSON, wantJSON)
}
})
}
Expand Down

0 comments on commit edfc4ab

Please sign in to comment.