Worker Domain Refactor (#5338)
* feat(server): Refactor LookupWorkerByName to be a test method * feat(server): Split worker tags table * refact(worker): Export api and config tags * refact(server): Return worker id from UpsertWorkerStatus * refact(server): Create ListWorkerStorageBucketUpdates domain function * refact(server): Use dedicated HCPb-worker list func * refact(server): Create ConnectionRoute domain function * refact(handlers): Move worker selection logic to internal/server package This commit moves all the logic to select a worker to handle a session to the internal/server package. Most functions were moved to this package with no changes, however, there are a couple of notable exceptions: - Given that we don't use GRPC errors in repos, all errors were adjusted to use the internal/errors package instead. - StorageBucketFilterCredIdFn is now used to prevent the internal/server package from importing internal/storage/plugin, which would cause a dep cycle. Callers of SelectSessionWorkers must implement this func which is responsible for returning a storage bucket's worker filter as well as its associated credential id. - authorizeSessionWithWorkerFilter now receives an internal/server.(*Repository) object when called. This is transparent to SelectSessionWorkers callers as it is handled internally. * feat(server): Add FilteredWithFeatures fn and new server options * refact(server): create new list and lookup worker queries * test(server): Add WorkerList unit tests * feat(server): Implement WorkerList randomness using crypto/rand pkg * chore(db): add index to server_worker table * refact(server): prefix test method with Test * refact(server): rename Downstreamers interface to Graph * chore(server): unexport and rename method * chore: add doc string to WorkerAddress (#5420) --------- Co-authored-by: Irena Rindos <irenarindos@users.noreply.github.com> Co-authored-by: irenarindos <irena.rindos@gmail.com>
This commit is contained in:
43 files changed
+2064
-1086
No files matched your search
@@ -27,6 +27,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/credential/vault"
|
||||
"github.com/hashicorp/boundary/internal/daemon/cluster"
|
||||
"github.com/hashicorp/boundary/internal/daemon/controller/common"
|
||||
"github.com/hashicorp/boundary/internal/daemon/controller/downstream"
|
||||
"github.com/hashicorp/boundary/internal/daemon/controller/handlers/health"
|
||||
"github.com/hashicorp/boundary/internal/daemon/controller/internal/metric"
|
||||
"github.com/hashicorp/boundary/internal/db"
|
||||
@@ -89,8 +90,8 @@ type downstreamWorkersTicker interface {
|
||||
var (
|
||||
downstreamReceiverFactory func(*atomic.Int64) (downstreamReceiver, error)
|
||||
|
||||
downstreamersFactory func(context.Context, string, string) (common.Downstreamers, error)
|
||||
downstreamWorkersTickerFactory func(context.Context, string, string, common.Downstreamers, downstreamReceiver, *atomic.Int64) (downstreamWorkersTicker, error)
|
||||
graphFactory func(context.Context, string, string) (downstream.Graph, error)
|
||||
downstreamWorkersTickerFactory func(context.Context, string, string, downstream.Graph, downstreamReceiver, *atomic.Int64) (downstreamWorkersTicker, error)
|
||||
commandClientFactory func(context.Context, *Controller) error
|
||||
extControllerFactory func(ctx context.Context, c *Controller, r db.Reader, w db.Writer, kms *kms.Kms) (intglobals.ControllerExtension, error)
|
||||
)
|
||||
@@ -109,7 +110,7 @@ type Controller struct {
|
||||
workerAuthCache *sync.Map
|
||||
|
||||
// downstream workers and routes to those workers
|
||||
downstreamWorkers common.Downstreamers
|
||||
downstreamWorkers downstream.Graph
|
||||
downstreamConns downstreamReceiver
|
||||
|
||||
apiListeners []*base.ServerListener
|
||||
@@ -494,9 +495,9 @@ func New(ctx context.Context, conf *Config) (*Controller, error) {
|
||||
event.WriteSysEvent(ctx, op, "unable to ensure worker auth roots exist, may be due to multiple controllers starting at once, continuing")
|
||||
}
|
||||
|
||||
if downstreamersFactory != nil {
|
||||
if graphFactory != nil {
|
||||
boundVer := version.Get().VersionNumber()
|
||||
c.downstreamWorkers, err = downstreamersFactory(ctx, "root", boundVer)
|
||||
c.downstreamWorkers, err = graphFactory(ctx, "root", boundVer)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to initialize downstream workers graph: %w", err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user