Skip to content

Commit

Permalink
Merge branch 'upgrade-avago-logging' into 225-logging
Browse files Browse the repository at this point in the history
  • Loading branch information
holisticode committed Aug 16, 2022
2 parents 6ae5847 + 099e2a1 commit 45f6c28
Show file tree
Hide file tree
Showing 13 changed files with 185 additions and 163 deletions.
25 changes: 13 additions & 12 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/ava-labs/avalanche-network-runner/local"
"github.com/ava-labs/avalanche-network-runner/rpcpb"
"github.com/ava-labs/avalanchego/utils/logging"
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
Expand Down Expand Up @@ -62,7 +63,7 @@ type client struct {
}

func New(cfg Config, log logging.Logger) (Client, error) {
log.Debug("dialing server at endpoint %s", cfg.Endpoint)
log.Debug("dialing server at ", zap.String("endpoint", cfg.Endpoint))

ctx, cancel := context.WithTimeout(context.Background(), cfg.DialTimeout)
conn, err := grpc.DialContext(
Expand Down Expand Up @@ -179,7 +180,7 @@ func (c *client) StreamStatus(ctx context.Context, pushInterval time.Duration) (
ch := make(chan *rpcpb.ClusterInfo, 1)
go func() {
defer func() {
c.log.Debug("closing stream send %s", stream.CloseSend())
c.log.Debug("closing stream send ", zap.Error(stream.CloseSend()))
close(ch)
}()
c.log.Info("start receive routine")
Expand All @@ -205,9 +206,9 @@ func (c *client) StreamStatus(ctx context.Context, pushInterval time.Duration) (
return
}
if isClientCanceled(stream.Context().Err(), err) {
c.log.Warn("failed to receive status request from gRPC stream due to client cancellation: %s", err)
c.log.Warn("failed to receive status request from gRPC stream due to client cancellation: ", zap.Error(err))
} else {
c.log.Warn("failed to receive status request from gRPC stream: %s", err)
c.log.Warn("failed to receive status request from gRPC stream:", zap.Error(err))
}
return
}
Expand All @@ -231,12 +232,12 @@ func (c *client) AddNode(ctx context.Context, name string, execPath string, opts
ChainConfigs: ret.chainConfigs,
}

c.log.Info("add node %q", name)
c.log.Info("add node", zap.String("name", name))
return c.controlc.AddNode(ctx, req)
}

func (c *client) RemoveNode(ctx context.Context, name string) (*rpcpb.RemoveNodeResponse, error) {
c.log.Info("remove node %q", name)
c.log.Info("remove node", zap.String("name", name))
return c.controlc.RemoveNode(ctx, &rpcpb.RemoveNodeRequest{Name: name})
}

Expand All @@ -253,17 +254,17 @@ func (c *client) RestartNode(ctx context.Context, name string, opts ...OpOption)
}
req.ChainConfigs = ret.chainConfigs

c.log.Info("restart node %q", name)
c.log.Info("restart node", zap.String("name", name))
return c.controlc.RestartNode(ctx, req)
}

func (c *client) AttachPeer(ctx context.Context, nodeName string) (*rpcpb.AttachPeerResponse, error) {
c.log.Info("attaching peer %q", nodeName)
c.log.Info("attaching peer", zap.String("name", nodeName))
return c.controlc.AttachPeer(ctx, &rpcpb.AttachPeerRequest{NodeName: nodeName})
}

