mirror of https://github.com/status-im/consul.git
Complete logic for sending coordinates
This commit is contained in:
parent
8a0bb40bba
commit
98d87b5dd5
|
@ -38,6 +38,9 @@ const (
|
|||
"but no reason was provided. This is a default message."
|
||||
defaultServiceMaintReason = "Maintenance mode is enabled for this " +
|
||||
"service, but no reason was provided. This is a default message."
|
||||
|
||||
// An interval used to send network coordinates to servers
|
||||
syncCoordinateStaggerIntv = 15 * time.Second
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -557,19 +560,38 @@ func (a *Agent) ResumeSync() {
|
|||
a.state.Resume()
|
||||
}
|
||||
|
||||
// SendCoordinates starts a goroutine that periodically sends the local coordinate
|
||||
// SendCoordinates starts a loop that periodically sends the local coordinate
|
||||
// to a server
|
||||
func (a *Agent) SendCoordinates() {
|
||||
var c coordinate.Coordinate
|
||||
if a.config.Server {
|
||||
c = a.server
|
||||
}
|
||||
req := structs.CoordinateUpdateRequest{
|
||||
NodeSpecificRequest: NodeSpecificRequest{
|
||||
Datacenter: a.config.Datacenter,
|
||||
Node: a.config.NodeName,
|
||||
},
|
||||
QueryOptions: structs.QueryOptions{Token: a.config.ACLToken},
|
||||
func (a *Agent) SendCoordinates(shutdownCh chan struct{}) {
|
||||
for {
|
||||
intv := aeScale(a.config.SyncCoordinateInterval, len(a.LANMembers()))
|
||||
intv = intv + randomStagger(intv)
|
||||
timer := time.After(intv)
|
||||
select {
|
||||
case <-timer:
|
||||
var c coordinate.Coordinate
|
||||
if a.config.Server {
|
||||
c = a.server.GetLANCoordinate()
|
||||
} else {
|
||||
c = a.client.GetCoordinate()
|
||||
}
|
||||
req := structs.CoordinateUpdateRequest{
|
||||
NodeSpecificRequest: NodeSpecificRequest{
|
||||
Datacenter: a.config.Datacenter,
|
||||
Node: a.config.NodeName,
|
||||
},
|
||||
Op: structs.CoordinateSet,
|
||||
Coord: c,
|
||||
QueryOptions: structs.QueryOptions{Token: a.config.ACLToken},
|
||||
}
|
||||
|
||||
var reply struct{}
|
||||
if err := a.RPC("Coordinate.Update", &arg, &reply); err != nil {
|
||||
a.logger.Printf("[ERR] coordinate update error: %s", err.Error())
|
||||
}
|
||||
case <-shutdownCh:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -709,6 +709,9 @@ func (c *Command) Run(args []string) int {
|
|||
errWanCh := make(chan struct{})
|
||||
go c.retryJoinWan(config, errWanCh)
|
||||
|
||||
// Start sending network coordinates to servers
|
||||
go c.agent.SendCoordinates(c.agent.shutdownCh)
|
||||
|
||||
// Wait for exit
|
||||
return c.handleSignals(config, errCh, errWanCh)
|
||||
}
|
||||
|
|
|
@ -372,6 +372,10 @@ type Config struct {
|
|||
// representation of our state. Defaults to every 60s.
|
||||
AEInterval time.Duration `mapstructure:"-" json:"-"`
|
||||
|
||||
// SyncCoordinateInterval controls the interval for sending network coordinates
|
||||
// to servers.
|
||||
SyncCoordinateInterval time.Duration `mapstructure:"-" json:"-"`
|
||||
|
||||
// Checks holds the provided check definitions
|
||||
Checks []*CheckDefinition `mapstructure:"-" json:"-"`
|
||||
|
||||
|
@ -466,6 +470,7 @@ func DefaultConfig() *Config {
|
|||
Protocol: consul.ProtocolVersionMax,
|
||||
CheckUpdateInterval: 5 * time.Minute,
|
||||
AEInterval: time.Minute,
|
||||
SyncCoordinateInterval: 15 * time.Second,
|
||||
ACLTTL: 30 * time.Second,
|
||||
ACLDownPolicy: "extend-cache",
|
||||
ACLDefaultPolicy: "allow",
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/hashicorp/consul/consul/structs"
|
||||
"github.com/hashicorp/serf/coordinate"
|
||||
"github.com/hashicorp/serf/serf"
|
||||
)
|
||||
|
||||
|
@ -376,3 +377,8 @@ func (c *Client) Stats() map[string]map[string]string {
|
|||
}
|
||||
return stats
|
||||
}
|
||||
|
||||
// GetCoordinate returns the network coordinate of the receiver
|
||||
func (c *Client) GetCoordinate() *coordinate.Coordinate {
|
||||
return c.serf.GetCoordinate()
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import (
|
|||
"github.com/hashicorp/consul/tlsutil"
|
||||
"github.com/hashicorp/raft"
|
||||
"github.com/hashicorp/raft-boltdb"
|
||||
"github.com/hashicorp/serf/coordinate"
|
||||
"github.com/hashicorp/serf/serf"
|
||||
)
|
||||
|
||||
|
@ -693,3 +694,8 @@ func (s *Server) Stats() map[string]map[string]string {
|
|||
}
|
||||
return stats
|
||||
}
|
||||
|
||||
// GetLANCoordinate returns the network coordinate of the receiver
|
||||
func (s *Server) GetLANCoordinate() *coordinate.Coordinate {
|
||||
return s.serfLAN.GetCoordinate()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue