Skip to content

Commit

Permalink
server: add cluster config
Browse files Browse the repository at this point in the history
  • Loading branch information
andydunstall committed Apr 6, 2024
1 parent c79ab46 commit cc3d668
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
3 changes: 1 addition & 2 deletions cli/agent/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ Heartbeat interval in seconds.
To verify the connection to the server is ok, the listener sends a
heartbeat to the upstream at the '--server.heartbeat-interval-seconds'
interval, with a timeout of '--server.heartbeat-timeout-seconds'.`,

)
cmd.Flags().IntVar(
&conf.Server.HeartbeatTimeoutSeconds,
Expand Down Expand Up @@ -143,7 +142,7 @@ The available levels are 'debug', 'info', 'warn' and 'error'.`,
"log.subsystems",
nil,
`
Each log has a 'subsystem' field where the log occured.
Each log has a 'subsystem' field where the log occured.
'--log.subsystems' enables all log levels for those given subsystems. This
can be useful to debug a particular subsystem without having to enable all
Expand Down
45 changes: 40 additions & 5 deletions cli/server/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,19 @@ func NewCommand() *cobra.Command {
The Pico server is responsible for proxying requests from downstream clients to
registered upstream listeners.
Note Pico does not yet support a cluster of nodes.
Pico may run as a cluster of nodes for fault tolerance and scalability. Use
'--cluster.members' to configure addresses of existing members in the cluster
to join.
Examples:
# Start a pico server on :8080
# Start a Pico server on :8080
pico server
# Start a pico server on :7000.
pico server --server.addr :7000
# Start a Pico server on :7000.
pico server --server.listen-addr :7000
# Start a Pico server and join an existing cluster.
pico server --cluster.members 10.26.104.14,10.26.104.75
`,
}

Expand All @@ -53,8 +58,19 @@ 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.addr :8080' will listen on '0.0.0.0:8080'`,
'--server.listen-addr :8080' will listen on '0.0.0.0:8080'`,
)
cmd.Flags().StringVar(
&conf.Server.GossipAddr,
"server.gossip-addr",
":7000",
`
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().IntVar(
&conf.Server.GracePeriodSeconds,
"server.grace-period-seconds",
Expand All @@ -68,6 +84,25 @@ connections to upstream listeners, announcing to the cluster the node is
leaving...`,
)

cmd.Flags().StringSliceVar(
&conf.Cluster.Members,
"cluster.members",
nil,
`
A list of addresses of members in the cluster to join.
This may be either addresses of specific nodes, such as
'--cluster.members 10.26.104.14,10.26.104.75', or a domain that resolves to
the addresses of the nodes in the cluster (e.g. a Kubernetes headless
service), such as '--cluster.members pico.prod-pico-ns'.
Each address must include the host, and may optionally include a port. If no
port is given, the gossip port of this node is used.
Note each node propagates membership information to the other known nodes,
so the initial set of configured members only needs to be a subset of nodes.`,
)

cmd.Flags().IntVar(
&conf.Proxy.TimeoutSeconds,
"proxy.timeout-seconds",
Expand Down
11 changes: 11 additions & 0 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@ package config
import "fmt"

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

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

// GracePeriodSeconds is the maximum number of seconds to gracefully
// shutdown after receiving a shutdown signal.
GracePeriodSeconds int `json:"grace_period_seconds"`
}

type ClusterConfig struct {
Members []string `json:"members"`
}

func (c *ServerConfig) Validate() error {
if c.ListenAddr == "" {
return fmt.Errorf("missing listen addr")
Expand Down Expand Up @@ -63,6 +73,7 @@ func (c *LogConfig) Validate() error {

type Config struct {
Server ServerConfig `json:"server"`
Cluster ClusterConfig `json:"cluster"`
Proxy ProxyConfig `json:"proxy"`
Upstream UpstreamConfig `json:"upstream"`
Log LogConfig `json:"log"`
Expand Down

0 comments on commit cc3d668

Please sign in to comment.