func (c *client) SendOutboundMessage(ctx context.Context, nodeName string, peerID string, op uint32, msgBody []byte) (*rpcpb.SendOutboundMessageResponse, error) {
c.log.Info("sending outbound message: node-name %s, peer-id %s", nodeName, peerID)
c.log.Info("sending outbound message", zap.String("name", nodeName), zap.String("peer-ID", peerID))
return c.controlc.SendOutboundMessage(ctx, &rpcpb.SendOutboundMessageRequest{
NodeName: nodeName,
PeerId: peerID,
Expand All @@ -273,12 +274,12 @@ func (c *client) SendOutboundMessage(ctx context.Context, nodeName string, peerI
}

func (c *client) SaveSnapshot(ctx context.Context, snapshotName string) (*rpcpb.SaveSnapshotResponse, error) {
c.log.Info("save snapshot with name %s", snapshotName)
c.log.Info("save snapshot", zap.String("snapshot-name", snapshotName))
return c.controlc.SaveSnapshot(ctx, &rpcpb.SaveSnapshotRequest{SnapshotName: snapshotName})
}

func (c *client) LoadSnapshot(ctx context.Context, snapshotName string, opts ...OpOption) (*rpcpb.LoadSnapshotResponse, error) {
c.log.Info("load snapshot with name %s", snapshotName)
c.log.Info("load snapshot", zap.String("snapshot-name", snapshotName))
ret := &Op{}
ret.applyOpts(opts)
req := rpcpb.LoadSnapshotRequest{
Expand All @@ -301,7 +302,7 @@ func (c *client) LoadSnapshot(ctx context.Context, snapshotName string, opts ...
}

func (c *client) RemoveSnapshot(ctx context.Context, snapshotName string) (*rpcpb.RemoveSnapshotResponse, error) {
c.log.Info("remove snapshot with name %s", snapshotName)
c.log.Info("remove snapshot", zap.String("snapshot-name", snapshotName))
return c.controlc.RemoveSnapshot(ctx, &rpcpb.RemoveSnapshotRequest{SnapshotName: snapshotName})
}

Expand Down
44 changes: 22 additions & 22 deletions cmd/control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/ava-labs/avalanche-network-runner/ux"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/spf13/cobra"
"go.uber.org/zap"
)

func init() {
Expand Down Expand Up @@ -183,8 +184,7 @@ func startFunc(cmd *cobra.Command, args []string) error {
}

if globalNodeConfig != "" {
ux.Print(log, logging.Yellow.Wrap("global node config provided, will be applied to all nodes: %+v"), globalNodeConfig)

ux.Print(log, logging.Yellow.Wrap("global node config provided, will be applied to all nodes"), zap.String("global-node-config", globalNodeConfig))
// validate it's valid JSON
var js json.RawMessage
if err := json.Unmarshal([]byte(globalNodeConfig), &js); err != nil {
Expand Down Expand Up @@ -228,7 +228,7 @@ func startFunc(cmd *cobra.Command, args []string) error {
return err
}

ux.Print(log, logging.Green.Wrap("start response: %+v"), info)
ux.Print(log, logging.Green.Wrap("start"), zap.Any("response", info))
return nil
}

Expand Down Expand Up @@ -266,7 +266,7 @@ func createBlockchainsFunc(cmd *cobra.Command, args []string) error {
return err
}

ux.Print(log, logging.Green.Wrap("deploy-blockchains response: %+v"), info)
ux.Print(log, logging.Green.Wrap("deploy-blockchains"), zap.Any("response", info))
return nil
}

Expand Down Expand Up @@ -307,7 +307,7 @@ func createSubnetsFunc(cmd *cobra.Command, args []string) error {
return err
}

ux.Print(log, logging.Green.Wrap("add-subnets response: %+v"), info)
ux.Print(log, logging.Green.Wrap("add-subnets"), zap.Any("response", info))
return nil
}

Expand Down Expand Up @@ -335,7 +335,7 @@ func healthFunc(cmd *cobra.Command, args []string) error {
return err
}

ux.Print(log, logging.Green.Wrap("health response: %+v"), resp)
ux.Print(log, logging.Green.Wrap("health"), zap.Any("response", resp))
return nil
}

Expand Down Expand Up @@ -363,7 +363,7 @@ func urisFunc(cmd *cobra.Command, args []string) error {
return err
}

ux.Print(log, logging.Green.Wrap("URIs: %q"), uris)
ux.Print(log, logging.Green.Wrap("URIs"), zap.Any("uris", uris))
return nil
}

Expand Down Expand Up @@ -391,7 +391,7 @@ func statusFunc(cmd *cobra.Command, args []string) error {
return err
}

ux.Print(log, logging.Green.Wrap("status response: %+v"), resp)
ux.Print(log, logging.Green.Wrap("status"), zap.Any("response", resp))
return nil
}

Expand Down Expand Up @@ -429,7 +429,7 @@ func streamStatusFunc(cmd *cobra.Command, args []string) error {
go func() {
select {
case sig := <-sigc:
log.Warn("received signal: %s", sig.String())
log.Warn("received signal", zap.String("signal", sig.String()))
case <-ctx.Done():
}
cancel()
Expand All @@ -441,7 +441,7 @@ func streamStatusFunc(cmd *cobra.Command, args []string) error {
return err
}
for info := range ch {
ux.Print(log, logging.Cyan.Wrap("cluster info: %+v"), info)
ux.Print(log, logging.Cyan.Wrap("cluster"), zap.Any("info", info))
}
cancel() // receiver channel is closed, so cancel goroutine
<-donec
Expand Down Expand Up @@ -474,7 +474,7 @@ func removeNodeFunc(cmd *cobra.Command, args []string) error {
return err
}

ux.Print(log, logging.Green.Wrap("remove node response: %+v"), info)
ux.Print(log, logging.Green.Wrap("remove node"), zap.Any("response", info))
return nil
}

Expand Down Expand Up @@ -518,7 +518,7 @@ func addNodeFunc(cmd *cobra.Command, args []string) error {
opts := []client.OpOption{}

if addNodeConfig != "" {
ux.Print(log, logging.Yellow.Wrap("WARNING: overriding node configs with custom provided config: %+v"), addNodeConfig)
ux.Print(log, logging.Yellow.Wrap("WARNING: overriding node configs with custom provided config"), zap.String("add-node-config", addNodeConfig))
// validate it's valid JSON
var js json.RawMessage
if err := json.Unmarshal([]byte(addNodeConfig), &js); err != nil {
Expand Down Expand Up @@ -547,7 +547,7 @@ func addNodeFunc(cmd *cobra.Command, args []string) error {
return err
}

ux.Print(log, logging.Green.Wrap("add node response: %+v"), info)
ux.Print(log, logging.Green.Wrap("add node"), zap.Any("response", info))
return nil
}

Expand Down Expand Up @@ -612,7 +612,7 @@ func restartNodeFunc(cmd *cobra.Command, args []string) error {
return err
}

ux.Print(log, logging.Green.Wrap("restart node response: %+v"), info)
ux.Print(log, logging.Green.Wrap("restart node"), zap.Any("response", info))
return nil
}

Expand Down Expand Up @@ -642,7 +642,7 @@ func attachPeerFunc(cmd *cobra.Command, args []string) error {
return err
}

ux.Print(log, logging.Green.Wrap("attach peer response: %+v"), resp)
ux.Print(log, logging.Green.Wrap("attach peer"), zap.Any("response", resp))
return nil
}

Expand Down Expand Up @@ -711,7 +711,7 @@ func sendOutboundMessageFunc(cmd *cobra.Command, args []string) error {
return err
}

ux.Print(log, logging.Green.Wrap("send outbound message response: %+v"), resp)
ux.Print(log, logging.Green.Wrap("send outbound message"), zap.Any("response", resp))
return nil
}

Expand Down Expand Up @@ -739,7 +739,7 @@ func stopFunc(cmd *cobra.Command, args []string) error {
return err
}

ux.Print(log, logging.Green.Wrap("stop response: %+v"), info)
ux.Print(log, logging.Green.Wrap("stop"), zap.Any("response", info))
return nil
}

