Skip to content

Commit 2d68c65

Browse files
authored
DAOS-14850 control: Allow logging.Logger in Context (#13569) (#14210)
Updates control plane tools to set a context in a logger for ease of debug/trace logging. Signed-off-by: Michael MacDonald <[email protected]>
1 parent 98c953a commit 2d68c65

19 files changed

+195
-71
lines changed

src/control/cmd/daos_agent/attachinfo.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
package main
88

99
import (
10-
"context"
1110
"fmt"
1211
"os"
1312

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

39-
ctx := context.Background()
39+
ctx := cmd.MustLogCtx()
4040
req := &control.GetAttachInfoReq{
4141
AllRanks: true,
4242
}

src/control/cmd/daos_agent/network.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
package main
88

99
import (
10-
"context"
1110
"strings"
1211

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

3332
fabricScanner := hwprov.DefaultFabricScanner(cmd.Logger)
3433

35-
results, err := fabricScanner.Scan(context.Background(), prov)
34+
results, err := fabricScanner.Scan(cmd.MustLogCtx(), prov)
3635
if err != nil {
3736
return nil
3837
}

src/control/cmd/daos_agent/start.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (cmd *startCmd) Execute(_ []string) error {
5454
cmd.Infof("Starting %s (pid %d)", versionString(), os.Getpid())
5555
startedAt := time.Now()
5656

57-
parent, shutdown := context.WithCancel(context.Background())
57+
parent, shutdown := context.WithCancel(cmd.MustLogCtx())
5858
defer shutdown()
5959

6060
var shuttingDown atm.Bool

src/control/cmd/daos_server/auto.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,5 +192,5 @@ func (cmd *configGenCmd) Execute(_ []string) error {
192192
return err
193193
}
194194

195-
return cmd.confGenPrint(context.Background(), getLocalFabric, getLocalStorage)
195+
return cmd.confGenPrint(cmd.MustLogCtx(), getLocalFabric, getLocalStorage)
196196
}

src/control/cmd/daos_server/network.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (cmd *networkScanCmd) Execute(_ []string) error {
8383
return err
8484
}
8585

86-
ctx := context.Background()
86+
ctx := cmd.MustLogCtx()
8787
fs := hwprov.DefaultFabricScanner(cmd.Logger)
8888

8989
var prov string

src/control/cmd/dmg/auto.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,5 @@ func (cmd *configGenCmd) confGenPrint(ctx context.Context) error {
126126
// parameters suitable to be used across all hosts in provided host list. Use the control API to
127127
// generate config from remote scan results.
128128
func (cmd *configGenCmd) Execute(_ []string) error {
129-
return cmd.confGenPrint(context.Background())
129+
return cmd.confGenPrint(cmd.MustLogCtx())
130130
}

src/control/cmd/dmg/cont.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
package main
88

99
import (
10-
"context"
11-
1210
"github.com/jessevdk/go-flags"
1311
"github.com/pkg/errors"
1412

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

52-
ctx := context.Background()
50+
ctx := c.MustLogCtx()
5351
err := control.ContSetOwner(ctx, c.ctlInvoker, req)
5452
if err != nil {
5553
msg = errors.WithMessage(err, "FAILED").Error()

src/control/cmd/dmg/firmware.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
package main
88

99
import (
10-
"context"
1110
"io"
1211
"strings"
1312

@@ -42,7 +41,7 @@ type firmwareQueryCmd struct {
4241

4342
// Execute runs the firmware query command.
4443
func (cmd *firmwareQueryCmd) Execute(args []string) error {
45-
ctx := context.Background()
44+
ctx := cmd.MustLogCtx()
4645

4746
req := &control.FirmwareQueryReq{
4847
SCM: cmd.isSCMRequested(),
@@ -127,7 +126,7 @@ type firmwareUpdateCmd struct {
127126

128127
// Execute runs the firmware update command.
129128
func (cmd *firmwareUpdateCmd) Execute(args []string) error {
130-
ctx := context.Background()
129+
ctx := cmd.MustLogCtx()
131130

132131
req := &control.FirmwareUpdateReq{
133132
FirmwarePath: cmd.FilePath,

src/control/cmd/dmg/network.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
package main
88

99
import (
10-
"context"
1110
"strings"
1211

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

3433
func (cmd *networkScanCmd) Execute(_ []string) error {
35-
ctx := context.Background()
34+
ctx := cmd.MustLogCtx()
3635
req := &control.NetworkScanReq{
3736
Provider: cmd.FabricProvider,
3837
}

src/control/cmd/dmg/pool.go

+17-17
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ func (cmd *PoolCreateCmd) Execute(args []string) error {
255255
// TODO (DAOS-9556) Update the protocol with a new message allowing to perform the
256256
// queries of storage request and the pool creation from the management server
257257
scmBytes, nvmeBytes, err := control.GetMaxPoolSize(
258-
context.Background(),
258+
cmd.MustLogCtx(),
259259
cmd.Logger,
260260
cmd.ctlInvoker,
261261
ranklist.RankList(req.Ranks))
@@ -375,7 +375,7 @@ func (cmd *PoolListCmd) Execute(_ []string) (errOut error) {
375375
NoQuery: cmd.NoQuery,
376376
}
377377

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

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

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

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

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

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

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

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

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

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

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

607607
if cmd.JSONOutputEnabled() {
608608
return cmd.OutputJSON(resp, err)
@@ -642,7 +642,7 @@ func (cmd *PoolQueryTargetsCmd) Execute(args []string) error {
642642
Targets: tgtsList,
643643
}
644644

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

647647
if cmd.JSONOutputEnabled() {
648648
return cmd.OutputJSON(resp, err)
@@ -671,7 +671,7 @@ func (cmd *PoolUpgradeCmd) Execute(args []string) error {
671671
ID: cmd.PoolID().String(),
672672
}
673673

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

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

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

768-
resp, err := control.PoolGetACL(context.Background(), cmd.ctlInvoker, req)
768+
resp, err := control.PoolGetACL(cmd.MustLogCtx(), cmd.ctlInvoker, req)
769769
if cmd.JSONOutputEnabled() {
770770
return cmd.OutputJSON(resp, err)
771771
}
@@ -835,7 +835,7 @@ func (cmd *PoolOverwriteACLCmd) Execute(args []string) error {
835835
ACL: acl,
836836
}
837837

838-
resp, err := control.PoolOverwriteACL(context.Background(), cmd.ctlInvoker, req)
838+
resp, err := control.PoolOverwriteACL(cmd.MustLogCtx(), cmd.ctlInvoker, req)
839839
if cmd.JSONOutputEnabled() {
840840
return cmd.OutputJSON(resp, err)
841841
}
@@ -883,7 +883,7 @@ func (cmd *PoolUpdateACLCmd) Execute(args []string) error {
883883
ACL: acl,
884884
}
885885

886-
resp, err := control.PoolUpdateACL(context.Background(), cmd.ctlInvoker, req)
886+
resp, err := control.PoolUpdateACL(cmd.MustLogCtx(), cmd.ctlInvoker, req)
887887
if cmd.JSONOutputEnabled() {
888888
return cmd.OutputJSON(resp, err)
889889
}
@@ -913,7 +913,7 @@ func (cmd *PoolDeleteACLCmd) Execute(args []string) error {
913913
Principal: cmd.Principal,
914914
}
915915

916-
resp, err := control.PoolDeleteACL(context.Background(), cmd.ctlInvoker, req)
916+
resp, err := control.PoolDeleteACL(cmd.MustLogCtx(), cmd.ctlInvoker, req)
917917
if cmd.JSONOutputEnabled() {
918918
return cmd.OutputJSON(resp, err)
919919
}

src/control/cmd/dmg/server.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
package main
88

99
import (
10-
"context"
1110
"strings"
1211

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

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

52-
resp, err := control.SetEngineLogMasks(context.Background(), cmd.ctlInvoker, req)
51+
resp, err := control.SetEngineLogMasks(cmd.MustLogCtx(), cmd.ctlInvoker, req)
5352
if err != nil {
5453
return err // control api returned an error, disregard response
5554
}

src/control/cmd/dmg/storage.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
package main
88

99
import (
10-
"context"
1110
"strings"
1211

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

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

64-
resp, err := control.StorageScan(context.Background(), cmd.ctlInvoker, req)
63+
resp, err := control.StorageScan(cmd.MustLogCtx(), cmd.ctlInvoker, req)
6564
if err != nil {
6665
return err
6766
}
@@ -115,7 +114,7 @@ type storageFormatCmd struct {
115114
//
116115
// Run NVMe and SCM storage format on all connected servers.
117116
func (cmd *storageFormatCmd) Execute(args []string) (err error) {
118-
ctx := context.Background()
117+
ctx := cmd.MustLogCtx()
119118

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

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

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

0 commit comments

Comments
 (0)