Skip to content

Commit b5def95

Browse files
committed
Sync WCI compute status to worker deployment version state
Add DescribeWorkerControllerInstanceStatus activity to fetch the WCI validation status and map it to a ComputeStatus. During handleSyncState, invoke syncVersionDataToComputeStatus to update the version state's ComputeStatus with the provider validation result. The sync is gated behind the "sync-compute-validation-status" workflow version for backward compatibility.
1 parent 6412893 commit b5def95

3 files changed

Lines changed: 46 additions & 0 deletions

File tree

service/worker/workerdeployment/version_activities.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"go.temporal.io/sdk/temporal"
2020
deploymentspb "go.temporal.io/server/api/deployment/v1"
2121
"go.temporal.io/server/api/matchingservice/v1"
22+
"go.temporal.io/server/common"
2223
"go.temporal.io/server/common/metrics"
2324
"go.temporal.io/server/common/namespace"
2425
"go.temporal.io/server/common/worker_versioning"
@@ -199,6 +200,19 @@ func (a *VersionActivities) GetVersionDrainageStatus(ctx context.Context, versio
199200
}, nil
200201
}
201202

203+
func (a *VersionActivities) DescribeWorkerControllerInstanceStatus(ctx context.Context, version *deploymentspb.WorkerDeploymentVersion) (*deploymentpb.ComputeStatus, error) {
204+
resp, _, err := a.WorkerControllerInstanceClient.DescribeWorkerControllerInstance(ctx, a.namespace, &deploymentpb.WorkerDeploymentVersion{DeploymentName: version.GetDeploymentName(), BuildId: version.GetBuildId()})
205+
if err != nil {
206+
if common.IsNotFoundError(err) {
207+
return nil, nil
208+
}
209+
210+
return nil, err
211+
}
212+
213+
return wciValidationStatusToComputeStatus(resp.ValidationStatus), nil
214+
}
215+
202216
func (a *VersionActivities) UpdateWorkerControllerInstance(ctx context.Context, input *deploymentspb.UpdateWorkerControllerInstanceInput) (*computepb.ComputeConfigSummary, error) {
203217
upserts := scalingGroupUpdatesToWCI(input.GetUpsertScalingGroups())
204218
resp, err := a.WorkerControllerInstanceClient.UpdateWorkerControllerInstance(ctx, a.namespace, input.GetVersion(), nil, input.GetIdentity(), upserts, input.GetRemoveScalingGroups())

service/worker/workerdeployment/version_workflow.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,12 @@ func (d *VersionWorkflowRunner) run(ctx workflow.Context) error {
345345
}
346346
}
347347

348+
// When creating a compute provider and version together, there is a race condition between the two coming up. Making sure to have pulled
349+
// the latest state from the compute provider if this happens to be the slower one.
350+
if err := d.syncVersionDataToComputeStatus(ctx); err != nil {
351+
return err
352+
}
353+
348354
// Listen to signals in a different goroutine to make business logic clearer
349355
workflow.Go(ctx, d.listenToSignals)
350356

@@ -1244,6 +1250,27 @@ func (d *VersionWorkflowRunner) syncVersionStatusAfterDrainageStatusChange(ctx w
12441250
return d.syncVersionDataToTaskQueues(ctx, versionData)
12451251
}
12461252

1253+
// syncVersionDataToComputeStatus is a helper that syncs the compute status from WCI to the worker deployment version
1254+
func (d *VersionWorkflowRunner) syncVersionDataToComputeStatus(ctx workflow.Context) error {
1255+
if workflow.GetVersion(ctx, "sync-compute-validation-status", workflow.DefaultVersion, 0) == workflow.DefaultVersion {
1256+
return nil
1257+
}
1258+
1259+
state := d.GetVersionState()
1260+
1261+
var result deploymentpb.ComputeStatus
1262+
resp := workflow.ExecuteActivity(workflow.WithActivityOptions(ctx, defaultActivityOptions), d.a.DescribeWorkerControllerInstanceStatus, state.GetVersion())
1263+
if err := resp.Get(ctx, &result); err != nil {
1264+
return err
1265+
}
1266+
if result.ProviderValidation == nil {
1267+
return nil
1268+
}
1269+
1270+
state.ComputeStatus = &result
1271+
return nil
1272+
}
1273+
12471274
// syncVersionDataToTaskQueues is a helper that syncs the provided version data to all task queues.
12481275
// This function does NOT acquire the workflow lock - the caller is responsible for that.
12491276
func (d *VersionWorkflowRunner) syncVersionDataToTaskQueues(ctx workflow.Context, versionData *deploymentspb.DeploymentVersionData) error {

service/worker/workerdeployment/version_workflow_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ func (s *VersionWorkflowSuite) SetupTest() {
5454
}
5555
s.env.RegisterWorkflowWithOptions(versionWorkflow, workflow.RegisterOptions{Name: WorkerDeploymentVersionWorkflowType})
5656

57+
var a *VersionActivities
58+
s.env.OnActivity(a.DescribeWorkerControllerInstanceStatus, mock.Anything, mock.Anything).
59+
Return(&deploymentpb.ComputeStatus{}, nil).
60+
Maybe()
61+
5762
// Initialize an empty ClientImpl to use its helper methods
5863
s.workerDeploymentClient = &ClientImpl{}
5964
}

0 commit comments

Comments
 (0)