Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
set cluster bind address consistently via the same mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
Dieterbe committed Dec 1, 2017
1 parent ae3c5da commit 81eea5f
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 34 deletions.
15 changes: 6 additions & 9 deletions cluster/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ var (
peersStr string
mode string
maxPrio int
clusterPort int
clusterHost net.IP
clusterBindAddr string
httpTimeout time.Duration
minAvailableShards int

swimUseConfig string
swimBindAddrStr string
swimBindAddr *net.TCPAddr
swimTCPTimeout time.Duration
swimIndirectChecks int
swimRetransmitMult int
Expand All @@ -47,7 +46,6 @@ func ConfigSetup() {
clusterCfg := flag.NewFlagSet("cluster", flag.ExitOnError)
clusterCfg.StringVar(&ClusterName, "name", "metrictank", "Unique name of the cluster.")
clusterCfg.BoolVar(&primary, "primary-node", false, "the primary node writes data to cassandra. There should only be 1 primary node per shardGroup.")
clusterCfg.StringVar(&clusterBindAddr, "bind-addr", "0.0.0.0:7946", "TCP Address to listen on for cluster communication")
clusterCfg.StringVar(&peersStr, "peers", "", "TCP addresses of other nodes, comma separated. use this if you shard your data and want to query other instances")
clusterCfg.StringVar(&mode, "mode", "single", "Operating mode of cluster. (single|multi)")
clusterCfg.DurationVar(&httpTimeout, "http-timeout", time.Second*60, "How long to wait before aborting http requests to cluster peers and returning a http 503 service unavailable")
Expand All @@ -57,6 +55,7 @@ func ConfigSetup() {

swimCfg := flag.NewFlagSet("swim", flag.ExitOnError)
swimCfg.StringVar(&swimUseConfig, "use-config", "default-lan", "config setting to use. If set, will override all other swim settings. Use none|default-lan|default-local|default-wan. see https://godoc.org/github.com/hashicorp/memberlist#Config . Note all our swim settings correspond to default-lan")
swimCfg.StringVar(&swimBindAddrStr, "bind-addr", "0.0.0.0:7946", "binding TCP Address for UDP and TCP gossip")
swimCfg.DurationVar(&swimTCPTimeout, "tcp-timeout", 10*time.Second, "timeout for establishing a stream connection with peers for a full state sync, and for stream reads and writes")
swimCfg.IntVar(&swimIndirectChecks, "indirect-checks", 3, "number of nodes that will be asked to perform an indirect probe of a node in the case a direct probe fails")
swimCfg.IntVar(&swimRetransmitMult, "retransmit-mult", 4, "multiplier for number of retransmissions for gossip messages. Retransmits = RetransmitMult * log(N+1)")
Expand All @@ -80,18 +79,16 @@ func ConfigProcess() {
log.Fatal(4, "CLU Config: invalid cluster operating mode")
}

addr, err := net.ResolveTCPAddr("tcp", clusterBindAddr)
var err error
swimBindAddr, err = net.ResolveTCPAddr("tcp", swimBindAddrStr)
if err != nil {
log.Fatal(4, "CLU Config: bind-addr is not a valid TCP address: %s", err.Error())
log.Fatal(4, "CLU Config: swim-bind-addr is not a valid TCP address: %s", err.Error())
}

if httpTimeout == 0 {
log.Fatal(4, "CLU Config: http-timeout must be a non-zero duration string like 60s")
}

clusterHost = addr.IP
clusterPort = addr.Port

Mode = ModeType(mode)

client = http.Client{
Expand Down
7 changes: 3 additions & 4 deletions cluster/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cluster
import (
"crypto/sha256"
"encoding/json"
"net"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -83,6 +82,9 @@ func NewMemberlistManager(thisNode Node) *MemberlistManager {
switch swimUseConfig {
case "none":
mgr.cfg = memberlist.DefaultLANConfig() // use this as base so that the other settings have proper defaults
mgr.cfg.BindPort = swimBindAddr.Port
mgr.cfg.BindAddr = swimBindAddr.IP.String()
mgr.cfg.AdvertisePort = swimBindAddr.Port
mgr.cfg.TCPTimeout = swimTCPTimeout
mgr.cfg.IndirectChecks = swimIndirectChecks
mgr.cfg.RetransmitMult = swimRetransmitMult
Expand All @@ -107,9 +109,6 @@ func NewMemberlistManager(thisNode Node) *MemberlistManager {
default:
panic("invalid swimUseConfig. should already have been validated")
}
mgr.cfg.BindPort = clusterPort
mgr.cfg.BindAddr = clusterHost.String()
mgr.cfg.AdvertisePort = clusterPort
mgr.cfg.Events = mgr
mgr.cfg.Delegate = mgr
h := sha256.New()
Expand Down
6 changes: 3 additions & 3 deletions docker/docker-chaos/metrictank.ini
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ name = metrictank
primary-node = true
# maximum priority before a node should be considered not-ready.
max-priority = 10
# the TCP/UDP address to listen on for the gossip protocol.
bind-addr = 0.0.0.0:7946
# TCP addresses of other nodes, comma separated. use this if you shard your data and want to query other instances.
# If no port is specified, it is assumed the other nodes are using the same port this node is listening on.
peers =
Expand All @@ -210,14 +208,16 @@ http-timeout = 60s
## SWIM clustering settings ##
# only relevant when using cluster mode 'multi'
# for more details, see https://godoc.org/github.com/hashicorp/memberlist#Config
# all values correspond literally to the memberlist.Config options
# all values correspond literally to the memberlist.Config options except where noted
[swim]
# config setting to use. If set, will override all other swim settings. Use none|default-lan|default-local|default-wan. Note all our swim settings correspond to default-lan")
# see:
# * https://godoc.org/github.com/hashicorp/memberlist#DefaultLANConfig
# * https://godoc.org/github.com/hashicorp/memberlist#DefaultLocalConfig
# * https://godoc.org/github.com/hashicorp/memberlist#DefaultWANConfig
use-config = default-lan
# binding TCP Address for UDP and TCP gossip (full ip/dns:port combo unlike memberlist.Config)
bind-addr = 0.0.0.0:7946
# timeout for establishing a stream connection with peers for a full state sync, and for stream reads and writes
tcp-timeout = 10s
# number of nodes that will be asked to perform an indirect probe of a node in the case a direct probe fails
Expand Down
6 changes: 3 additions & 3 deletions docker/docker-cluster/metrictank.ini
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ name = metrictank
primary-node = true
# maximum priority before a node should be considered not-ready.
max-priority = 10
# the TCP/UDP address to listen on for the gossip protocol.
bind-addr = 0.0.0.0:7946
# TCP addresses of other nodes, comma separated. use this if you shard your data and want to query other instances.
# If no port is specified, it is assumed the other nodes are using the same port this node is listening on.
peers =
Expand All @@ -210,14 +208,16 @@ http-timeout = 60s
## SWIM clustering settings ##
# only relevant when using cluster mode 'multi'
# for more details, see https://godoc.org/github.com/hashicorp/memberlist#Config
# all values correspond literally to the memberlist.Config options
# all values correspond literally to the memberlist.Config options except where noted
[swim]
# config setting to use. If set, will override all other swim settings. Use none|default-lan|default-local|default-wan. Note all our swim settings correspond to default-lan")
# see:
# * https://godoc.org/github.com/hashicorp/memberlist#DefaultLANConfig
# * https://godoc.org/github.com/hashicorp/memberlist#DefaultLocalConfig
# * https://godoc.org/github.com/hashicorp/memberlist#DefaultWANConfig
use-config = default-lan
# binding TCP Address for UDP and TCP gossip (full ip/dns:port combo unlike memberlist.Config)
bind-addr = 0.0.0.0:7946
# timeout for establishing a stream connection with peers for a full state sync, and for stream reads and writes
tcp-timeout = 10s
# number of nodes that will be asked to perform an indirect probe of a node in the case a direct probe fails
Expand Down
6 changes: 3 additions & 3 deletions docker/docker-dev-custom-cfg-kafka/metrictank.ini
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ name = metrictank
primary-node = true
# maximum priority before a node should be considered not-ready.
max-priority = 10
# the TCP/UDP address to listen on for the gossip protocol.
bind-addr = 0.0.0.0:7946
# TCP addresses of other nodes, comma separated. use this if you shard your data and want to query other instances.
# If no port is specified, it is assumed the other nodes are using the same port this node is listening on.
peers =
Expand All @@ -210,14 +208,16 @@ http-timeout = 60s
## SWIM clustering settings ##
# only relevant when using cluster mode 'multi'
# for more details, see https://godoc.org/github.com/hashicorp/memberlist#Config
# all values correspond literally to the memberlist.Config options
# all values correspond literally to the memberlist.Config options except where noted
[swim]
# config setting to use. If set, will override all other swim settings. Use none|default-lan|default-local|default-wan. Note all our swim settings correspond to default-lan")
# see:
# * https://godoc.org/github.com/hashicorp/memberlist#DefaultLANConfig
# * https://godoc.org/github.com/hashicorp/memberlist#DefaultLocalConfig
# * https://godoc.org/github.com/hashicorp/memberlist#DefaultWANConfig
use-config = default-lan
# binding TCP Address for UDP and TCP gossip (full ip/dns:port combo unlike memberlist.Config)
bind-addr = 0.0.0.0:7946
# timeout for establishing a stream connection with peers for a full state sync, and for stream reads and writes
tcp-timeout = 10s
# number of nodes that will be asked to perform an indirect probe of a node in the case a direct probe fails
Expand Down
6 changes: 3 additions & 3 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,6 @@ name = metrictank
primary-node = true
# maximum priority before a node should be considered not-ready.
max-priority = 10
# the TCP/UDP address to listen on for the gossip protocol.
bind-addr = 0.0.0.0:7946
# TCP addresses of other nodes, comma separated. use this if you shard your data and want to query other instances.
# If no port is specified, it is assumed the other nodes are using the same port this node is listening on.
peers =
Expand All @@ -262,14 +260,16 @@ http-timeout = 60s
```
# only relevant when using cluster mode 'multi'
# for more details, see https://godoc.org/github.com/hashicorp/memberlist#Config
# all values correspond literally to the memberlist.Config options
# all values correspond literally to the memberlist.Config options except where noted
[swim]
# config setting to use. If set, will override all other swim settings. Use none|default-lan|default-local|default-wan. Note all our swim settings correspond to default-lan")
# see:
# * https://godoc.org/github.com/hashicorp/memberlist#DefaultLANConfig
# * https://godoc.org/github.com/hashicorp/memberlist#DefaultLocalConfig
# * https://godoc.org/github.com/hashicorp/memberlist#DefaultWANConfig
use-config = default-lan
# binding TCP Address for UDP and TCP gossip (full ip/dns:port combo unlike memberlist.Config)
bind-addr = 0.0.0.0:7946
# timeout for establishing a stream connection with peers for a full state sync, and for stream reads and writes
tcp-timeout = 10s
# number of nodes that will be asked to perform an indirect probe of a node in the case a direct probe fails
Expand Down
6 changes: 3 additions & 3 deletions metrictank-sample.ini
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@ name = metrictank
primary-node = true
# maximum priority before a node should be considered not-ready.
max-priority = 10
# the TCP/UDP address to listen on for the gossip protocol.
bind-addr = 0.0.0.0:7946
# TCP addresses of other nodes, comma separated. use this if you shard your data and want to query other instances.
# If no port is specified, it is assumed the other nodes are using the same port this node is listening on.
peers =
Expand All @@ -213,14 +211,16 @@ http-timeout = 60s
## SWIM clustering settings ##
# only relevant when using cluster mode 'multi'
# for more details, see https://godoc.org/github.com/hashicorp/memberlist#Config
# all values correspond literally to the memberlist.Config options
# all values correspond literally to the memberlist.Config options except where noted
[swim]
# config setting to use. If set, will override all other swim settings. Use none|default-lan|default-local|default-wan. Note all our swim settings correspond to default-lan")
# see:
# * https://godoc.org/github.com/hashicorp/memberlist#DefaultLANConfig
# * https://godoc.org/github.com/hashicorp/memberlist#DefaultLocalConfig
# * https://godoc.org/github.com/hashicorp/memberlist#DefaultWANConfig
use-config = default-lan
# binding TCP Address for UDP and TCP gossip (full ip/dns:port combo unlike memberlist.Config)
bind-addr = 0.0.0.0:7946
# timeout for establishing a stream connection with peers for a full state sync, and for stream reads and writes
tcp-timeout = 10s
# number of nodes that will be asked to perform an indirect probe of a node in the case a direct probe fails
Expand Down
6 changes: 3 additions & 3 deletions scripts/config/metrictank-docker.ini
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ name = metrictank
primary-node = true
# maximum priority before a node should be considered not-ready.
max-priority = 10
# the TCP/UDP address to listen on for the gossip protocol.
bind-addr = 0.0.0.0:7946
# TCP addresses of other nodes, comma separated. use this if you shard your data and want to query other instances.
# If no port is specified, it is assumed the other nodes are using the same port this node is listening on.
peers =
Expand All @@ -210,14 +208,16 @@ http-timeout = 60s
## SWIM clustering settings ##
# only relevant when using cluster mode 'multi'
# for more details, see https://godoc.org/github.com/hashicorp/memberlist#Config
# all values correspond literally to the memberlist.Config options
# all values correspond literally to the memberlist.Config options except where noted
[swim]
# config setting to use. If set, will override all other swim settings. Use none|default-lan|default-local|default-wan. Note all our swim settings correspond to default-lan")
# see:
# * https://godoc.org/github.com/hashicorp/memberlist#DefaultLANConfig
# * https://godoc.org/github.com/hashicorp/memberlist#DefaultLocalConfig
# * https://godoc.org/github.com/hashicorp/memberlist#DefaultWANConfig
use-config = default-lan
# binding TCP Address for UDP and TCP gossip (full ip/dns:port combo unlike memberlist.Config)
bind-addr = 0.0.0.0:7946
# timeout for establishing a stream connection with peers for a full state sync, and for stream reads and writes
tcp-timeout = 10s
# number of nodes that will be asked to perform an indirect probe of a node in the case a direct probe fails
Expand Down
6 changes: 3 additions & 3 deletions scripts/config/metrictank-package.ini
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ name = metrictank
primary-node = true
# maximum priority before a node should be considered not-ready.
max-priority = 10
# the TCP/UDP address to listen on for the gossip protocol.
bind-addr = 0.0.0.0:7946
# TCP addresses of other nodes, comma separated. use this if you shard your data and want to query other instances.
# If no port is specified, it is assumed the other nodes are using the same port this node is listening on.
peers =
Expand All @@ -210,14 +208,16 @@ http-timeout = 60s
## SWIM clustering settings ##
# only relevant when using cluster mode 'multi'
# for more details, see https://godoc.org/github.com/hashicorp/memberlist#Config
# all values correspond literally to the memberlist.Config options
# all values correspond literally to the memberlist.Config options except where noted
[swim]
# config setting to use. If set, will override all other swim settings. Use none|default-lan|default-local|default-wan. Note all our swim settings correspond to default-lan")
# see:
# * https://godoc.org/github.com/hashicorp/memberlist#DefaultLANConfig
# * https://godoc.org/github.com/hashicorp/memberlist#DefaultLocalConfig
# * https://godoc.org/github.com/hashicorp/memberlist#DefaultWANConfig
use-config = default-lan
# binding TCP Address for UDP and TCP gossip (full ip/dns:port combo unlike memberlist.Config)
bind-addr = 0.0.0.0:7946
# timeout for establishing a stream connection with peers for a full state sync, and for stream reads and writes
tcp-timeout = 10s
# number of nodes that will be asked to perform an indirect probe of a node in the case a direct probe fails
Expand Down

0 comments on commit 81eea5f

Please sign in to comment.