Expand Down Expand Up @@ -767,7 +767,7 @@ func saveSnapshotFunc(cmd *cobra.Command, args []string) error {
return err
}

ux.Print(log, logging.Green.Wrap("save-snapshot response: %+v"), resp)
ux.Print(log, logging.Green.Wrap("save-snapshot"), zap.Any("response", resp))
return nil
}

Expand Down Expand Up @@ -833,7 +833,7 @@ func loadSnapshotFunc(cmd *cobra.Command, args []string) error {
}

if globalNodeConfig != "" {
ux.Print(log, logging.Yellow.Wrap("global node config provided, will be applied to all nodes: %+v"), globalNodeConfig)
ux.Print(log, logging.Yellow.Wrap("global node config provided, will be applied to all nodes"), zap.String("global-node-config", globalNodeConfig))

// validate it's valid JSON
var js json.RawMessage
Expand All @@ -850,7 +850,7 @@ func loadSnapshotFunc(cmd *cobra.Command, args []string) error {
return err
}

ux.Print(log, logging.Green.Wrap("load-snapshot response: %+v"), resp)
ux.Print(log, logging.Green.Wrap("load-snapshot"), zap.Any("response", resp))
return nil
}

Expand Down Expand Up @@ -878,7 +878,7 @@ func removeSnapshotFunc(cmd *cobra.Command, args []string) error {
return err
}

