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
@@ -473,8 +473,9 @@ type TestControllerOpts struct {
|
||||
PublicClusterAddr string
|
||||
|
||||
// The amount of time to wait before marking connections as canceling when a
|
||||
// worker has not reported in
|
||||
WorkerStatusGracePeriodDuration time.Duration
|
||||
// worker has not reported in, and whether a worker is considered to be
|
||||
// routable based on the last time it received a routing info report.
|
||||
WorkerRPCGracePeriod time.Duration
|
||||
|
||||
// The period of time after which it will consider other controllers to be
|
||||
// no longer accessible, based on time since their last status update in the
|
||||
@@ -691,8 +692,8 @@ func TestControllerConfig(t testing.TB, ctx context.Context, tc *TestController,
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if opts.WorkerStatusGracePeriodDuration != 0 {
|
||||
opts.Config.Controller.WorkerStatusGracePeriodDuration = opts.WorkerStatusGracePeriodDuration
|
||||
if opts.WorkerRPCGracePeriod != 0 {
|
||||
opts.Config.Controller.WorkerRPCGracePeriodDuration = opts.WorkerRPCGracePeriod
|
||||
}
|
||||
if opts.LivenessTimeToStaleDuration != 0 {
|
||||
opts.Config.Controller.LivenessTimeToStaleDuration = opts.LivenessTimeToStaleDuration
|
||||
@@ -862,7 +863,7 @@ func (tc *TestController) AddClusterControllerMember(t testing.TB, opts *TestCon
|
||||
DisableAuthMethodCreation: true,
|
||||
DisableAutoStart: opts.DisableAutoStart,
|
||||
PublicClusterAddr: opts.PublicClusterAddr,
|
||||
WorkerStatusGracePeriodDuration: opts.WorkerStatusGracePeriodDuration,
|
||||
WorkerRPCGracePeriod: opts.WorkerRPCGracePeriod,
|
||||
LivenessTimeToStaleDuration: opts.LivenessTimeToStaleDuration,
|
||||
WorkerAuthCaCertificateLifetime: tc.c.conf.TestOverrideWorkerAuthCaCertificateLifetime,
|
||||
WorkerAuthDebuggingEnabled: tc.c.conf.WorkerAuthDebuggingEnabled,
|
||||
@@ -881,53 +882,45 @@ func (tc *TestController) AddClusterControllerMember(t testing.TB, opts *TestCon
|
||||
return NewTestController(t, nextOpts)
|
||||
}
|
||||
|
||||
// WaitForNextWorkerStatusUpdate waits for the next status check from a worker to
|
||||
// come in. If it does not come in within the default status grace
|
||||
// WaitForNextWorkerRoutingInfoUpdate waits for the next routing info RPC from a worker to
|
||||
// come in. If it does not come in within the default worker RPC grace
|
||||
// period, this function returns an error.
|
||||
func (tc *TestController) WaitForNextWorkerStatusUpdate(workerStatusName string) error {
|
||||
const op = "controller.(TestController).WaitForNextWorkerStatusUpdate"
|
||||
ctx := context.TODO()
|
||||
event.WriteSysEvent(ctx, op, "waiting for next status report from worker", "worker", workerStatusName)
|
||||
waitStatusStart := time.Now()
|
||||
ctx, cancel := context.WithTimeout(tc.ctx, time.Duration(tc.c.workerStatusGracePeriod.Load()))
|
||||
func (tc *TestController) WaitForNextWorkerRoutingInfoUpdate(workerName string) error {
|
||||
const op = "controller.(TestController).WaitForNextWorkerRoutingInfoUpdate"
|
||||
waitStart := time.Now()
|
||||
ctx, cancel := context.WithTimeout(tc.ctx, time.Duration(tc.c.workerRPCGracePeriod.Load()))
|
||||
defer cancel()
|
||||
event.WriteSysEvent(ctx, op, "waiting for next routing info from worker", "worker", workerName)
|
||||
var err error
|
||||
for {
|
||||
if err = func() error {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
|
||||
case <-time.After(time.Second):
|
||||
// pass
|
||||
}
|
||||
|
||||
return nil
|
||||
}(); err != nil {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
break
|
||||
case <-time.After(time.Second):
|
||||
// pass
|
||||
}
|
||||
|
||||
var waitStatusCurrent time.Time
|
||||
tc.Controller().WorkerStatusUpdateTimes().Range(func(k, v any) bool {
|
||||
var waitCurrent time.Time
|
||||
tc.Controller().WorkerRoutingInfoUpdateTimes().Range(func(k, v any) bool {
|
||||
if k == nil || v == nil {
|
||||
err = fmt.Errorf("nil key or value on entry: key=%#v value=%#v", k, v)
|
||||
return false
|
||||
}
|
||||
|
||||
workerStatusUpdateId, ok := k.(string)
|
||||
workerUpdateId, ok := k.(string)
|
||||
if !ok {
|
||||
err = fmt.Errorf("unexpected type %T for key: key=%#v value=%#v", k, k, v)
|
||||
return false
|
||||
}
|
||||
|
||||
workerStatusUpdateTime, ok := v.(time.Time)
|
||||
workerUpdateTime, ok := v.(time.Time)
|
||||
if !ok {
|
||||
err = fmt.Errorf("unexpected type %T for value: key=%#v value=%#v", k, k, v)
|
||||
return false
|
||||
}
|
||||
|
||||
if workerStatusUpdateId == workerStatusName {
|
||||
waitStatusCurrent = workerStatusUpdateTime
|
||||
if workerUpdateId == workerName {
|
||||
waitCurrent = workerUpdateTime
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -938,16 +931,16 @@ func (tc *TestController) WaitForNextWorkerStatusUpdate(workerStatusName string)
|
||||
break
|
||||
}
|
||||
|
||||
if waitStatusCurrent.After(waitStatusStart) {
|
||||
if waitCurrent.After(waitStart) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
event.WriteError(ctx, op, err, event.WithInfoMsg("error waiting for next status report from worker", "worker", workerStatusName))
|
||||
event.WriteError(ctx, op, err, event.WithInfoMsg("error waiting for next routing info RPC from worker", "worker", workerName))
|
||||
return err
|
||||
}
|
||||
event.WriteSysEvent(ctx, op, "waiting for next status report from worker received successfully", "worker", workerStatusName)
|
||||
event.WriteSysEvent(ctx, op, "next routing info RPC from worker received successfully", "worker", workerName)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user