Skip to content

Commit 21693c0

Browse files
author
Samir Raval
authored
DAOS-10625 control: Create the tool to collect the logs/config for support purpose (#11094)
1> Adding dmg support collectlog option collect the logs/configs from servers. 2> Adding daos_server support collectlog option to get the system and server side information in case dmg Management layer is not working for some reason. 3> Adding daos_admin support collectlog option to get the client side logs and configs. 4> Added unit test for support lib 5> Added functional tests for dmg,daos_agent and daos_server support options Signed-off-by: Samir Raval <[email protected]>
1 parent 4d105a5 commit 21693c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+3366
-129
lines changed

src/control/cmd/daos_agent/main.go

+24
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type cliOptions struct {
3838
DumpInfo dumpAttachInfoCmd `command:"dump-attachinfo" description:"Dump system attachinfo"`
3939
DumpTopo hwprov.DumpTopologyCmd `command:"dump-topology" description:"Dump system topology"`
4040
NetScan netScanCmd `command:"net-scan" description:"Perform local network fabric scan"`
41+
Support supportCmd `command:"support" description:"Perform debug tasks to help support team"`
4142
}
4243

4344
type (
@@ -114,6 +115,25 @@ func exitWithError(log logging.Logger, err error) {
114115
os.Exit(1)
115116
}
116117

118+
type (
119+
supportAgentConfig interface {
120+
setSupportConf(string)
121+
getSupportConf() string
122+
}
123+
124+
supportAgentConfigCmd struct {
125+
supportCfgPath string
126+
}
127+
)
128+
129+
func (cmd *supportAgentConfigCmd) setSupportConf(cfgPath string) {
130+
cmd.supportCfgPath = cfgPath
131+
}
132+
133+
func (cmd *supportAgentConfigCmd) getSupportConf() string {
134+
return cmd.supportCfgPath
135+
}
136+
117137
func parseOpts(args []string, opts *cliOptions, invoker control.Invoker, log *logging.LeveledLogger) error {
118138
p := flags.NewParser(opts, flags.Default)
119139
p.Options ^= flags.PrintErrors // Don't allow the library to print errors
@@ -176,6 +196,10 @@ func parseOpts(args []string, opts *cliOptions, invoker control.Invoker, log *lo
176196
log.Debugf("agent config loaded from %s", cfgPath)
177197
}
178198

199+
if suppCmd, ok := cmd.(supportAgentConfig); ok {
200+
suppCmd.setSupportConf(cfgPath)
201+
}
202+
179203
if opts.RuntimeDir != "" {
180204
log.Debugf("Overriding socket path from config file with %s", opts.RuntimeDir)
181205
cfg.RuntimeDir = opts.RuntimeDir

src/control/cmd/daos_agent/support.go

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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+
}

src/control/cmd/daos_server/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type mainOpts struct {
4747
Version versionCmd `command:"version" description:"Print daos_server version"`
4848
MgmtSvc msCmdRoot `command:"ms" description:"Perform tasks related to management service replicas"`
4949
DumpTopo hwprov.DumpTopologyCmd `command:"dump-topology" description:"Dump system topology"`
50+
Support supportCmd `command:"support" description:"Perform debug tasks to help support team"`
5051
Config configCmd `command:"config" alias:"cfg" description:"Perform tasks related to configuration of hardware on the local server"`
5152

5253
// Allow a set of tests to be run before executing commands.
+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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 server"`
21+
}
22+
23+
// collectLogCmd is the struct representing the command to collect the Logs/config for support purpose
24+
type collectLogCmd struct {
25+
cfgCmd
26+
cmdutil.LogCmd
27+
support.CollectLogSubCmd
28+
}
29+
30+
func (cmd *collectLogCmd) Execute(_ []string) error {
31+
var LogCollection = map[int32][]string{
32+
support.CopyServerConfigEnum: {""},
33+
support.CollectSystemCmdEnum: support.SystemCmd,
34+
support.CollectServerLogEnum: support.ServerLog,
35+
support.CollectDaosServerCmdEnum: support.DaosServerCmd,
36+
}
37+
38+
// Default 4 steps of log/conf collection.
39+
progress := support.ProgressBar{
40+
Total: len(LogCollection),
41+
NoDisplay: false,
42+
}
43+
44+
if cmd.Archive {
45+
progress.Total++
46+
}
47+
48+
// Copy custom log folder
49+
if cmd.ExtraLogsDir != "" {
50+
LogCollection[support.CollectExtraLogsDirEnum] = []string{""}
51+
progress.Total++
52+
}
53+
54+
if cmd.TargetFolder == "" {
55+
cmd.TargetFolder = filepath.Join(os.TempDir(), "daos_support_server_logs")
56+
}
57+
cmd.Infof("Support logs will be copied to %s", cmd.TargetFolder)
58+
59+
progress.Steps = 100 / progress.Total
60+
params := support.CollectLogsParams{}
61+
params.Config = cmd.configPath()
62+
params.TargetFolder = cmd.TargetFolder
63+
params.ExtraLogsDir = cmd.ExtraLogsDir
64+
for logFunc, logCmdSet := range LogCollection {
65+
for _, logCmd := range logCmdSet {
66+
cmd.Debugf("Log Function Enum = %d -- Log Collect Cmd = %s ", logFunc, logCmd)
67+
params.LogFunction = logFunc
68+
params.LogCmd = logCmd
69+
70+
err := support.CollectSupportLog(cmd.Logger, params)
71+
if err != nil {
72+
fmt.Println(err)
73+
if cmd.Stop {
74+
return err
75+
}
76+
}
77+
}
78+
fmt.Printf(progress.Display())
79+
}
80+
81+
if cmd.Archive {
82+
cmd.Debugf("Archiving the Log Folder %s", cmd.TargetFolder)
83+
err := support.ArchiveLogs(cmd.Logger, params)
84+
if err != nil {
85+
return err
86+
}
87+
88+
// FIXME: DAOS-13290 Workaround for files held open
89+
for i := 1; i < 3; i++ {
90+
os.RemoveAll(cmd.TargetFolder)
91+
}
92+
}
93+
94+
fmt.Printf(progress.Display())
95+
96+
return nil
97+
}

src/control/cmd/dmg/command_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// (C) Copyright 2019-2022 Intel Corporation.
2+
// (C) Copyright 2019-2023 Intel Corporation.
33
//
44
// SPDX-License-Identifier: BSD-2-Clause-Patent
55
//

src/control/cmd/dmg/json_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func TestDmg_JsonOutput(t *testing.T) {
6767
testArgs := append([]string{"-i", "--json"}, args...)
6868
switch strings.Join(args, " ") {
6969
case "version", "telemetry config", "telemetry run", "config generate",
70-
"manpage", "system set-prop":
70+
"manpage", "system set-prop", "support collect-log":
7171
return
7272
case "storage nvme-rebind":
7373
testArgs = append(testArgs, "-l", "foo.com", "-a",

src/control/cmd/dmg/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ type cliOptions struct {
196196
Config configCmd `command:"config" alias:"cfg" description:"Perform tasks related to configuration of hardware on remote servers"`
197197
System SystemCmd `command:"system" alias:"sys" description:"Perform distributed tasks related to DAOS system"`
198198
Network NetCmd `command:"network" alias:"net" description:"Perform tasks related to network devices attached to remote servers"`
199+
Support supportCmd `command:"support" alias:"supp" description:"Perform debug tasks to help support team"`
199200
Pool PoolCmd `command:"pool" description:"Perform tasks related to DAOS pools"`
200201
Cont ContCmd `command:"container" alias:"cont" description:"Perform tasks related to DAOS containers"`
201202
Version versionCmd `command:"version" description:"Print dmg version"`

0 commit comments

Comments
 (0)