Skip to content

Commit

Permalink
DAOS-14850 control: Allow logging.Logger in Context
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.

Change-Id: I94ea454ca83afa3ba035bdcc8ec419b0ad7897e7
Required-githooks: true
Signed-off-by: Michael MacDonald <mjmac@google.com>
  • Loading branch information
mjmac committed Jan 4, 2024
1 parent f33d9f6 commit 6434de4
Show file tree
Hide file tree
Showing 19 changed files with 193 additions and 68 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 @@ -325,7 +325,7 @@ func (cmd *PoolCreateCmd) Execute(args []string) error {
}
}

ctx := context.Background()
ctx := cmd.MustLogCtx()
req := &control.PoolCreateReq{
User: cmd.UserName.String(),
UserGroup: cmd.GroupName.String(),
Expand Down Expand Up @@ -408,7 +408,7 @@ func (cmd *PoolListCmd) Execute(_ []string) (errOut error) {
NoQuery: cmd.NoQuery,
}

initialResp, err := control.ListPools(context.Background(), cmd.ctlInvoker, req)
initialResp, err := control.ListPools(cmd.MustLogCtx(), cmd.ctlInvoker, req)
if err != nil {
return err // control api returned an error, disregard response
}
Expand Down Expand Up @@ -486,7 +486,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 @@ -508,7 +508,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 @@ -536,7 +536,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 @@ -565,7 +565,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 @@ -590,7 +590,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 @@ -623,7 +623,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 @@ -653,7 +653,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 @@ -693,7 +693,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 @@ -722,7 +722,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 @@ -762,7 +762,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 @@ -790,7 +790,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 @@ -819,7 +819,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 @@ -889,7 +889,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 @@ -937,7 +937,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 @@ -967,7 +967,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 6434de4

Please sign in to comment.