feat: Report Local Storage State Status

- add `LocalStorageState` to worker status reports
- update worker service handler to process `LocalStorageState`. If is empty for workers older workers, we set the `LocalStorageState` to `unknown`
- update field mask paths to support `LocalStorageState`
This commit is contained in:
Elim Tsiagbey committed 2024-04-05 16:46:06 -04:00
1 parent aea473c77b
commit 8506ed3e2c
8 files changed
+281 -11

No files matched your search

+4 -2
View File
@@ -305,6 +305,8 @@ func (r *Repository) UpsertWorkerStatus(ctx context.Context, worker *Worker, opt
return nil, errors.New(ctx, errors.InvalidParameter, op, "worker keyId and reported name are both empty; one is required")
case worker.OperationalState == "":
return nil, errors.New(ctx, errors.InvalidParameter, op, "worker operational state is empty")
case worker.LocalStorageState == "":
return nil, errors.New(ctx, errors.InvalidParameter, op, "worker local storage state is empty")
}
var workerId string
@@ -349,7 +351,7 @@ func (r *Repository) UpsertWorkerStatus(ctx context.Context, worker *Worker, opt
// KMS-PKI) PKI-based workers to come via API only. We can't
// really guard on this in the DB so we need to be sure to not
// include it here.
n, err := w.Update(ctx, workerClone, []string{"address", "ReleaseVersion", "OperationalState"}, nil)
n, err := w.Update(ctx, workerClone, []string{"address", "ReleaseVersion", "OperationalState", "LocalStorageState"}, nil)
if err != nil {
return errors.Wrap(ctx, err, op, errors.WithMsg("unable to update status of pki worker"))
}
@@ -366,7 +368,7 @@ func (r *Repository) UpsertWorkerStatus(ctx context.Context, worker *Worker, opt
workerClone.Type = KmsWorkerType.String()
workerCreateConflict := &db.OnConflict{
Target: db.Columns{"public_id"},
Action: append(db.SetColumns([]string{"address", "release_version", "operational_state"}),
Action: append(db.SetColumns([]string{"address", "release_version", "operational_state", "local_storage_state"}),
db.SetColumnValues(map[string]any{"last_status_time": "now()"})...),
}
var withRowsAffected int64
+13
View File
@@ -308,6 +308,19 @@ func TestUpsertWorkerStatus(t *testing.T) {
// Version does not change for status updates
assert.Equal(t, uint32(1), worker.Version)
assert.Equal(t, "shutdown", worker.GetOperationalState())
assert.Equal(t, server.UnknownLocalStorageState.String(), worker.GetLocalStorageState())
// update again with available local storage state
wStatus4 := server.NewWorker(scope.Global.String(),
server.WithAddress("new_address"), server.WithName("config_name1"),
server.WithOperationalState("shutdown"), server.WithReleaseVersion("Boundary v0.11.0"),
server.WithLocalStorageState("available"))
worker, err = repo.UpsertWorkerStatus(ctx, wStatus4)
require.NoError(t, err)
assert.Greater(t, worker.GetLastStatusTime().AsTime(), worker.GetCreateTime().AsTime())
// Version does not change for status updates
assert.Equal(t, uint32(1), worker.Version)
assert.Equal(t, server.AvailableLocalStorageState.String(), worker.GetLocalStorageState())
// Should no longer see this worker in listing if we exclude shutdown workers
workers, err = repo.ListWorkers(ctx, []string{scope.Global.String()}, server.WithActiveWorkers(true))