Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to msgpack v2 2.1.2 #705

Merged
merged 7 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
27 changes: 20 additions & 7 deletions client/rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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.
dhiaayachi marked this conversation as resolved.
Show resolved Hide resolved
MsgpackUseNewTimeFormat bool
}

// RPCClient is used to make requests to the Agent using an RPC mechanism.
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion cmd/serf/command/agent/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 6 additions & 0 deletions cmd/serf/command/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 30 additions & 21 deletions cmd/serf/command/agent/ipc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion cmd/serf/command/agent/rpc_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/serf/command/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
13 changes: 9 additions & 4 deletions coordinate/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
45 changes: 36 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
Loading
Loading