Files
tasks/service/worker/workerdeployment/compute_util.go
Shahab TajikandGitHub 37e7c4dd5d Add compute config to WorkerDeploymentVersionSummary (#9838)
## What changed?
- Add compute config summary for latest and all other version so it is
exposed in `ListWorkerDeployments` and `DescribeWorkerDeployment` APIs.

## Why?
Mainly for UI to show compute provider types.

## How did you test it?
- [x] built
- [ ] run locally and tested manually
- [x] covered by existing tests
- [ ] added new unit test(s)
- [ ] added new functional test(s)

## Potential risks
None
2026-04-08 22:22:08 +00:00

106 lines
3.6 KiB
Go

package workerdeployment
import (
computepb "go.temporal.io/api/compute/v1"
wciiface "go.temporal.io/auto-scaled-workers/wci/workflow/iface"
"go.temporal.io/sdk/workflow"
)
func computeConfigScalingGroupsToWCISpec(scalingGroups map[string]*computepb.ComputeConfigScalingGroup) *wciiface.WorkerControllerInstanceSpec {
specs := make(map[string]wciiface.ScalingGroupSpec, len(scalingGroups))
for name, sg := range scalingGroups {
groupSpec := wciiface.ScalingGroupSpec{
TaskTypes: sg.GetTaskQueueTypes(),
Compute: wciiface.ComputeProviderSpec{
ProviderType: wciiface.ComputeProviderType(sg.GetProvider().GetType()),
},
}
if scaler := sg.GetScaler(); scaler != nil {
groupSpec.Scaling = &wciiface.ScalingAlgorithmSpec{
ScalingAlgorithm: wciiface.ScalingAlgorithmType(scaler.GetType()),
}
}
specs[name] = groupSpec
}
return &wciiface.WorkerControllerInstanceSpec{
ScalingGroupSpecs: specs,
}
}
func scalingGroupUpdatesToWCI(updates map[string]*computepb.ComputeConfigScalingGroupUpdate) map[string]wciiface.ScalingGroupSpecUpdate {
result := make(map[string]wciiface.ScalingGroupSpecUpdate, len(updates))
for name, update := range updates {
sg := update.GetScalingGroup()
spec := wciiface.ScalingGroupSpec{
TaskTypes: sg.GetTaskQueueTypes(),
Compute: wciiface.ComputeProviderSpec{
ProviderType: wciiface.ComputeProviderType(sg.GetProvider().GetType()),
Config: sg.GetProvider().GetDetails(),
},
}
if scaler := sg.GetScaler(); scaler != nil {
spec.Scaling = &wciiface.ScalingAlgorithmSpec{
ScalingAlgorithm: wciiface.ScalingAlgorithmType(scaler.GetType()),
Config: scaler.GetDetails(),
}
}
result[name] = wciiface.ScalingGroupSpecUpdate{
Spec: spec,
UpdateMask: update.GetUpdateMask().GetPaths(),
}
}
return result
}
func wciSpecToComputeConfig(spec *wciiface.WorkerControllerInstanceSpec) *computepb.ComputeConfig {
if spec == nil || len(spec.ScalingGroupSpecs) == 0 {
return nil
}
groups := make(map[string]*computepb.ComputeConfigScalingGroup, len(spec.ScalingGroupSpecs))
for name, sg := range spec.ScalingGroupSpecs {
group := &computepb.ComputeConfigScalingGroup{
TaskQueueTypes: sg.TaskTypes,
Provider: &computepb.ComputeProvider{
Type: string(sg.Compute.ProviderType),
Details: sg.Compute.Config,
},
}
if sg.Scaling != nil {
group.Scaler = &computepb.ComputeScaler{
Type: string(sg.Scaling.ScalingAlgorithm),
Details: sg.Scaling.Config,
}
}
groups[name] = group
}
return &computepb.ComputeConfig{ScalingGroups: groups}
}
func wciSpecToComputeConfigSummary(spec *wciiface.WorkerControllerInstanceSpec) *computepb.ComputeConfigSummary {
if spec == nil || len(spec.ScalingGroupSpecs) == 0 {
return nil
}
groups := make(map[string]*computepb.ComputeConfigScalingGroupSummary, len(spec.ScalingGroupSpecs))
names := workflow.DeterministicKeys(spec.ScalingGroupSpecs)
for _, name := range names {
sg := spec.ScalingGroupSpecs[name]
groups[name] = &computepb.ComputeConfigScalingGroupSummary{
TaskQueueTypes: sg.TaskTypes,
ProviderType: string(sg.Compute.ProviderType),
}
}
return &computepb.ComputeConfigSummary{ScalingGroups: groups}
}
func scalingGroupsToUpsertUpdates(scalingGroups map[string]*computepb.ComputeConfigScalingGroup) map[string]*computepb.ComputeConfigScalingGroupUpdate {
updates := make(map[string]*computepb.ComputeConfigScalingGroupUpdate, len(scalingGroups))
names := workflow.DeterministicKeys(scalingGroups)
for _, name := range names {
sg := scalingGroups[name]
updates[name] = &computepb.ComputeConfigScalingGroupUpdate{
ScalingGroup: sg,
}
}
return updates
}