From ab3eb7f5282c411cced866c50d29856bd6bb0a81 Mon Sep 17 00:00:00 2001 From: Andrew Dunstall Date: Sat, 6 Apr 2024 16:03:18 +0100 Subject: [PATCH] server: add advertise http and gossip addr --- cli/server/command.go | 30 ++++++++++++++++++++++++++---- server/config/config.go | 23 ++++++++++++++++++++--- 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/cli/server/command.go b/cli/server/command.go index 503764f4..4686ef13 100644 --- a/cli/server/command.go +++ b/cli/server/command.go @@ -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, @@ -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, @@ -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, diff --git a/server/config/config.go b/server/config/config.go index 5cc02c36..463d48f9 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -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"` @@ -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 }