Worker status refactor (#5417)
* oss: feat(proto): statistics rpc added to server coordination service * oss: feat(session): add update statistics status service * oss: feat(handlers): add Statistics method to worker service server * oss: feat(worker): add statistics ticking * oss: internal/proto: define the new RoutingInfo RPC * oss: internal/server: repository changes for RoutingInfo RPC * oss: internal/daemon: add RoutingInfo handler to worker service The new RoutingInfo RPC is used to get information from the worker that is used to make routing decisions on the controller. It also handles the initial request from the worker. * oss: feat(db): server_worker_session_info table * oss: feat(proto): session info rpc for server coordination service * oss: feat(server): worker session info request data type * oss: feat(worker): session info ticker * oss: feat(handler): server coordination handler for session info * oss: feat(session): utilize session info request time for session cleanup * oss: proto: fix some gotags comments Some of these fields were missing comments, while others had incorrectly formatted comments. * oss: worker: send connection status to server This is required for the correct tracking of orphaned connections * oss: internal/daemon/worker: add function to wait for Statistics RPC * oss: internal/daemon/worker: add routing info RPC The new RoutingInfo RPC replaces part of the Status RPC, namely the part which is used by the controller and worker to perform decisions around the establishment of new sessions and new worker connections. * oss: internal/daemon/worker: remove unnecessary error check * oss: internal/daemon/worker: lock access to config and upstreams The new confLock protects access to the conf value and to the addressReceivers slice. * oss: worker: replace Status RPC with RoutingInfo * oss: worker: deprecate the Status RPC and related types The Status RPC and related messages have been replaced by the RoutingInfo/SessionInfo/Statistics RPCs. The controller will continue to support the Status RPC until two new minor versions have been released. * oss: internal/event: add default deny for new worker RPCs * oss: internal/daemon/worker: allow RPC interval to be set The new SessionInfo/RoutingInfo/Statistics RPCs run at long intervals, which make some of our cluster tests take a long time to complete. This allows their interval to be configured in tests. * oss: all: use TestWorkerRPCInterval in slow tests This should speed up these tests significantly. * oss: internal/tests/cluster: reset sys eventer in test --------- Co-authored-by: Damian Debkowski <damian.debkowski@hashicorp.com>
This commit is contained in:
1 parent
554195f49f
commit
ec0a3f964b
70 files changed
+5492
-1618
No files matched your search
@@ -117,11 +117,11 @@ type Controller struct {
|
||||
clusterListener *base.ServerListener
|
||||
|
||||
// Used for testing and tracking worker health
|
||||
workerStatusUpdateTimes *sync.Map
|
||||
workerRoutingInfoUpdateTimes *sync.Map
|
||||
|
||||
// Timing variables. These are atomics for SIGHUP support, and are int64
|
||||
// because they are casted to time.Duration.
|
||||
workerStatusGracePeriod *atomic.Int64
|
||||
workerRPCGracePeriod *atomic.Int64
|
||||
livenessTimeToStale *atomic.Int64
|
||||
getDownstreamWorkersTimeout *atomic.Int64
|
||||
|
||||
@@ -177,19 +177,19 @@ func New(ctx context.Context, conf *Config) (*Controller, error) {
|
||||
metric.InitializeApiCollectors(conf.PrometheusRegisterer)
|
||||
ratelimit.InitializeMetrics(conf.PrometheusRegisterer)
|
||||
c := &Controller{
|
||||
conf: conf,
|
||||
logger: conf.Logger.Named("controller"),
|
||||
started: ua.NewBool(false),
|
||||
tickerWg: new(sync.WaitGroup),
|
||||
schedulerWg: new(sync.WaitGroup),
|
||||
workerAuthCache: new(sync.Map),
|
||||
workerStatusUpdateTimes: new(sync.Map),
|
||||
enabledPlugins: conf.Server.EnabledPlugins,
|
||||
apiListeners: make([]*base.ServerListener, 0),
|
||||
downstreamConnManager: cluster.NewDownstreamManager(),
|
||||
workerStatusGracePeriod: new(atomic.Int64),
|
||||
livenessTimeToStale: new(atomic.Int64),
|
||||
getDownstreamWorkersTimeout: new(atomic.Int64),
|
||||
conf: conf,
|
||||
logger: conf.Logger.Named("controller"),
|
||||
started: ua.NewBool(false),
|
||||
tickerWg: new(sync.WaitGroup),
|
||||
schedulerWg: new(sync.WaitGroup),
|
||||
workerAuthCache: new(sync.Map),
|
||||
workerRoutingInfoUpdateTimes: new(sync.Map),
|
||||
enabledPlugins: conf.Server.EnabledPlugins,
|
||||
apiListeners: make([]*base.ServerListener, 0),
|
||||
downstreamConnManager: cluster.NewDownstreamManager(),
|
||||
workerRPCGracePeriod: new(atomic.Int64),
|
||||
livenessTimeToStale: new(atomic.Int64),
|
||||
getDownstreamWorkersTimeout: new(atomic.Int64),
|
||||
}
|
||||
|
||||
c.started.Store(false)
|
||||
@@ -223,11 +223,11 @@ func New(ctx context.Context, conf *Config) (*Controller, error) {
|
||||
}
|
||||
}
|
||||
|
||||
switch conf.RawConfig.Controller.WorkerStatusGracePeriodDuration {
|
||||
switch conf.RawConfig.Controller.WorkerRPCGracePeriodDuration {
|
||||
case 0:
|
||||
c.workerStatusGracePeriod.Store(int64(server.DefaultLiveness))
|
||||
c.workerRPCGracePeriod.Store(int64(server.DefaultLiveness))
|
||||
default:
|
||||
c.workerStatusGracePeriod.Store(int64(conf.RawConfig.Controller.WorkerStatusGracePeriodDuration))
|
||||
c.workerRPCGracePeriod.Store(int64(conf.RawConfig.Controller.WorkerRPCGracePeriodDuration))
|
||||
}
|
||||
switch conf.RawConfig.Controller.LivenessTimeToStaleDuration {
|
||||
case 0:
|
||||
@@ -623,7 +623,7 @@ func (c *Controller) registerJobs() error {
|
||||
if err := pluginhost.RegisterJobs(c.baseContext, c.scheduler, rw, rw, c.kms, c.conf.HostPlugins); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := session.RegisterJobs(c.baseContext, c.scheduler, rw, rw, c.kms, c.workerStatusGracePeriod); err != nil {
|
||||
if err := session.RegisterJobs(c.baseContext, c.scheduler, rw, rw, c.kms, c.workerRPCGracePeriod); err != nil {
|
||||
return err
|
||||
}
|
||||
var serverJobOpts []serversjob.Option
|
||||
@@ -633,7 +633,7 @@ func (c *Controller) registerJobs() error {
|
||||
serversjob.WithRotationFrequency(c.conf.TestOverrideWorkerAuthCaCertificateLifetime/2),
|
||||
)
|
||||
}
|
||||
if err := serversjob.RegisterJobs(c.baseContext, c.scheduler, rw, rw, c.kms, c.ControllerExtension, c.workerStatusGracePeriod, serverJobOpts...); err != nil {
|
||||
if err := serversjob.RegisterJobs(c.baseContext, c.scheduler, rw, rw, c.kms, c.ControllerExtension, c.workerRPCGracePeriod, serverJobOpts...); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := kmsjob.RegisterJobs(c.baseContext, c.scheduler, c.kms); err != nil {
|
||||
@@ -675,12 +675,12 @@ func (c *Controller) Shutdown() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// WorkerStatusUpdateTimes returns the map, which specifically is held in _this_
|
||||
// WorkerRoutingInfoUpdateTimes returns the map, which specifically is held in _this_
|
||||
// controller, not the DB. It's used in tests to verify that a given controller
|
||||
// is receiving updates from an expected set of workers, to test out balancing
|
||||
// and auto reconnection.
|
||||
func (c *Controller) WorkerStatusUpdateTimes() *sync.Map {
|
||||
return c.workerStatusUpdateTimes
|
||||
func (c *Controller) WorkerRoutingInfoUpdateTimes() *sync.Map {
|
||||
return c.workerRoutingInfoUpdateTimes
|
||||
}
|
||||
|
||||
// ReloadTimings reloads timing related parameters
|
||||
@@ -694,11 +694,11 @@ func (c *Controller) ReloadTimings(newConfig *config.Config) error {
|
||||
return errors.New(c.baseContext, errors.InvalidParameter, op, "nil config.Controller")
|
||||
}
|
||||
|
||||
switch newConfig.Controller.WorkerStatusGracePeriodDuration {
|
||||
switch newConfig.Controller.WorkerRPCGracePeriodDuration {
|
||||
case 0:
|
||||
c.workerStatusGracePeriod.Store(int64(server.DefaultLiveness))
|
||||
c.workerRPCGracePeriod.Store(int64(server.DefaultLiveness))
|
||||
default:
|
||||
c.workerStatusGracePeriod.Store(int64(newConfig.Controller.WorkerStatusGracePeriodDuration))
|
||||
c.workerRPCGracePeriod.Store(int64(newConfig.Controller.WorkerRPCGracePeriodDuration))
|
||||
}
|
||||
switch newConfig.Controller.LivenessTimeToStaleDuration {
|
||||
case 0:
|
||||
|
||||
Reference in new issue
Block a user