Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISSUE-2052: Fixing diagnostic logs for fresh setup #1799

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions deepfence_server/diagnosis/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,12 @@ func getDiagnosticLogsHelper(ctx context.Context, mc directory.FileManager, path
// Get completed files from minio
objects := mc.ListFiles(ctx, pathPrefix, false, 0, true)
log.Debug().Msgf("diagnosis logs at %s: %v", pathPrefix, objects)
diagnosticLogsResponse := make([]DiagnosticLogsLink, len(objects))
for i, obj := range objects {
diagnosticLogsResponse := make([]DiagnosticLogsLink, 0, len(objects))
for _, obj := range objects {
if len(obj.Key) == 0 {
continue
}

message := ""
urlLink, err := mc.ExposeFile(ctx, obj.Key, false, DiagnosisLinkExpiry, url.Values{})
if err != nil {
Expand All @@ -105,13 +109,13 @@ func getDiagnosticLogsHelper(ctx context.Context, mc directory.FileManager, path
}
}
fileName := filepath.Base(obj.Key)
diagnosticLogsResponse[i] = DiagnosticLogsLink{
diagnosticLogsResponse = append(diagnosticLogsResponse, DiagnosticLogsLink{
URLLink: urlLink,
FileName: fileName,
Label: strings.TrimSuffix(strings.TrimPrefix(fileName, "deepfence-agent-logs-"), ".zip"),
Message: message,
CreatedAt: obj.LastModified.Format("2006-01-02 15:04:05"),
}
})
}
sort.Slice(diagnosticLogsResponse, func(i, j int) bool {
return diagnosticLogsResponse[i].CreatedAt > diagnosticLogsResponse[j].CreatedAt
Expand Down
Loading