From 5d32001edfaa18d1c010af65db707cdb38141e80 Mon Sep 17 00:00:00 2001 From: Christopher Swenson Date: Wed, 20 Mar 2024 08:36:21 -0700 Subject: [PATCH] Upgrade to msgpack v2 2.1.2 (#705) This adds the option to specify what version of the `time.Time` encoding format is desired. The default option is `false`, which preserves compatibility with the current dependency of `hashicorp/go-msgpack 0.5.5` in go.mod, but users of this library will probably want to override the the setting. While we're here, upgrade the go.mod file. I tested that this appears to work with Nomad. This needs to be updated and merged after https://github.com/hashicorp/memberlist/pull/292 --- .github/workflows/check.yml | 8 +-- client/rpc_client.go | 27 +++++++--- cmd/serf/command/agent/command.go | 2 +- cmd/serf/command/agent/config.go | 6 +++ cmd/serf/command/agent/ipc.go | 51 ++++++++++-------- cmd/serf/command/agent/rpc_client_test.go | 2 +- cmd/serf/command/util_test.go | 2 +- coordinate/config.go | 13 +++-- go.mod | 45 ++++++++++++---- go.sum | 65 +++++++++++------------ serf/config.go | 6 +++ serf/delegate.go | 4 +- serf/delegate_test.go | 2 +- serf/event.go | 2 +- serf/internal_query.go | 8 +-- serf/internal_query_test.go | 4 +- serf/keymanager.go | 2 +- serf/messages.go | 12 +++-- serf/messages_test.go | 4 +- serf/ping_delegate.go | 8 ++- serf/serf.go | 30 ++++++----- serf/serf_test.go | 2 +- testutil/retry/retry.go | 15 +++--- 23 files changed, 195 insertions(+), 125 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index a9216293f..07530e5d8 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - GO_VERSION: ['1.19', '1.20'] + GO_VERSION: [ "1.19","1.20","1.21" ] steps: - name: "Fetch source code" uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 @@ -45,7 +45,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - GO_VERSION: [ "1.16","1.17","1.18" ] + GO_VERSION: [ "1.19","1.20","1.21" ] steps: - name: "Fetch source code" uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 @@ -76,7 +76,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - GO_VERSION: [ "1.16","1.17","1.18" ] + GO_VERSION: [ "1.19","1.20","1.21" ] steps: - name: "Fetch source code" uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 @@ -107,7 +107,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - GO_VERSION: [ "1.16","1.17","1.18" ] + GO_VERSION: [ "1.19","1.20","1.21" ] steps: - name: "Fetch source code" uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 diff --git a/client/rpc_client.go b/client/rpc_client.go index 6173cc00e..99470f240 100644 --- a/client/rpc_client.go +++ b/client/rpc_client.go @@ -12,7 +12,7 @@ import ( "sync/atomic" "time" - "github.com/hashicorp/go-msgpack/codec" + "github.com/hashicorp/go-msgpack/v2/codec" "github.com/hashicorp/logutils" "github.com/hashicorp/serf/coordinate" ) @@ -53,6 +53,12 @@ type Config struct { // If provided, overrides the DefaultTimeout used for // IO deadlines Timeout time.Duration + + // MsgpackUseNewTimeFormat when set to true, force the underlying msgpack + // codec to use the new format of time.Time when encoding (used in + // go-msgpack v1.1.5 by default). Decoding is not affected, as all + // go-msgpack v2.1.0+ decoders know how to decode both formats. + MsgpackUseNewTimeFormat bool } // RPCClient is used to make requests to the Agent using an RPC mechanism. @@ -119,6 +125,15 @@ func NewRPCClient(addr string) (*RPCClient, error) { return ClientFromConfig(&conf) } +func (c *Config) newMsgpackHandle() *codec.MsgpackHandle { + return &codec.MsgpackHandle{ + WriteExt: true, + BasicHandle: codec.BasicHandle{ + TimeNotBuiltin: !c.MsgpackUseNewTimeFormat, + }, + } +} + // ClientFromConfig is used to create a new RPC client given the // configuration object. This will return a client, or an error if // the connection could not be established. @@ -144,10 +159,8 @@ func ClientFromConfig(c *Config) (*RPCClient, error) { dispatch: make(map[uint64]seqHandler), shutdownCh: make(chan struct{}), } - client.dec = codec.NewDecoder(client.reader, - &codec.MsgpackHandle{RawToString: true, WriteExt: true}) - client.enc = codec.NewEncoder(client.writer, - &codec.MsgpackHandle{RawToString: true, WriteExt: true}) + client.dec = codec.NewDecoder(client.reader, c.newMsgpackHandle()) + client.enc = codec.NewEncoder(client.writer, c.newMsgpackHandle()) go client.listen() // Do the initial handshake @@ -202,8 +215,8 @@ func (c *RPCClient) ForceLeave(node string) error { return c.genericRPC(&header, &req, nil) } -//ForceLeavePrune uses ForceLeave but is used to reap the -//node entirely +// ForceLeavePrune uses ForceLeave but is used to reap the +// node entirely func (c *RPCClient) ForceLeavePrune(node string) error { header := requestHeader{ Command: forceLeaveCommand, diff --git a/cmd/serf/command/agent/command.go b/cmd/serf/command/agent/command.go index 3feff1e2c..dbbe860a7 100644 --- a/cmd/serf/command/agent/command.go +++ b/cmd/serf/command/agent/command.go @@ -452,7 +452,7 @@ func (c *Command) startAgent(config *Config, agent *Agent, // Start the IPC layer c.Ui.Output("Starting Serf agent RPC...") - ipc := NewAgentIPC(agent, config.RPCAuthKey, rpcListener, logOutput, logWriter) + ipc := NewAgentIPC(agent, config.RPCAuthKey, rpcListener, logOutput, logWriter, config.MsgpackUseNewTimeFormat) c.Ui.Output("Serf agent running!") c.Ui.Info(fmt.Sprintf(" Node name: '%s'", config.NodeName)) diff --git a/cmd/serf/command/agent/config.go b/cmd/serf/command/agent/config.go index 47eb39f5a..49186c529 100644 --- a/cmd/serf/command/agent/config.go +++ b/cmd/serf/command/agent/config.go @@ -235,6 +235,12 @@ type Config struct { // contain alphanumeric, dashes and '.'characters // and sets maximum length to 128 characters ValidateNodeNames bool `mapstructure:"validate_node_names"` + + // MsgpackUseNewTimeFormat is used to force the underlying msgpack codec to + // use the newer format of time.Time when encoding, used in versions <=0.5.5 + // by default. Decoding is not affected, as all decoders know how to decode + // both formats. + MsgpackUseNewTimeFormat bool } // BindAddrParts returns the parts of the BindAddr that should be diff --git a/cmd/serf/command/agent/ipc.go b/cmd/serf/command/agent/ipc.go index c4a532d59..8ff2af336 100644 --- a/cmd/serf/command/agent/ipc.go +++ b/cmd/serf/command/agent/ipc.go @@ -38,7 +38,7 @@ import ( "time" "github.com/armon/go-metrics" - "github.com/hashicorp/go-msgpack/codec" + "github.com/hashicorp/go-msgpack/v2/codec" "github.com/hashicorp/logutils" "github.com/hashicorp/serf/coordinate" "github.com/hashicorp/serf/serf" @@ -241,14 +241,15 @@ type memberEventRecord struct { type AgentIPC struct { sync.Mutex - agent *Agent - authKey string - clients map[string]*IPCClient - listener net.Listener - logger *log.Logger - logWriter *logWriter - stop uint32 - stopCh chan struct{} + agent *Agent + authKey string + clients map[string]*IPCClient + listener net.Listener + logger *log.Logger + logWriter *logWriter + stop uint32 + stopCh chan struct{} + msgpackUseNewTimeFormat bool } type IPCClient struct { @@ -330,18 +331,19 @@ func (c *IPCClient) RegisterQuery(q *serf.Query) uint64 { // NewAgentIPC is used to create a new Agent IPC handler func NewAgentIPC(agent *Agent, authKey string, listener net.Listener, - logOutput io.Writer, logWriter *logWriter) *AgentIPC { + logOutput io.Writer, logWriter *logWriter, msgpackUseNewTimeFormat bool) *AgentIPC { if logOutput == nil { logOutput = os.Stderr } ipc := &AgentIPC{ - agent: agent, - authKey: authKey, - clients: make(map[string]*IPCClient), - listener: listener, - logger: log.New(logOutput, "", log.LstdFlags), - logWriter: logWriter, - stopCh: make(chan struct{}), + agent: agent, + authKey: authKey, + clients: make(map[string]*IPCClient), + listener: listener, + logger: log.New(logOutput, "", log.LstdFlags), + logWriter: logWriter, + stopCh: make(chan struct{}), + msgpackUseNewTimeFormat: msgpackUseNewTimeFormat, } go ipc.listen() return ipc @@ -370,6 +372,15 @@ func (i *AgentIPC) isStopped() bool { return atomic.LoadUint32(&i.stop) == 1 } +func (i *AgentIPC) newMsgpackHandle() *codec.MsgpackHandle { + return &codec.MsgpackHandle{ + WriteExt: true, + BasicHandle: codec.BasicHandle{ + TimeNotBuiltin: !i.msgpackUseNewTimeFormat, + }, + } +} + // listen is a long running routine that listens for new clients func (i *AgentIPC) listen() { for { @@ -393,10 +404,8 @@ func (i *AgentIPC) listen() { eventStreams: make(map[uint64]*eventStream), pendingQueries: make(map[uint64]*serf.Query), } - client.dec = codec.NewDecoder(client.reader, - &codec.MsgpackHandle{RawToString: true, WriteExt: true}) - client.enc = codec.NewEncoder(client.writer, - &codec.MsgpackHandle{RawToString: true, WriteExt: true}) + client.dec = codec.NewDecoder(client.reader, i.newMsgpackHandle()) + client.enc = codec.NewEncoder(client.writer, i.newMsgpackHandle()) // Register the client i.Lock() diff --git a/cmd/serf/command/agent/rpc_client_test.go b/cmd/serf/command/agent/rpc_client_test.go index 29b86fe82..2de3dd305 100644 --- a/cmd/serf/command/agent/rpc_client_test.go +++ b/cmd/serf/command/agent/rpc_client_test.go @@ -40,7 +40,7 @@ func testRPCClientWithConfig(t *testing.T, ip net.IP, agentConf *Config, mult := io.MultiWriter(tw, lw) agent := testAgentWithConfig(t, ip, agentConf, serfConf, mult) - ipc := NewAgentIPC(agent, "", l, mult, lw) + ipc := NewAgentIPC(agent, "", l, mult, lw, serfConf.MsgpackUseNewTimeFormat) rpcClient, err := client.NewRPCClient(l.Addr().String()) if err != nil { diff --git a/cmd/serf/command/util_test.go b/cmd/serf/command/util_test.go index 5890035f9..4502fe1bf 100644 --- a/cmd/serf/command/util_test.go +++ b/cmd/serf/command/util_test.go @@ -60,6 +60,6 @@ func testIPC(t *testing.T, ip net.IP, a *agent.Agent) (string, *agent.AgentIPC) lw := agent.NewLogWriter(512) mult := io.MultiWriter(tw, lw) - ipc := agent.NewAgentIPC(a, "", l, mult, lw) + ipc := agent.NewAgentIPC(a, "", l, mult, lw, false) return rpcAddr, ipc } diff --git a/coordinate/config.go b/coordinate/config.go index b6526953e..02cce7e98 100644 --- a/coordinate/config.go +++ b/coordinate/config.go @@ -14,12 +14,17 @@ import ( // here: // // [1] Dabek, Frank, et al. "Vivaldi: A decentralized network coordinate system." -// ACM SIGCOMM Computer Communication Review. Vol. 34. No. 4. ACM, 2004. +// +// ACM SIGCOMM Computer Communication Review. Vol. 34. No. 4. ACM, 2004. +// // [2] Ledlie, Jonathan, Paul Gardner, and Margo I. Seltzer. "Network Coordinates -// in the Wild." NSDI. Vol. 7. 2007. +// +// in the Wild." NSDI. Vol. 7. 2007. +// // [3] Lee, Sanghwan, et al. "On suitability of Euclidean embedding for -// host-based network coordinate systems." Networking, IEEE/ACM Transactions -// on 18.1 (2010): 27-40. +// +// host-based network coordinate systems." Networking, IEEE/ACM Transactions +// on 18.1 (2010): 27-40. type Config struct { // The dimensionality of the coordinate system. As discussed in [2], more // dimensions improves the accuracy of the estimates up to a point. Per [2] diff --git a/go.mod b/go.mod index 458403775..a82e35d18 100644 --- a/go.mod +++ b/go.mod @@ -1,22 +1,49 @@ module github.com/hashicorp/serf -go 1.12 +go 1.19 require ( github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e github.com/armon/go-metrics v0.4.1 - github.com/armon/go-radix v1.0.0 // indirect - github.com/fatih/color v1.9.0 // indirect - github.com/hashicorp/go-msgpack v0.5.3 - github.com/hashicorp/go-multierror v1.1.0 // indirect + github.com/hashicorp/go-msgpack/v2 v2.1.2 github.com/hashicorp/go-syslog v1.0.0 - github.com/hashicorp/go-uuid v1.0.1 // indirect github.com/hashicorp/logutils v1.0.0 github.com/hashicorp/mdns v1.0.4 - github.com/hashicorp/memberlist v0.5.0 - github.com/mattn/go-colorable v0.1.6 // indirect + github.com/hashicorp/memberlist v0.5.1 github.com/mitchellh/cli v1.1.5 github.com/mitchellh/mapstructure v1.5.0 - github.com/posener/complete v1.2.3 // indirect github.com/ryanuber/columnize v2.1.2+incompatible ) + +require ( + github.com/Masterminds/goutils v1.1.1 // indirect + github.com/Masterminds/semver/v3 v3.1.1 // indirect + github.com/Masterminds/sprig/v3 v3.2.1 // indirect + github.com/armon/go-radix v1.0.0 // indirect + github.com/bgentry/speakeasy v0.1.0 // indirect + github.com/fatih/color v1.9.0 // indirect + github.com/google/btree v1.1.2 // indirect + github.com/google/uuid v1.1.2 // indirect + github.com/hashicorp/errwrap v1.1.0 // indirect + github.com/hashicorp/go-immutable-radix v1.3.1 // indirect + github.com/hashicorp/go-multierror v1.1.1 // indirect + github.com/hashicorp/go-sockaddr v1.0.5 // indirect + github.com/hashicorp/go-uuid v1.0.1 // indirect + github.com/hashicorp/golang-lru v1.0.2 // indirect + github.com/huandu/xstrings v1.3.2 // indirect + github.com/imdario/mergo v0.3.11 // indirect + github.com/mattn/go-colorable v0.1.6 // indirect + github.com/mattn/go-isatty v0.0.12 // indirect + github.com/miekg/dns v1.1.56 // indirect + github.com/mitchellh/copystructure v1.0.0 // indirect + github.com/mitchellh/reflectwalk v1.0.0 // indirect + github.com/posener/complete v1.2.3 // indirect + github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect + github.com/shopspring/decimal v1.2.0 // indirect + github.com/spf13/cast v1.3.1 // indirect + golang.org/x/crypto v0.14.0 // indirect + golang.org/x/mod v0.13.0 // indirect + golang.org/x/net v0.17.0 // indirect + golang.org/x/sys v0.13.0 // indirect + golang.org/x/tools v0.14.0 // indirect +) diff --git a/go.sum b/go.sum index eb8f9ef7b..21cc9215e 100644 --- a/go.sum +++ b/go.sum @@ -11,7 +11,6 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e h1:QEF07wC0T1rKkctt1RINW/+RMTVmiwxETico2l3gxJA= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= -github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= github.com/armon/go-metrics v0.4.1 h1:hR91U9KYmb6bLBYLQjyM+3j+rcd/UhE+G78SFnF8gJA= github.com/armon/go-metrics v0.4.1/go.mod h1:E6amYzXo6aW1tqzoZGT755KkbgrJsSdpwZ+3JqfkOG4= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= @@ -40,40 +39,43 @@ github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c h1:964Od4U6p2jUkFxvCydnIczKteheJEzHRToSGK3Bnlw= -github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.1.2 h1:xf4v41cLI2Z6FxbKm+8Bu+m8ifhj15JuZ9sa0jZCMUU= +github.com/google/btree v1.1.2/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= +github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= -github.com/hashicorp/go-immutable-radix v1.0.0 h1:AKDB1HM5PWEA7i4nhcpwOrO2byshxBjXVn/J/3+z5/0= github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= -github.com/hashicorp/go-msgpack v0.5.3 h1:zKjpN5BK/P5lMYrLmBHdBULWbJ0XpYR+7NGzqkZzoD4= -github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= +github.com/hashicorp/go-immutable-radix v1.3.1 h1:DKHmCUm2hRBK510BaiZlwvpD40f8bJFeZnpfm2KLowc= +github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +github.com/hashicorp/go-msgpack/v2 v2.1.2 h1:4Ee8FTp834e+ewB71RDrQ0VKpyFdrKOjvYtnQ/ltVj0= +github.com/hashicorp/go-msgpack/v2 v2.1.2/go.mod h1:upybraOAblm4S7rx0+jeNy+CWWhzywQsSRV5033mMu4= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= -github.com/hashicorp/go-multierror v1.1.0 h1:B9UzwGQJehnUY1yNrnwREHc3fGbC2xefo8g4TbElacI= -github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA= +github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= +github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= -github.com/hashicorp/go-sockaddr v1.0.0 h1:GeH6tui99pF4NJgfnhp+L6+FfobzVW3Ah46sLo0ICXs= -github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= +github.com/hashicorp/go-sockaddr v1.0.5 h1:dvk7TIXCZpmfOlM+9mlcrWmWjw/wlKT+VDq2wMvfPJU= +github.com/hashicorp/go-sockaddr v1.0.5/go.mod h1:uoUUmtwU7n9Dv3O4SNLeFvg0SxQ3lyjsj6+CCykpaxI= github.com/hashicorp/go-syslog v1.0.0 h1:KaodqZuhUoZereWVIYmpUgZysurB1kBLX2j0MwMrUAE= github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1BE= github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCOH9wdo= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c= +github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/mdns v1.0.4 h1:sY0CMhFmjIPDMlTB+HfymFHCaYLhgifZ0QhjaYKD/UQ= github.com/hashicorp/mdns v1.0.4/go.mod h1:mtBihi+LeNXGtG8L9dX59gAEa12BDtBQSp4v/YAJqrc= -github.com/hashicorp/memberlist v0.5.0 h1:EtYPN8DpAURiapus508I4n9CzHs2W+8NZGbmmR/prTM= -github.com/hashicorp/memberlist v0.5.0/go.mod h1:yvyXLpo0QaGE59Y7hDTsTzDD25JYBZ4mHgHUZ8lrOI0= +github.com/hashicorp/memberlist v0.5.1 h1:mk5dRuzeDNis2bi6LLoQIXfMH7JQvAzt3mQD0vNZZUo= +github.com/hashicorp/memberlist v0.5.1/go.mod h1:zGDXV6AqbDTKTM6yxW0I4+JtFzZAJVoIPvss4hV8F24= github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/huandu/xstrings v1.3.2 h1:L18LIDzqlW6xN2rEkpdV8+oL/IXWJ1APd+vsdYy4Wdw= github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= @@ -84,10 +86,8 @@ github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= @@ -99,9 +99,9 @@ github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOA github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= -github.com/miekg/dns v1.1.41 h1:WMszZWJG0XmzbK9FEmzH2TVcqYzFesusSIB41b8KHxY= github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI= +github.com/miekg/dns v1.1.56 h1:5imZaSeoRNvpM9SzWNhEcP9QliKiz20/dA2QabIGVnE= +github.com/miekg/dns v1.1.56/go.mod h1:cRm6Oo2C8TY9ZS/TqsSrseAcncm74lfK5G+ikN2SWWY= github.com/mitchellh/cli v1.1.5 h1:OxRIeJXpAMztws/XHlN2vu6imG5Dpq+j61AzAX5fLng= github.com/mitchellh/cli v1.1.5/go.mod h1:v8+iFts2sPIKUV1ltktPXMCC8fumSKFItNcD2cLtRR4= github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ= @@ -115,7 +115,6 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -157,32 +156,30 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a h1:vclmkQCjlDX5OydZ9wv8rBCcS0QyQY66Mpf/7BZbInM= golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY= +golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1 h1:4qWs8cYYH6PoEFy4dfhDFgoMGkwAcETd+MmPdCPMzUc= golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -190,26 +187,24 @@ golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 h1:WIoqL4EROvwiPdUtaip4VcDdpZ4kha7wBWZrbVKCIZg= -golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc= +golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/serf/config.go b/serf/config.go index 2a4fb7649..c44aa7561 100644 --- a/serf/config.go +++ b/serf/config.go @@ -269,6 +269,12 @@ type Config struct { // MetricLabels is a map of optional labels to apply to all metrics emitted. MetricLabels []metrics.Label + + // MsgpackUseNewTimeFormat is used to force the underlying msgpack codec to + // use the newer format of time.Time when encoding, used in versions <=0.5.5 + // by default. Decoding is not affected, as all decoders know how to decode + // both formats. + MsgpackUseNewTimeFormat bool } // Init allocates the subdata structures diff --git a/serf/delegate.go b/serf/delegate.go index 6555f5a26..405ed2644 100644 --- a/serf/delegate.go +++ b/serf/delegate.go @@ -8,7 +8,7 @@ import ( "fmt" "github.com/armon/go-metrics" - "github.com/hashicorp/go-msgpack/codec" + "github.com/hashicorp/go-msgpack/v2/codec" "github.com/hashicorp/memberlist" ) @@ -200,7 +200,7 @@ func (d *delegate) LocalState(join bool) []byte { } // Encode the push pull state - buf, err := encodeMessage(messagePushPullType, &pp) + buf, err := encodeMessage(messagePushPullType, &pp, d.serf.msgpackUseNewTimeFormat) if err != nil { d.serf.logger.Printf("[ERR] serf: Failed to encode local state: %v", err) return nil diff --git a/serf/delegate_test.go b/serf/delegate_test.go index 3174e3dde..a45677a52 100644 --- a/serf/delegate_test.go +++ b/serf/delegate_test.go @@ -187,7 +187,7 @@ func TestDelegate_MergeRemoteState(t *testing.T) { QueryLTime: 100, } - buf, err := encodeMessage(messagePushPullType, &pp) + buf, err := encodeMessage(messagePushPullType, &pp, c1.MsgpackUseNewTimeFormat) if err != nil { t.Fatalf("err: %v", err) } diff --git a/serf/event.go b/serf/event.go index ec46a674a..45cd378cb 100644 --- a/serf/event.go +++ b/serf/event.go @@ -199,7 +199,7 @@ func (q *Query) Respond(buf []byte) error { resp := q.createResponse(buf) // Encode response - raw, err := encodeMessage(messageQueryResponseType, resp) + raw, err := encodeMessage(messageQueryResponseType, resp, q.serf.msgpackUseNewTimeFormat) if err != nil { return fmt.Errorf("failed to format response: %v", err) } diff --git a/serf/internal_query.go b/serf/internal_query.go index cac3340cf..23988c335 100644 --- a/serf/internal_query.go +++ b/serf/internal_query.go @@ -151,7 +151,7 @@ func (s *serfQueries) handleConflict(q *Query) { s.serf.memberLock.Unlock() // Encode the response - buf, err := encodeMessage(messageConflictResponseType, out) + buf, err := encodeMessage(messageConflictResponseType, out, s.serf.msgpackUseNewTimeFormat) if err != nil { s.logger.Printf("[ERR] serf: Failed to encode conflict query response: %v", err) return @@ -174,7 +174,7 @@ func (s *serfQueries) keyListResponseWithCorrectSize(q *Query, resp *nodeKeyResp } for i := maxListKeys; i >= 0; i-- { - buf, err := encodeMessage(messageKeyResponseType, resp) + buf, err := encodeMessage(messageKeyResponseType, resp, q.serf.config.MsgpackUseNewTimeFormat) if err != nil { return nil, messageQueryResponse{}, err } @@ -183,7 +183,7 @@ func (s *serfQueries) keyListResponseWithCorrectSize(q *Query, resp *nodeKeyResp qresp := q.createResponse(buf) // Encode response - raw, err := encodeMessage(messageQueryResponseType, qresp) + raw, err := encodeMessage(messageQueryResponseType, qresp, q.serf.msgpackUseNewTimeFormat) if err != nil { return nil, messageQueryResponse{}, err } @@ -217,7 +217,7 @@ func (s *serfQueries) sendKeyResponse(q *Query, resp *nodeKeyResponse) { return } default: - buf, err := encodeMessage(messageKeyResponseType, resp) + buf, err := encodeMessage(messageKeyResponseType, resp, s.serf.msgpackUseNewTimeFormat) if err != nil { s.logger.Printf("[ERR] serf: Failed to encode key response: %v", err) return diff --git a/serf/internal_query_test.go b/serf/internal_query_test.go index 470e9e7f5..e4a7552ae 100644 --- a/serf/internal_query_test.go +++ b/serf/internal_query_test.go @@ -100,12 +100,12 @@ func TestSerfQueries_estimateMaxKeysInListKeyResponseFactor(t *testing.T) { } found := 0 for i := len(resp.Keys); i >= 0; i-- { - buf, err := encodeMessage(messageKeyResponseType, resp) + buf, err := encodeMessage(messageKeyResponseType, resp, q.serf.msgpackUseNewTimeFormat) if err != nil { t.Fatal(err) } qresp := q.createResponse(buf) - raw, err := encodeMessage(messageQueryResponseType, qresp) + raw, err := encodeMessage(messageQueryResponseType, qresp, q.serf.msgpackUseNewTimeFormat) if err != nil { t.Fatal(err) } diff --git a/serf/keymanager.go b/serf/keymanager.go index 5ce8fbf8d..5ea5e8798 100644 --- a/serf/keymanager.go +++ b/serf/keymanager.go @@ -115,7 +115,7 @@ func (k *KeyManager) handleKeyRequest(key, query string, opts *KeyRequestOptions } // Encode the query request - req, err := encodeMessage(messageKeyRequestType, keyRequest{Key: rawKey}) + req, err := encodeMessage(messageKeyRequestType, keyRequest{Key: rawKey}, k.serf.msgpackUseNewTimeFormat) if err != nil { return resp, err } diff --git a/serf/messages.go b/serf/messages.go index 0f2944a66..f7d2cd8a0 100644 --- a/serf/messages.go +++ b/serf/messages.go @@ -8,7 +8,7 @@ import ( "net" "time" - "github.com/hashicorp/go-msgpack/codec" + "github.com/hashicorp/go-msgpack/v2/codec" ) // messageType are the types of gossip messages Serf will send along @@ -131,15 +131,19 @@ func (m *messageQueryResponse) Ack() bool { } func decodeMessage(buf []byte, out interface{}) error { - var handle codec.MsgpackHandle + handle := codec.MsgpackHandle{} return codec.NewDecoder(bytes.NewReader(buf), &handle).Decode(out) } -func encodeMessage(t messageType, msg interface{}) ([]byte, error) { +func encodeMessage(t messageType, msg interface{}, msgpackUseNewTimeFormat bool) ([]byte, error) { buf := bytes.NewBuffer(nil) buf.WriteByte(uint8(t)) - handle := codec.MsgpackHandle{} + handle := codec.MsgpackHandle{ + BasicHandle: codec.BasicHandle{ + TimeNotBuiltin: !msgpackUseNewTimeFormat, + }, + } encoder := codec.NewEncoder(buf, &handle) err := encoder.Encode(msg) return buf.Bytes(), err diff --git a/serf/messages_test.go b/serf/messages_test.go index 18ea0c935..44dff0804 100644 --- a/serf/messages_test.go +++ b/serf/messages_test.go @@ -9,7 +9,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/go-msgpack/codec" + "github.com/hashicorp/go-msgpack/v2/codec" ) func TestQueryFlags(t *testing.T) { @@ -23,7 +23,7 @@ func TestQueryFlags(t *testing.T) { func TestEncodeMessage(t *testing.T) { in := &messageLeave{Node: "foo"} - raw, err := encodeMessage(messageLeaveType, in) + raw, err := encodeMessage(messageLeaveType, in, false) if err != nil { t.Fatalf("err: %v", err) } diff --git a/serf/ping_delegate.go b/serf/ping_delegate.go index 78a34f742..d6ff93ff4 100644 --- a/serf/ping_delegate.go +++ b/serf/ping_delegate.go @@ -8,7 +8,7 @@ import ( "time" "github.com/armon/go-metrics" - "github.com/hashicorp/go-msgpack/codec" + "github.com/hashicorp/go-msgpack/v2/codec" "github.com/hashicorp/memberlist" "github.com/hashicorp/serf/coordinate" ) @@ -37,7 +37,11 @@ func (p *pingDelegate) AckPayload() []byte { buf.Write(version) // The rest of the message is the serialized coordinate. - enc := codec.NewEncoder(&buf, &codec.MsgpackHandle{}) + enc := codec.NewEncoder(&buf, &codec.MsgpackHandle{ + BasicHandle: codec.BasicHandle{ + TimeNotBuiltin: !p.serf.msgpackUseNewTimeFormat, + }, + }) if err := enc.Encode(p.serf.coordClient.GetCoordinate()); err != nil { p.serf.logger.Printf("[ERR] serf: Failed to encode coordinate: %v\n", err) } diff --git a/serf/serf.go b/serf/serf.go index 96f1d0a09..a260c8738 100644 --- a/serf/serf.go +++ b/serf/serf.go @@ -20,7 +20,7 @@ import ( "time" "github.com/armon/go-metrics" - "github.com/hashicorp/go-msgpack/codec" + "github.com/hashicorp/go-msgpack/v2/codec" "github.com/hashicorp/memberlist" "github.com/hashicorp/serf/coordinate" ) @@ -110,7 +110,8 @@ type Serf struct { coordCacheLock sync.RWMutex // metricLabels is the slice of labels to put on all emitted metrics - metricLabels []metrics.Label + metricLabels []metrics.Label + msgpackUseNewTimeFormat bool } // SerfState is the state of the Serf instance. @@ -270,13 +271,14 @@ func Create(conf *Config) (*Serf, error) { } serf := &Serf{ - config: conf, - logger: logger, - members: make(map[string]*memberState), - queryResponse: make(map[LamportTime]*QueryResponse), - shutdownCh: make(chan struct{}), - state: SerfAlive, - metricLabels: conf.MetricLabels, + config: conf, + logger: logger, + members: make(map[string]*memberState), + queryResponse: make(map[LamportTime]*QueryResponse), + shutdownCh: make(chan struct{}), + state: SerfAlive, + metricLabels: conf.MetricLabels, + msgpackUseNewTimeFormat: conf.MsgpackUseNewTimeFormat, } serf.eventJoinIgnore.Store(false) @@ -494,7 +496,7 @@ func (s *Serf) UserEvent(name string, payload []byte, coalesce bool) error { } // Start broadcasting the event - raw, err := encodeMessage(messageUserEventType, &msg) + raw, err := encodeMessage(messageUserEventType, &msg, s.msgpackUseNewTimeFormat) if err != nil { return err } @@ -574,7 +576,7 @@ func (s *Serf) Query(name string, payload []byte, params *QueryParam) (*QueryRes } // Encode the query - raw, err := encodeMessage(messageQueryType, &q) + raw, err := encodeMessage(messageQueryType, &q, s.msgpackUseNewTimeFormat) if err != nil { return nil, err } @@ -913,7 +915,7 @@ func (s *Serf) State() SerfState { // the broadcast. If a notify channel is given, this channel will be closed // when the broadcast is sent. func (s *Serf) broadcast(t messageType, msg interface{}, notify chan<- struct{}) error { - raw, err := encodeMessage(t, msg) + raw, err := encodeMessage(t, msg, s.msgpackUseNewTimeFormat) if err != nil { return err } @@ -1367,7 +1369,7 @@ func (s *Serf) handleQuery(query *messageQuery) bool { From: s.config.NodeName, Flags: queryFlagAck, } - raw, err := encodeMessage(messageQueryResponseType, &ack) + raw, err := encodeMessage(messageQueryResponseType, &ack, s.msgpackUseNewTimeFormat) if err != nil { s.logger.Printf("[ERR] serf: failed to format ack: %v", err) } else { @@ -1531,7 +1533,7 @@ func (s *Serf) resolveNodeConflict() { } } -//eraseNode takes a node completely out of the member list +// eraseNode takes a node completely out of the member list func (s *Serf) eraseNode(m *memberState) { // Delete from members delete(s.members, m.Name) diff --git a/serf/serf_test.go b/serf/serf_test.go index 10c430548..8bc66262f 100644 --- a/serf/serf_test.go +++ b/serf/serf_test.go @@ -21,7 +21,7 @@ import ( "testing" "time" - "github.com/hashicorp/go-msgpack/codec" + "github.com/hashicorp/go-msgpack/v2/codec" "github.com/hashicorp/memberlist" "github.com/hashicorp/serf/coordinate" "github.com/hashicorp/serf/serf/internal/race" diff --git a/testutil/retry/retry.go b/testutil/retry/retry.go index f75940cf3..2914b6ade 100644 --- a/testutil/retry/retry.go +++ b/testutil/retry/retry.go @@ -5,14 +5,13 @@ // // A sample retry operation looks like this: // -// func TestX(t *testing.T) { -// retry.Run(t, func(r *retry.R) { -// if err := foo(); err != nil { -// r.Fatal("f: ", err) -// } -// }) -// } -// +// func TestX(t *testing.T) { +// retry.Run(t, func(r *retry.R) { +// if err := foo(); err != nil { +// r.Fatal("f: ", err) +// } +// }) +// } package retry import (