Skip to content

Commit

Permalink
ISSUE-2052: Fixing diagnostic logs for fresh setup (#1799)
Browse files Browse the repository at this point in the history
  • Loading branch information
varunsharma0286 authored Dec 1, 2023
1 parent 26de65e commit f8a620f
Showing 1 changed file with 8 additions and 4 deletions.
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

0 comments on commit f8a620f

Please sign in to comment.