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

DAOS-13763 control: Fix daos_metrics collection for support collect-log. #12555

Merged
merged 2 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
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
54 changes: 9 additions & 45 deletions src/control/cmd/dmg/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@
package main

import (
"bytes"
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"

"github.com/pkg/errors"

"github.com/daos-stack/daos/src/control/cmd/dmg/pretty"
"github.com/daos-stack/daos/src/control/common/cmdutil"
"github.com/daos-stack/daos/src/control/lib/control"
Expand All @@ -38,56 +34,19 @@ type collectLogCmd struct {
support.CollectLogSubCmd
}

// Copy Admin logs to TargetHost (central location) if option is provided.
func (cmd *collectLogCmd) rsyncAdminLog() error {

runcmd := strings.Join([]string{
"rsync",
"-av",
"--blocking-io",
cmd.TargetFolder + "/",
cmd.TargetHost + ":" + cmd.TargetFolder}, " ")

cmd.Debugf("Rsync Admin Log command = %s", runcmd)
rsyncCmd := exec.Command("sh", "-c", runcmd)
var stdout, stderr bytes.Buffer
rsyncCmd.Stdout = &stdout
rsyncCmd.Stderr = &stderr
err := rsyncCmd.Run()
outStr, errStr := string(stdout.Bytes()), string(stderr.Bytes())
if err != nil {
return errors.Wrapf(err, "Error running command %s with %s", rsyncCmd, err)
}
cmd.Debugf("rsyncCmd:= %s stdout:\n%s\nstderr:\n%s\n", rsyncCmd, outStr, errStr)

return nil
}

// gRPC call to initiate the rsync and copy the logs to Admin/TargetHost (central location).
// gRPC call to initiate the rsync and copy the logs to Admin (central location).
func (cmd *collectLogCmd) rsyncLog() error {
hostName, err := support.GetHostName()
if err != nil {
return err
}

// Admin host will be the central host to collect all the logs from servers.
// Logs will be rsync to TargetHost is provided.
if cmd.TargetHost == "" {
cmd.TargetHost = hostName
} else {
// initiate the rsync and copy the Admin logs to targetHost
err = cmd.rsyncAdminLog()
if err != nil && cmd.Stop {
return err
}
}

req := &control.CollectLogReq{
TargetFolder: cmd.TargetFolder,
TargetHost: cmd.TargetHost,
AdminNode: hostName,
LogFunction: support.RsyncLogEnum,
}
cmd.Debugf("Rsync logs from servers to %s:%s ", cmd.TargetHost, cmd.TargetFolder)
cmd.Debugf("Rsync logs from servers to %s:%s ", hostName, cmd.TargetFolder)
resp, err := control.CollectLog(context.Background(), cmd.ctlInvoker, req)
if err != nil && cmd.Stop {
return err
Expand All @@ -106,9 +65,14 @@ func (cmd *collectLogCmd) rsyncLog() error {

// gRPC call to Archive the logs on individual servers.
func (cmd *collectLogCmd) archLogsOnServer() error {
hostName, err := support.GetHostName()
if err != nil {
return err
}

req := &control.CollectLogReq{
TargetFolder: cmd.TargetFolder,
TargetHost: cmd.TargetHost,
AdminNode: hostName,
LogFunction: support.ArchiveLogsEnum,
}
cmd.Debugf("Archiving the Log Folder %s", cmd.TargetFolder)
Expand Down
38 changes: 19 additions & 19 deletions src/control/common/proto/ctl/support.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/control/lib/control/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type (
CollectLogReq struct {
unaryRequest
TargetFolder string
TargetHost string
AdminNode string
ExtraLogsDir string
JsonOutput bool
LogFunction int32
Expand All @@ -41,7 +41,7 @@ func CollectLog(ctx context.Context, rpcClient UnaryInvoker, req *CollectLogReq)
req.setRPC(func(ctx context.Context, conn *grpc.ClientConn) (proto.Message, error) {
return ctlpb.NewCtlSvcClient(conn).CollectLog(ctx, &ctlpb.CollectLogReq{
TargetFolder: req.TargetFolder,
TargetHost: req.TargetHost,
AdminNode: req.AdminNode,
ExtraLogsDir: req.ExtraLogsDir,
JsonOutput: req.JsonOutput,
LogFunction: req.LogFunction,
Expand Down
9 changes: 4 additions & 5 deletions src/control/lib/support/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ type CollectLogSubCmd struct {
TargetFolder string `short:"t" long:"target-folder" description:"Target Folder location where log will be copied"`
Archive bool `short:"z" long:"archive" description:"Archive the log/config files"`
ExtraLogsDir string `short:"c" long:"extra-logs-dir" description:"Collect the Logs from given directory"`
TargetHost string `short:"m" long:"target-host" description:"Rsync all the logs to central system"`
}

// Folder names to copy logs and configs
Expand Down Expand Up @@ -120,7 +119,7 @@ type CollectLogsParams struct {
Config string
Hostlist string
TargetFolder string
TargetHost string
AdminNode string
ExtraLogsDir string
JsonOutput bool
LogFunction int32
Expand Down Expand Up @@ -341,7 +340,7 @@ func getSysNameFromQuery(configPath string, log logging.Logger) ([]string, error
return hostNames, nil
}

// R sync logs from individual servers to Admin/TargetHost node
// R sync logs from individual servers to Admin node
func rsyncLog(log logging.Logger, opts ...CollectLogsParams) error {
targetLocation, err := createHostFolder(opts[0].TargetFolder, log)
if err != nil {
Expand All @@ -353,7 +352,7 @@ func rsyncLog(log logging.Logger, opts ...CollectLogsParams) error {
"-av",
"--blocking-io",
targetLocation,
opts[0].TargetHost + ":" + opts[0].TargetFolder},
opts[0].AdminNode + ":" + opts[0].TargetFolder},
" ")

out, err := exec.Command("sh", "-c", cmd).Output()
Expand Down Expand Up @@ -650,7 +649,7 @@ func collectDaosMetrics(daosNodeLocation string, log logging.Logger, opts ...Col

_, err := cpOutputToFile(daosNodeLocation, log, daos)
if err != nil {
return err
log.Errorf("Failed to run %s: %v", daos.cmd, err)
}
}
} else {
Expand Down
13 changes: 4 additions & 9 deletions src/control/lib/support/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,28 +344,23 @@ func TestSupport_rsyncLog(t *testing.T) {

for name, tc := range map[string]struct {
targetFolder string
TargetHost string
AdminNode string
expErr error
}{
"rsync to invalid Target directory": {
targetFolder: targetTestDir + "/foo/bar",
TargetHost: hostName + ":/tmp/foo/bar/",
expErr: errors.New("Error running command"),
},
"rsync to invalid Target Host": {
targetFolder: targetTestDir + "/foo/bar",
TargetHost: "invalid-host",
AdminNode: hostName + ":/tmp/foo/bar/",
expErr: errors.New("Error running command"),
},
"rsync invalid log directory": {
targetFolder: srcPath + "/file1",
TargetHost: hostName,
AdminNode: hostName,
expErr: errors.New("not a directory"),
},
} {
t.Run(name, func(t *testing.T) {
rsLog.TargetFolder = tc.targetFolder
rsLog.TargetHost = tc.TargetHost
rsLog.AdminNode = tc.AdminNode
gotErr := rsyncLog(log, rsLog)
test.CmpErr(t, tc.expErr, gotErr)
})
Expand Down
2 changes: 1 addition & 1 deletion src/control/server/ctl_support_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (c *ControlService) CollectLog(ctx context.Context, req *ctlpb.CollectLogRe
params := support.CollectLogsParams{}
params.TargetFolder = req.TargetFolder
params.ExtraLogsDir = req.ExtraLogsDir
params.TargetHost = req.TargetHost
params.AdminNode = req.AdminNode
params.JsonOutput = req.JsonOutput
params.LogFunction = req.LogFunction
params.LogCmd = req.LogCmd
Expand Down
2 changes: 1 addition & 1 deletion src/proto/ctl/support.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ option go_package = "github.com/daos-stack/daos/src/control/common/proto/ctl";
message CollectLogReq {
string TargetFolder = 1;
string ExtraLogsDir = 2;
string TargetHost = 3;
string AdminNode = 3;
bool JsonOutput = 4;
int32 LogFunction = 5;
string LogCmd = 6;
Expand Down