|
| 1 | +// |
| 2 | +// (C) Copyright 2022-2023 Intel Corporation. |
| 3 | +// |
| 4 | +// SPDX-License-Identifier: BSD-2-Clause-Patent |
| 5 | +// |
| 6 | + |
| 7 | +package main |
| 8 | + |
| 9 | +import ( |
| 10 | + "fmt" |
| 11 | + "os" |
| 12 | + "path/filepath" |
| 13 | + |
| 14 | + "github.com/daos-stack/daos/src/control/common/cmdutil" |
| 15 | + "github.com/daos-stack/daos/src/control/lib/support" |
| 16 | +) |
| 17 | + |
| 18 | +// supportCmd is the struct representing the top-level support subcommand. |
| 19 | +type supportCmd struct { |
| 20 | + CollectLog collectLogCmd `command:"collect-log" description:"Collect logs from client"` |
| 21 | + agentConfigPath string |
| 22 | +} |
| 23 | + |
| 24 | +// collectLogCmd is the struct representing the command to collect the log from client side. |
| 25 | +type collectLogCmd struct { |
| 26 | + supportAgentConfigCmd |
| 27 | + cmdutil.LogCmd |
| 28 | + support.CollectLogSubCmd |
| 29 | +} |
| 30 | + |
| 31 | +func (cmd *collectLogCmd) Execute(_ []string) error { |
| 32 | + var LogCollection = map[int32][]string{ |
| 33 | + support.CopyAgentConfigEnum: {""}, |
| 34 | + support.CollectAgentLogEnum: {""}, |
| 35 | + support.CollectAgentCmdEnum: support.AgentCmd, |
| 36 | + support.CollectClientLogEnum: {""}, |
| 37 | + support.CollectSystemCmdEnum: support.SystemCmd, |
| 38 | + } |
| 39 | + |
| 40 | + // Default 3 steps of log/conf collection. |
| 41 | + progress := support.ProgressBar{ |
| 42 | + Total: len(LogCollection), |
| 43 | + NoDisplay: false, |
| 44 | + } |
| 45 | + |
| 46 | + if cmd.Archive { |
| 47 | + progress.Total++ |
| 48 | + } |
| 49 | + |
| 50 | + // Copy the custom log folder |
| 51 | + if cmd.ExtraLogsDir != "" { |
| 52 | + LogCollection[support.CollectExtraLogsDirEnum] = []string{""} |
| 53 | + progress.Total++ |
| 54 | + } |
| 55 | + |
| 56 | + if cmd.TargetFolder == "" { |
| 57 | + cmd.TargetFolder = filepath.Join(os.TempDir(), "daos_support_client_logs") |
| 58 | + } |
| 59 | + cmd.Infof("Support Logs will be copied to %s", cmd.TargetFolder) |
| 60 | + |
| 61 | + progress.Steps = 100 / progress.Total |
| 62 | + params := support.CollectLogsParams{} |
| 63 | + params.TargetFolder = cmd.TargetFolder |
| 64 | + params.ExtraLogsDir = cmd.ExtraLogsDir |
| 65 | + params.Config = cmd.getSupportConf() |
| 66 | + for logFunc, logCmdSet := range LogCollection { |
| 67 | + for _, logCmd := range logCmdSet { |
| 68 | + cmd.Debugf("Log Function Enum = %d -- Log Collect Cmd = %s ", logFunc, logCmd) |
| 69 | + params.LogFunction = logFunc |
| 70 | + params.LogCmd = logCmd |
| 71 | + |
| 72 | + err := support.CollectSupportLog(cmd.Logger, params) |
| 73 | + if err != nil { |
| 74 | + fmt.Println(err) |
| 75 | + if cmd.Stop { |
| 76 | + return err |
| 77 | + } |
| 78 | + } |
| 79 | + } |
| 80 | + fmt.Printf(progress.Display()) |
| 81 | + } |
| 82 | + |
| 83 | + if cmd.Archive { |
| 84 | + cmd.Debugf("Archiving the Log Folder %s", cmd.TargetFolder) |
| 85 | + err := support.ArchiveLogs(cmd.Logger, params) |
| 86 | + if err != nil { |
| 87 | + return err |
| 88 | + } |
| 89 | + |
| 90 | + // FIXME: DAOS-13290 Workaround for files held open |
| 91 | + for i := 1; i < 3; i++ { |
| 92 | + os.RemoveAll(cmd.TargetFolder) |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + fmt.Printf(progress.Display()) |
| 97 | + |
| 98 | + return nil |
| 99 | +} |
0 commit comments