Skip to content

Commit

Permalink
server: add advertise http and gossip addr
Browse files Browse the repository at this point in the history
  • Loading branch information
andydunstall committed Apr 6, 2024
1 parent 23bf992 commit ab3eb7f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
30 changes: 26 additions & 4 deletions cli/server/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,26 @@ Examples:
var conf config.Config

cmd.Flags().StringVar(
&conf.Server.ListenAddr,
"server.listen-addr",
&conf.Server.HTTPAddr,
"server.http-addr",
":8080",
`
The host/port to listen on for incoming HTTP and WebSocket connections from
both downstream clients and upstream listeners.
If the host is unspecified it defaults to all listeners, such as
'--server.listen-addr :8080' will listen on '0.0.0.0:8080'`,
'--server.http-addr :8080' will listen on '0.0.0.0:8080'`,
)
cmd.Flags().StringVar(
&conf.Server.AdvertiseHTTPAddr,
"server.advertise-http-addr",
"127.0.0.1:8080",
`
HTTP listen address to advertise to other nodes in the cluster. This is the
address other nodes will used to send requests to the node.
Such as if the listen address is ':8080', the advertised address may be
'10.26.104.45:8080' or 'node1.cluster:8080'.`,
)
cmd.Flags().StringVar(
&conf.Server.GossipAddr,
Expand All @@ -67,6 +78,17 @@ The host/port to listen for inter-node gossip traffic.
If the host is unspecified it defaults to all listeners, such as
'--server.gossip-addr :7000' will listen on '0.0.0.0:7000'`,
)
cmd.Flags().StringVar(
&conf.Server.AdvertiseGossipAddr,
"server.advertise-gossip-addr",
"127.0.0.1:7000",
`
Gossip listen address to advertise to other nodes in the cluster. This is the
address other nodes will used to gossip with the.
Such as if the listen address is ':7000', the advertised address may be
'10.26.104.45:7000' or 'node1.cluster:7000'.`,
)

cmd.Flags().IntVar(
&conf.Server.GracePeriodSeconds,
Expand Down Expand Up @@ -193,7 +215,7 @@ func run(conf *config.Config, logger *log.Logger) {

registry := prometheus.NewRegistry()
server := server.NewServer(
conf.Server.ListenAddr,
conf.Server.HTTPAddr,
registry,
conf,
logger,
Expand Down
23 changes: 20 additions & 3 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ package config
import "fmt"

type ServerConfig struct {
// ListenAddr is the address to listen for incoming HTTP and WebSocket
// HTTPAddr is the address to listen for incoming HTTP and WebSocket
// connections.
ListenAddr string `json:"listen_addr"`
HTTPAddr string `json:"http_addr"`

// AdvertiseHTTPAddr is the HTTP address to advertise to other nodes
// in the cluster.
AdvertiseHTTPAddr string `json:"advertise_http_addr"`

// GossipAddr is the address to listen for incoming UDP gossip messages.
GossipAddr string `json:"gossip_addr"`

// AdvertiseGossipAddr is the gossip address to advertise to other nodes in
// the cluster.
AdvertiseGossipAddr string `json:"advertise_gossip_addr"`

// GracePeriodSeconds is the maximum number of seconds to gracefully
// shutdown after receiving a shutdown signal.
GracePeriodSeconds int `json:"grace_period_seconds"`
Expand All @@ -22,9 +30,18 @@ type ClusterConfig struct {
}

func (c *ServerConfig) Validate() error {
if c.ListenAddr == "" {
if c.HTTPAddr == "" {
return fmt.Errorf("missing listen addr")
}
if c.AdvertiseHTTPAddr == "" {
return fmt.Errorf("missing advertise listen addr")
}
if c.GossipAddr == "" {
return fmt.Errorf("missing gossip addr")
}
if c.AdvertiseGossipAddr == "" {
return fmt.Errorf("missing advertise gossip addr")
}
return nil
}

Expand Down

0 comments on commit ab3eb7f

Please sign in to comment.