ux.Print(log, logging.Green.Wrap("remove-snapshot response: %+v"), resp)
ux.Print(log, logging.Green.Wrap("remove-snapshot"), zap.Any("response", resp))
return nil
}

Expand All @@ -905,7 +905,7 @@ func getSnapshotNamesFunc(cmd *cobra.Command, args []string) error {
return err
}

ux.Print(log, logging.Green.Wrap("Snapshots: %+v"), snapshotNames)
ux.Print(log, logging.Green.Wrap("Snapshots"), zap.Strings("snapshot-names", snapshotNames))
return nil
}

Expand Down
5 changes: 3 additions & 2 deletions cmd/ping/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ava-labs/avalanche-network-runner/ux"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/spf13/cobra"
"go.uber.org/zap"
)

var (
Expand Down Expand Up @@ -67,7 +68,7 @@ func pingFunc(cmd *cobra.Command, args []string) error {
return err
}

logString := "ping response " + logging.Green.Wrap("%+v")
ux.Print(log, logString, resp)
logString := logging.Green.Wrap("ping")
ux.Print(log, logString, zap.Any("response", resp))
return nil
}
7 changes: 4 additions & 3 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/ava-labs/avalanche-network-runner/utils/constants"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/spf13/cobra"
"go.uber.org/zap"
)

func init() {
Expand Down Expand Up @@ -97,15 +98,15 @@ func serverFunc(cmd *cobra.Command, args []string) (err error) {
signal.Notify(sigc, syscall.SIGINT, syscall.SIGTERM)
select {
case sig := <-sigc:
log.Warn("signal received; closing server: %s", sig.String())
log.Warn("signal received; closing server: %s", zap.String("signal", sig.String()))
rootCancel()
// wait for server stop
waitForServerStop := <-errc
log.Warn("closed server: %v", waitForServerStop)
log.Warn("closed server", zap.Error(waitForServerStop))
case serverClosed := <-errc:
// server already stopped here
_ = rootCancel
log.Warn("server closed: %s", serverClosed)
log.Warn("server closed", zap.Error(serverClosed))
}
return err
}
10 changes: 9 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ module github.com/ava-labs/avalanche-network-runner

go 1.18

replace github.com/ava-labs/avalanchego => ../avalanchego-internal

replace github.com/ava-labs/avalanche-ledger-go => ../avalanche-ledger-go

require (
github.com/ava-labs/avalanchego v1.7.17
github.com/ava-labs/coreth v0.8.15-rc.2
Expand All @@ -14,17 +18,20 @@ require (
github.com/shirou/gopsutil v3.21.11+incompatible
github.com/spf13/cobra v1.3.0
github.com/stretchr/testify v1.7.2
go.uber.org/zap v1.21.0
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
google.golang.org/genproto v0.0.0-20220712132514-bdd2acd4974d
google.golang.org/grpc v1.47.0
google.golang.org/protobuf v1.28.0
)

require (
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/NYTimes/gziphandler v1.1.1 // indirect
github.com/VictoriaMetrics/fastcache v1.10.0 // indirect
github.com/aead/siphash v1.0.1 // indirect
github.com/ava-labs/avalanche-ledger-go v0.0.0-00010101000000-000000000000 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd v0.23.1 // indirect
Expand Down Expand Up @@ -112,9 +119,10 @@ require (
github.com/tklauser/numcpus v0.2.2 // indirect
github.com/tyler-smith/go-bip39 v1.0.2 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
github.com/zondax/hid v0.9.0 // indirect
github.com/zondax/ledger-go v0.12.2 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
golang.org/x/net v0.0.0-20220708220712-1185a9018129 // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
Expand Down
Loading

0 comments on commit 45f6c28

Please sign in to comment.