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

nsqd: seperate broadcast ports for tcp and http #1297

Merged
merged 1 commit into from
Nov 19, 2020
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
2 changes: 2 additions & 0 deletions apps/nsqd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ func nsqdFlagSet(opts *nsqd.Options) *flag.FlagSet {
authHTTPAddresses := app.StringArray{}
flagSet.Var(&authHTTPAddresses, "auth-http-address", "<addr>:<port> to query auth server (may be given multiple times)")
flagSet.String("broadcast-address", opts.BroadcastAddress, "address that will be registered with lookupd (defaults to the OS hostname)")
flagSet.Int("broadcast-tcp-port", opts.BroadcastTCPPort, "TCP port that will be registered with lookupd (defaults to the TCP port that this nsqd is listening on)")
flagSet.Int("broadcast-http-port", opts.BroadcastHTTPPort, "HTTP port that will be registered with lookupd (defaults to the HTTP port that this nsqd is listening on)")
lookupdTCPAddrs := app.StringArray{}
flagSet.Var(&lookupdTCPAddrs, "lookupd-tcp-address", "lookupd TCP address (may be given multiple times)")
flagSet.Duration("http-client-connect-timeout", opts.HTTPClientConnectTimeout, "timeout for HTTP connect")
Expand Down
4 changes: 2 additions & 2 deletions nsqd/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ func connectCallback(n *NSQD, hostname string) func(*lookupPeer) {
return func(lp *lookupPeer) {
ci := make(map[string]interface{})
ci["version"] = version.Binary
ci["tcp_port"] = n.RealTCPAddr().Port
ci["http_port"] = n.RealHTTPAddr().Port
ci["tcp_port"] = n.getOpts().BroadcastTCPPort
ci["http_port"] = n.getOpts().BroadcastHTTPPort
ci["hostname"] = hostname
ci["broadcast_address"] = n.getOpts().BroadcastAddress

Expand Down
32 changes: 18 additions & 14 deletions nsqd/nsqd.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,6 @@ func New(opts *Options) (*NSQD, error) {
return nil, errors.New("--node-id must be [0,1024)")
}

if opts.StatsdPrefix != "" {
var port string
_, port, err = net.SplitHostPort(opts.HTTPAddress)
if err != nil {
return nil, fmt.Errorf("failed to parse HTTP address (%s) - %s", opts.HTTPAddress, err)
}
statsdHostKey := statsd.HostKey(net.JoinHostPort(opts.BroadcastAddress, port))
prefixWithHost := strings.Replace(opts.StatsdPrefix, "%s", statsdHostKey, -1)
if prefixWithHost[len(prefixWithHost)-1] != '.' {
prefixWithHost += "."
}
opts.StatsdPrefix = prefixWithHost
}

if opts.TLSClientAuthPolicy != "" && opts.TLSRequired == TLSNotRequired {
opts.TLSRequired = TLSRequired
}
Expand Down Expand Up @@ -171,6 +157,24 @@ func New(opts *Options) (*NSQD, error) {
}
}

if opts.BroadcastHTTPPort == 0 {
opts.BroadcastHTTPPort = n.RealHTTPAddr().Port
}

if opts.BroadcastTCPPort == 0 {
opts.BroadcastTCPPort = n.RealTCPAddr().Port
}

if opts.StatsdPrefix != "" {
var port string = fmt.Sprint(opts.BroadcastHTTPPort)
statsdHostKey := statsd.HostKey(net.JoinHostPort(opts.BroadcastAddress, port))
prefixWithHost := strings.Replace(opts.StatsdPrefix, "%s", statsdHostKey, -1)
if prefixWithHost[len(prefixWithHost)-1] != '.' {
prefixWithHost += "."
}
opts.StatsdPrefix = prefixWithHost
}

return n, nil
}

Expand Down
12 changes: 8 additions & 4 deletions nsqd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type Options struct {
HTTPAddress string `flag:"http-address"`
HTTPSAddress string `flag:"https-address"`
BroadcastAddress string `flag:"broadcast-address"`
BroadcastTCPPort int `flag:"broadcast-tcp-port"`
BroadcastHTTPPort int `flag:"broadcast-http-port"`
NSQLookupdTCPAddresses []string `flag:"lookupd-tcp-address" cfg:"nsqlookupd_tcp_addresses"`
AuthHTTPAddresses []string `flag:"auth-http-address" cfg:"auth_http_addresses"`
HTTPClientConnectTimeout time.Duration `flag:"http-client-connect-timeout" cfg:"http_client_connect_timeout"`
Expand Down Expand Up @@ -98,10 +100,12 @@ func NewOptions() *Options {
LogPrefix: "[nsqd] ",
LogLevel: lg.INFO,

TCPAddress: "0.0.0.0:4150",
HTTPAddress: "0.0.0.0:4151",
HTTPSAddress: "0.0.0.0:4152",
BroadcastAddress: hostname,
TCPAddress: "0.0.0.0:4150",
HTTPAddress: "0.0.0.0:4151",
HTTPSAddress: "0.0.0.0:4152",
BroadcastAddress: hostname,
BroadcastTCPPort: 0,
BroadcastHTTPPort: 0,

NSQLookupdTCPAddresses: make([]string, 0),
AuthHTTPAddresses: make([]string, 0),
Expand Down