Skip to content

Commit

Permalink
DAOS-14850 control: Allow logging.Logger in Context (#13569)
Browse files Browse the repository at this point in the history
Updates control plane tools to set a context in a logger
for ease of debug/trace logging.

Signed-off-by: Michael MacDonald <mjmac@google.com>
  • Loading branch information
mjmac committed Apr 20, 2024
1 parent 98c953a commit 542aa10
Show file tree
Hide file tree
Showing 18 changed files with 190 additions and 64 deletions.
4 changes: 2 additions & 2 deletions src/control/cmd/daos_agent/attachinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package main

import (
"context"
"fmt"
"os"

Expand All @@ -21,6 +20,7 @@ import (
type dumpAttachInfoCmd struct {
configCmd
ctlInvokerCmd
cmdutil.LogCmd
cmdutil.JSONOutputCmd
Output string `short:"o" long:"output" default:"stdout" description:"Dump output to this location"`
}
Expand All @@ -36,7 +36,7 @@ func (cmd *dumpAttachInfoCmd) Execute(_ []string) error {
out = f
}

ctx := context.Background()
ctx := cmd.MustLogCtx()
req := &control.GetAttachInfoReq{
AllRanks: true,
}
Expand Down
3 changes: 1 addition & 2 deletions src/control/cmd/daos_agent/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package main

import (
"context"
"strings"

"github.com/daos-stack/daos/src/control/cmd/dmg/pretty"
Expand All @@ -32,7 +31,7 @@ func (cmd *netScanCmd) Execute(_ []string) error {

fabricScanner := hwprov.DefaultFabricScanner(cmd.Logger)

results, err := fabricScanner.Scan(context.Background(), prov)
results, err := fabricScanner.Scan(cmd.MustLogCtx(), prov)
if err != nil {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion src/control/cmd/daos_agent/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (cmd *startCmd) Execute(_ []string) error {
cmd.Infof("Starting %s (pid %d)", versionString(), os.Getpid())
startedAt := time.Now()

parent, shutdown := context.WithCancel(context.Background())
parent, shutdown := context.WithCancel(cmd.MustLogCtx())
defer shutdown()

var shuttingDown atm.Bool
Expand Down
2 changes: 1 addition & 1 deletion src/control/cmd/daos_server/auto.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,5 @@ func (cmd *configGenCmd) Execute(_ []string) error {
return err
}

return cmd.confGenPrint(context.Background(), getLocalFabric, getLocalStorage)
return cmd.confGenPrint(cmd.MustLogCtx(), getLocalFabric, getLocalStorage)
}
2 changes: 1 addition & 1 deletion src/control/cmd/daos_server/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (cmd *networkScanCmd) Execute(_ []string) error {
return err
}

ctx := context.Background()
ctx := cmd.MustLogCtx()
fs := hwprov.DefaultFabricScanner(cmd.Logger)

var prov string
Expand Down
2 changes: 1 addition & 1 deletion src/control/cmd/dmg/auto.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,5 @@ func (cmd *configGenCmd) confGenPrint(ctx context.Context) error {
// parameters suitable to be used across all hosts in provided host list. Use the control API to
// generate config from remote scan results.
func (cmd *configGenCmd) Execute(_ []string) error {
return cmd.confGenPrint(context.Background())
return cmd.confGenPrint(cmd.MustLogCtx())
}
4 changes: 1 addition & 3 deletions src/control/cmd/dmg/cont.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
package main

import (
"context"

"github.com/jessevdk/go-flags"
"github.com/pkg/errors"

Expand Down Expand Up @@ -49,7 +47,7 @@ func (c *ContSetOwnerCmd) Execute(args []string) error {
Group: c.GroupName.String(),
}

ctx := context.Background()
ctx := c.MustLogCtx()
err := control.ContSetOwner(ctx, c.ctlInvoker, req)
if err != nil {
msg = errors.WithMessage(err, "FAILED").Error()
Expand Down
5 changes: 2 additions & 3 deletions src/control/cmd/dmg/firmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package main

import (
"context"
"io"
"strings"

Expand Down Expand Up @@ -42,7 +41,7 @@ type firmwareQueryCmd struct {

// Execute runs the firmware query command.
func (cmd *firmwareQueryCmd) Execute(args []string) error {
ctx := context.Background()
ctx := cmd.MustLogCtx()

req := &control.FirmwareQueryReq{
SCM: cmd.isSCMRequested(),
Expand Down Expand Up @@ -127,7 +126,7 @@ type firmwareUpdateCmd struct {

// Execute runs the firmware update command.
func (cmd *firmwareUpdateCmd) Execute(args []string) error {
ctx := context.Background()
ctx := cmd.MustLogCtx()

req := &control.FirmwareUpdateReq{
FirmwarePath: cmd.FilePath,
Expand Down
3 changes: 1 addition & 2 deletions src/control/cmd/dmg/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package main

import (
"context"
"strings"

"github.com/daos-stack/daos/src/control/cmd/dmg/pretty"
Expand All @@ -32,7 +31,7 @@ type networkScanCmd struct {
}

func (cmd *networkScanCmd) Execute(_ []string) error {
ctx := context.Background()
ctx := cmd.MustLogCtx()
req := &control.NetworkScanReq{
Provider: cmd.FabricProvider,
}
Expand Down
34 changes: 17 additions & 17 deletions src/control/cmd/dmg/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func (cmd *PoolCreateCmd) Execute(args []string) error {
// TODO (DAOS-9556) Update the protocol with a new message allowing to perform the
// queries of storage request and the pool creation from the management server
scmBytes, nvmeBytes, err := control.GetMaxPoolSize(
context.Background(),
cmd.MustLogCtx(),
cmd.Logger,
cmd.ctlInvoker,
ranklist.RankList(req.Ranks))
Expand Down Expand Up @@ -375,7 +375,7 @@ func (cmd *PoolListCmd) Execute(_ []string) (errOut error) {
NoQuery: cmd.NoQuery,
}

resp, err := control.ListPools(context.Background(), cmd.ctlInvoker, req)
resp, err := control.ListPools(cmd.MustLogCtx(), cmd.ctlInvoker, req)
if err != nil {
return err // control api returned an error, disregard response
}
Expand Down Expand Up @@ -435,7 +435,7 @@ func (cmd *PoolDestroyCmd) Execute(args []string) error {
Recursive: cmd.Recursive,
}

err := control.PoolDestroy(context.Background(), cmd.ctlInvoker, req)
err := control.PoolDestroy(cmd.MustLogCtx(), cmd.ctlInvoker, req)
if err != nil {
msg = errors.WithMessage(err, "failed").Error()
}
Expand All @@ -457,7 +457,7 @@ func (cmd *PoolEvictCmd) Execute(args []string) error {

req := &control.PoolEvictReq{ID: cmd.PoolID().String()}

err := control.PoolEvict(context.Background(), cmd.ctlInvoker, req)
err := control.PoolEvict(cmd.MustLogCtx(), cmd.ctlInvoker, req)
if err != nil {
msg = errors.WithMessage(err, "failed").Error()
}
Expand Down Expand Up @@ -485,7 +485,7 @@ func (cmd *PoolExcludeCmd) Execute(args []string) error {

req := &control.PoolExcludeReq{ID: cmd.PoolID().String(), Rank: ranklist.Rank(cmd.Rank), Targetidx: idxlist}

err := control.PoolExclude(context.Background(), cmd.ctlInvoker, req)
err := control.PoolExclude(cmd.MustLogCtx(), cmd.ctlInvoker, req)
if err != nil {
msg = errors.WithMessage(err, "failed").Error()
}
Expand Down Expand Up @@ -514,7 +514,7 @@ func (cmd *PoolDrainCmd) Execute(args []string) error {

req := &control.PoolDrainReq{ID: cmd.PoolID().String(), Rank: ranklist.Rank(cmd.Rank), Targetidx: idxlist}

err := control.PoolDrain(context.Background(), cmd.ctlInvoker, req)
err := control.PoolDrain(cmd.MustLogCtx(), cmd.ctlInvoker, req)
if err != nil {
msg = errors.WithMessage(err, "failed").Error()
}
Expand All @@ -539,7 +539,7 @@ func (cmd *PoolExtendCmd) Execute(args []string) error {
Ranks: cmd.RankList.Ranks(),
}

err := control.PoolExtend(context.Background(), cmd.ctlInvoker, req)
err := control.PoolExtend(cmd.MustLogCtx(), cmd.ctlInvoker, req)
if err != nil {
msg = errors.WithMessage(err, "failed").Error()
}
Expand Down Expand Up @@ -572,7 +572,7 @@ func (cmd *PoolReintegrateCmd) Execute(args []string) error {
Targetidx: idxlist,
}

err := control.PoolReintegrate(context.Background(), cmd.ctlInvoker, req)
err := control.PoolReintegrate(cmd.MustLogCtx(), cmd.ctlInvoker, req)
if err != nil {
msg = errors.WithMessage(err, "failed").Error()
}
Expand Down Expand Up @@ -602,7 +602,7 @@ func (cmd *PoolQueryCmd) Execute(args []string) error {
req.IncludeEnabledRanks = cmd.ShowEnabledRanks
req.IncludeDisabledRanks = cmd.ShowDisabledRanks

resp, err := control.PoolQuery(context.Background(), cmd.ctlInvoker, req)
resp, err := control.PoolQuery(cmd.MustLogCtx(), cmd.ctlInvoker, req)

if cmd.JSONOutputEnabled() {
return cmd.OutputJSON(resp, err)
Expand Down Expand Up @@ -642,7 +642,7 @@ func (cmd *PoolQueryTargetsCmd) Execute(args []string) error {
Targets: tgtsList,
}

resp, err := control.PoolQueryTargets(context.Background(), cmd.ctlInvoker, req)
resp, err := control.PoolQueryTargets(cmd.MustLogCtx(), cmd.ctlInvoker, req)

if cmd.JSONOutputEnabled() {
return cmd.OutputJSON(resp, err)
Expand Down Expand Up @@ -671,7 +671,7 @@ func (cmd *PoolUpgradeCmd) Execute(args []string) error {
ID: cmd.PoolID().String(),
}

err := control.PoolUpgrade(context.Background(), cmd.ctlInvoker, req)
err := control.PoolUpgrade(cmd.MustLogCtx(), cmd.ctlInvoker, req)
if err != nil {
return errors.Wrap(err, "pool upgrade failed")
}
Expand Down Expand Up @@ -708,7 +708,7 @@ func (cmd *PoolSetPropCmd) Execute(_ []string) error {
Properties: cmd.Args.Props.ToSet,
}

err := control.PoolSetProp(context.Background(), cmd.ctlInvoker, req)
err := control.PoolSetProp(cmd.MustLogCtx(), cmd.ctlInvoker, req)
if cmd.JSONOutputEnabled() {
return cmd.OutputJSON(nil, err)
}
Expand Down Expand Up @@ -736,7 +736,7 @@ func (cmd *PoolGetPropCmd) Execute(_ []string) error {
Properties: cmd.Args.Props.ToGet,
}

resp, err := control.PoolGetProp(context.Background(), cmd.ctlInvoker, req)
resp, err := control.PoolGetProp(cmd.MustLogCtx(), cmd.ctlInvoker, req)
if cmd.JSONOutputEnabled() {
return cmd.OutputJSON(resp, err)
}
Expand Down Expand Up @@ -765,7 +765,7 @@ type PoolGetACLCmd struct {
func (cmd *PoolGetACLCmd) Execute(args []string) error {
req := &control.PoolGetACLReq{ID: cmd.PoolID().String()}

resp, err := control.PoolGetACL(context.Background(), cmd.ctlInvoker, req)
resp, err := control.PoolGetACL(cmd.MustLogCtx(), cmd.ctlInvoker, req)
if cmd.JSONOutputEnabled() {
return cmd.OutputJSON(resp, err)
}
Expand Down Expand Up @@ -835,7 +835,7 @@ func (cmd *PoolOverwriteACLCmd) Execute(args []string) error {
ACL: acl,
}

resp, err := control.PoolOverwriteACL(context.Background(), cmd.ctlInvoker, req)
resp, err := control.PoolOverwriteACL(cmd.MustLogCtx(), cmd.ctlInvoker, req)
if cmd.JSONOutputEnabled() {
return cmd.OutputJSON(resp, err)
}
Expand Down Expand Up @@ -883,7 +883,7 @@ func (cmd *PoolUpdateACLCmd) Execute(args []string) error {
ACL: acl,
}

resp, err := control.PoolUpdateACL(context.Background(), cmd.ctlInvoker, req)
resp, err := control.PoolUpdateACL(cmd.MustLogCtx(), cmd.ctlInvoker, req)
if cmd.JSONOutputEnabled() {
return cmd.OutputJSON(resp, err)
}
Expand Down Expand Up @@ -913,7 +913,7 @@ func (cmd *PoolDeleteACLCmd) Execute(args []string) error {
Principal: cmd.Principal,
}

resp, err := control.PoolDeleteACL(context.Background(), cmd.ctlInvoker, req)
resp, err := control.PoolDeleteACL(cmd.MustLogCtx(), cmd.ctlInvoker, req)
if cmd.JSONOutputEnabled() {
return cmd.OutputJSON(resp, err)
}
Expand Down
3 changes: 1 addition & 2 deletions src/control/cmd/dmg/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package main

import (
"context"
"strings"

"github.com/pkg/errors"
Expand Down Expand Up @@ -49,7 +48,7 @@ func (cmd *serverSetLogMasksCmd) Execute(_ []string) (errOut error) {

cmd.Debugf("set log masks request: %+v", req)

resp, err := control.SetEngineLogMasks(context.Background(), cmd.ctlInvoker, req)
resp, err := control.SetEngineLogMasks(cmd.MustLogCtx(), cmd.ctlInvoker, req)
if err != nil {
return err // control api returned an error, disregard response
}
Expand Down
9 changes: 4 additions & 5 deletions src/control/cmd/dmg/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package main

import (
"context"
"strings"

"github.com/pkg/errors"
Expand Down Expand Up @@ -61,7 +60,7 @@ func (cmd *storageScanCmd) Execute(_ []string) error {

cmd.Debugf("storage scan request: %+v", req)

resp, err := control.StorageScan(context.Background(), cmd.ctlInvoker, req)
resp, err := control.StorageScan(cmd.MustLogCtx(), cmd.ctlInvoker, req)
if err != nil {
return err
}
Expand Down Expand Up @@ -115,7 +114,7 @@ type storageFormatCmd struct {
//
// Run NVMe and SCM storage format on all connected servers.
func (cmd *storageFormatCmd) Execute(args []string) (err error) {
ctx := context.Background()
ctx := cmd.MustLogCtx()

req := &control.StorageFormatReq{Reformat: cmd.Force}
req.SetHostList(cmd.getHostList())
Expand Down Expand Up @@ -164,7 +163,7 @@ type nvmeRebindCmd struct {
//
// Rebind NVMe SSD from kernel driver and bind to user-space driver on single server.
func (cmd *nvmeRebindCmd) Execute(args []string) error {
ctx := context.Background()
ctx := cmd.MustLogCtx()

if len(cmd.getHostList()) != 1 {
return errors.New("command expects a single host in hostlist")
Expand Down Expand Up @@ -213,7 +212,7 @@ type nvmeAddDeviceCmd struct {
//
// Add recently inserted NVMe SSD to a running engine by updating relevant NVMe config file.
func (cmd *nvmeAddDeviceCmd) Execute(args []string) error {
ctx := context.Background()
ctx := cmd.MustLogCtx()

if len(cmd.getHostList()) != 1 {
return errors.New("command expects a single host in hostlist")
Expand Down
Loading

0 comments on commit 542aa10

Please sign in to comment.