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:
Johan Brandhorst-SatzkornandDamian Debkowski authored and GitHub committed 2025-01-09 10:26:37 -08:00
1 parent 554195f49f
commit ec0a3f964b
70 files changed
+5492 -1618

No files matched your search

@@ -13,10 +13,29 @@ service ServerCoordinationService {
// Status gets worker status requests which include the ongoing jobs the worker is handling and
// returns the status response which includes the changes the controller would like to make to
// jobs as well as provide a list of the controllers in the system.
rpc Status(StatusRequest) returns (StatusResponse) {}
// This RPC is deprecated and is safe to remove after the release of Boundary v0.20.0.
rpc Status(StatusRequest) returns (StatusResponse) {
option deprecated = true;
}
// Returns the addresses of HCP Boundary workers, if any
rpc ListHcpbWorkers(ListHcpbWorkersRequest) returns (ListHcpbWorkersResponse) {}
// Statistics is used by the worker to report non-essential statistics about its sessions and connections.
rpc Statistics(StatisticsRequest) returns (StatisticsResponse) {}
// RoutingInfo is used by the worker to inform the controller of information
// required by the controller to make session routing decisions and any startup information.
// The controller may inform the worker of any downstream workers that should be disconnected.
// If the worker fails to successfully report its routing info to the controller,
// it will try again later.
rpc RoutingInfo(RoutingInfoRequest) returns (RoutingInfoResponse) {}
// SessionInfo is used by the worker to inform the controller of all the sessions
// it is managing. The controller may inform the worker if any sessions need to be changed.
// If the worker repeatedly fails to successfully report its session info to the controller,
// it will tear down any running sessions.
rpc SessionInfo(SessionInfoRequest) returns (SessionInfoResponse) {}
}
enum CONNECTIONSTATUS {
@@ -41,31 +60,41 @@ enum SESSIONSTATUS {
SESSIONSTATUS_TERMINATED = 4;
}
// This message is deprecated and is safe to remove after the release of Boundary v0.20.0.
message SessionJobInfo {
option deprecated = true;
string session_id = 1; // @gotags: `class:"public" eventstream:"observation"`
SESSIONSTATUS status = 2;
repeated Connection connections = 3;
SessionProcessingError processing_error = 4; // @gotags: `class:"public"`
}
// This enum is deprecated and is safe to remove after the release of Boundary v0.20.0.
enum SessionProcessingError {
option deprecated = true;
SESSION_PROCESSING_ERROR_UNSPECIFIED = 0;
SESSION_PROCESSING_ERROR_UNRECOGNIZED = 1;
}
// This message is deprecated and is safe to remove after the release of Boundary v0.20.0.
message MonitorSessionJobInfo {
option deprecated = true;
string session_id = 1; // @gotags: `class:"public" eventstream:"observation"`
SESSIONSTATUS status = 2; // @gotags: `class:"public"`
SessionProcessingError processing_error = 3; // @gotags: `class:"public"`
}
// This enum is deprecated and is safe to remove after the release of Boundary v0.20.0.
enum JOBTYPE {
option deprecated = true;
JOBTYPE_UNSPECIFIED = 0;
JOBTYPE_SESSION = 1;
JOBTYPE_MONITOR_SESSION = 2;
}
// This message is deprecated and is safe to remove after the release of Boundary v0.20.0.
message Job {
option deprecated = true;
JOBTYPE type = 1;
oneof job_info {
// This value is specified when type is JOBTYPE_SESSION.
@@ -74,13 +103,17 @@ message Job {
}
}
// This message is deprecated and is safe to remove after the release of Boundary v0.20.0.
message JobStatus {
option deprecated = true;
Job job = 1;
}
// UpstreamServer returns the controller address in the StatusResponse but may be used in the future to return
// worker address.
// This message is deprecated and is safe to remove after the release of Boundary v0.20.0.
message UpstreamServer {
option deprecated = true;
enum TYPE {
TYPE_UNSPECIFIED = 0;
TYPE_CONTROLLER = 1;
@@ -94,9 +127,11 @@ message UpstreamServer {
string address = 20; // @gotags: `class:"public"`
}
// This message is deprecated and is safe to remove after the release of Boundary v0.20.0.
message StatusRequest {
reserved 10;
reserved "worker";
option deprecated = true;
reserved 10, 50;
reserved "worker", "connected_worker_key_identifiers";
// Jobs which this worker wants to report the status.
repeated JobStatus jobs = 20;
@@ -113,12 +148,6 @@ message StatusRequest {
// get access to the key and spoof the connection, you're already compromised.
servers.v1.ServerWorkerStatus worker_status = 40;
// The worker key identifiers presented by all downstreams connected to this
// worker.
// Deprecated. Should be removed in 0.15.0 at which time
// connected_unmapped_worker_key_identifiers should be used exclusively.
repeated string connected_worker_key_identifiers = 50 [deprecated = true];
// The worker key identifiers for downstream workers for which there
// is not a known worker id mapping for them yet.
repeated string connected_unmapped_worker_key_identifiers = 51;
@@ -130,36 +159,36 @@ message StatusRequest {
repeated string connected_worker_public_ids = 55;
}
// This message is deprecated and is safe to remove after the release of Boundary v0.20.0.
enum CHANGETYPE {
option deprecated = true;
CHANGETYPE_UNSPECIFIED = 0;
// Indicates to the worker to update its knowledge of the state, which may
// cause action to be taken.
CHANGETYPE_UPDATE_STATE = 1;
}
// This message is deprecated and is safe to remove after the release of Boundary v0.20.0.
message JobChangeRequest {
option deprecated = true;
Job job = 1;
CHANGETYPE request_type = 2;
}
message AuthorizedWorkerList {
option deprecated = true;
// the key id of authorized workers
repeated string worker_key_identifiers = 1 [deprecated = true];
}
message AuthorizedDownstreamWorkerList {
// the key id of authorized workers which do not have a worker id known yet
// to the requester.
repeated string unmapped_worker_key_identifiers = 1;
repeated string unmapped_worker_key_identifiers = 1; // @gotags: class:"public" eventstream:"observation"
// the public id of workers that were reported as being connected and which
// are known by the controller.
repeated string worker_public_ids = 2;
repeated string worker_public_ids = 2; // @gotags: class:"public" eventstream:"observation"
}
// This message is deprecated and is safe to remove after the release of Boundary v0.20.0.
message StatusResponse {
reserved 10;
reserved "controllers";
option deprecated = true;
reserved 10, 50;
reserved "controllers", "authorized_workers";
// List of jobs and the expected state changes. For example, this will
// include jobs witch change type of canceled for jobs which are active on a
@@ -175,12 +204,6 @@ message StatusResponse {
// controller does not need to do a database lookup for the id using the name field.
string worker_id = 40; // @gotags: `class:"public" eventstream:"observation"`
// Of the worker key identifiers provided in the request, these are the ones
// which are authorized to remain connected.
// This is deprecated. Use authorized_downstream_workers instead. This
// should be removed in version 0.15.0.
AuthorizedWorkerList authorized_workers = 50 [deprecated = true];
// Of the downstream workers in the request, these are the ones
// which are authorized to remain connected.
AuthorizedDownstreamWorkerList authorized_downstream_workers = 51;
@@ -202,3 +225,99 @@ message ListHcpbWorkersRequest {}
message ListHcpbWorkersResponse {
repeated WorkerInfo workers = 1;
}
// SessionStatistics contains statistics about a session and its connections.
message SessionStatistics {
// Session ID holds the ID of the session which the statistics belong to.
string session_id = 1; // @gotags: class:"public" eventstream:"observation"
// Connections contains statistics about all the existing connections for the given session.
repeated Connection connections = 2;
}
// StatisticsRequest contains a worker statistics request. This request
// reports on information that is not important either to maintain existing
// sessions or create new ones.
message StatisticsRequest {
// The ID of the worker making the request.
string worker_id = 10; // @gotags: class:"public" eventstream:"observation"
// The statistics of the sessions managed by this worker
repeated SessionStatistics sessions = 20;
}
// StatisticsResponse contains a controller statistics response. Empty for now.
message StatisticsResponse {}
// RoutingIinfoRequest is the request message for the RoutingInfo RPC.
message RoutingInfoRequest {
// The worker status of the worker making the request.
servers.v1.ServerWorkerStatus worker_status = 1;
// Whether the tags should be updated or not.
bool update_tags = 2; // @gotags: class:"public" eventstream:"observation"
// The worker key identifiers for downstream workers for which there
// is not a known worker id.
repeated string connected_unmapped_worker_key_identifiers = 3; // @gotags: class:"public" eventstream:"observation"
// The worker public ids of all downstreams connected to this worker.
repeated string connected_worker_public_ids = 4; // @gotags: class:"public" eventstream:"observation"
}
// RoutingInfoResponse is the response message for the RoutingInfo RPC.
message RoutingInfoResponse {
// The controller-assigned ID of the worker which made the request.
string worker_id = 1; // @gotags: class:"public" eventstream:"observation"
// The calculated upstream addresses for the controller cluster.
repeated string calculated_upstream_addresses = 2; // @gotags: class:"public" eventstream:"observation"
// Of the downstream workers in the request, these are the ones
// which are authorized to remain connected.
AuthorizedDownstreamWorkerList authorized_downstream_workers = 3;
}
// Session type represents how the worker is processing a session.
enum SessionType {
SESSION_TYPE_UNSPECIFIED = 0;
// A session where the worker is the ingress worker.
SESSION_TYPE_INGRESSED = 1;
// A session where the worker is doing the recording of the session.
SESSION_TYPE_RECORDED = 2;
}
// Session contains information about a worker managed session
message Session {
// The ID of the session.
string session_id = 1; // @gotags: class:"public" eventstream:"observation"
// The status of the session.
SESSIONSTATUS session_status = 2; // @gotags: class:"public" eventstream:"observation"
// Represents how the worker is processing the session.
SessionType session_type = 3; // @gotags: class:"public" eventstream:"observation"
// Connections contains information about the connections managed by the session
repeated Connection connections = 4;
}
// SessionInfoRequest contains a worker session information request. This request
// reports on currently managed sessions on the worker. This includes all ingressed
// and recorded sessions.
message SessionInfoRequest {
// The ID of the worker making the request.
string worker_id = 1; // @gotags: class:"public" eventstream:"observation"
// The sessions which this worker wants to report the status of.
// Includes both ingressed sessions and recorded sessions.
repeated Session sessions = 2;
}
// SessionInfoResponse contains a controller session information response. This
// response indicates what, if any, changes should be made to the sessions.
// This also includes any sessions the worker is monitoring but not managing directly.
message SessionInfoResponse {
// List of sessions that are no longer active and whose status should be updated.
repeated Session non_active_sessions = 1;
}
@@ -17,22 +17,22 @@ message TagPair {
// ServerWorkerStatus is the new message used in place of Server to relay status request info.
message ServerWorkerStatus {
// Id of the worker.
// Id of the worker, used after the first request.
string public_id = 10; // @gotags: `class:"public" eventstream:"observation"`
// Name of the resource (optional)
// Name of the worker, used to identify workers in the KMS registration flow.
string name = 20; // @gotags: `class:"public"`
// Description of the resource (optional)
// Description of the worker (optional). Only used by KMS workers.
string description = 25; // @gotags: `class:"public"`
// Address for the worker. This must be set.
// Address for the worker.
string address = 30; // @gotags: `class:"public"`
// Tags for workers
repeated TagPair tags = 40;
// The key id for this worker, if applicable (optional)
// The key id of the worker, used to identify workers in the PKI registration flow.
string key_id = 50; // @gotags: `class:"public"`
// The version of Boundary the worker binary is running
@@ -159,3 +159,14 @@ message WorkerStorageBucketCredentialState {
// @inject_tag: `gorm:"not_null"`
timestamp.v1.Timestamp checked_at = 60;
}
// WorkerSessionInfoRequest contains information about a worker and its SessionInfo requests.
message WorkerSessionInfoRequest {
// worker_id is the public id of the worker.
// @inject_tag: `gorm:"primary_key"`
string worker_id = 10;
// The last_request_time is the last time a worker has reported its session information.
// @inject_tag: `gorm:"default:null"`
timestamp.v1.Timestamp last_request_time = 20;
}