Add version labels to missing deployment metric (#11799)

## What changed

- Add Worker Deployment name and build ID labels to
`worker_deployment_version_not_found_during_delete`.
- Assert both label values in the existing activity test.

## Why

The counter diagnoses stale Deployment workflow references, so it needs
to identify the exact missing Worker Deployment Version.

## Testing

- `GOWORK=off go test -tags test_dep ./service/worker/workerdeployment
-run '^TestDeleteWorkerDeploymentVersion$' -count=1`\n- `GOWORK=off go
vet -tags disable_grpc_modules,test_dep
./service/worker/workerdeployment`

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> Observability-only changes to metric tags and log fields on an
already-handled NotFound path; no change to deletion behavior.
> 
> **Overview**
> When deleting a worker deployment version hits a **NotFound** from
history (stale version workflow), the
**`worker_deployment_version_not_found_during_delete`** counter now
records **worker deployment name** and **build ID** tags, in addition to
namespace, so dashboards can pinpoint which version was missing.
> 
> The same path updates the warning log to use **`versionObj`** for
deployment name and build ID, **`namespace.Info().GetName()`** for
namespace, and **`args.GetRequestId()`** for the request ID. The
activity test now asserts the new metric tag values.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
8776d7fd78. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
This commit is contained in:
Shivam
2026-08-26 15:37:44 -04:00
committed by GitHub
parent 539790267f
commit a4a452c003
2 changed files with 11 additions and 5 deletions

View File

@@ -182,15 +182,17 @@ func (a *Activities) DeleteWorkerDeploymentVersion(ctx context.Context, args *de
if errors.As(err, &notFoundErr) {
metrics.WorkerDeploymentVersionNotFoundDuringDelete.With(a.MetricsHandler).Record(
1,
metrics.NamespaceTag(a.namespace.Name().String()),
metrics.NamespaceTag(a.namespace.Info().GetName()),
metrics.WorkerDeploymentNameTag(versionObj.GetDeploymentName(), true),
metrics.WorkerDeploymentBuildIDTag(versionObj.GetBuildId(), true),
)
activity.GetLogger(ctx).Warn(
"version workflow not found during deletion; allowing deployment workflow to remove stale reference",
"namespace", a.namespace.Name().String(),
"deploymentName", args.DeploymentName,
"version", args.Version,
"namespace", a.namespace.Info().GetName(),
"deploymentName", versionObj.GetDeploymentName(),
"version", versionObj.GetBuildId(),
"versionWorkflowID", workflowID,
"requestID", args.RequestId,
"requestID", args.GetRequestId(),
"error", err,
)
return nil

View File

@@ -78,6 +78,10 @@ func TestDeleteWorkerDeploymentVersion(t *testing.T) {
require.Equal(t, int64(1), recordings[0].Value)
namespaceTag := metrics.NamespaceTag(tv.NamespaceName().String())
require.Equal(t, namespaceTag.Value, recordings[0].Tags[namespaceTag.Key])
deploymentTag := metrics.WorkerDeploymentNameTag(tv.DeploymentSeries(), true)
require.Equal(t, deploymentTag.Value, recordings[0].Tags[deploymentTag.Key])
buildIDTag := metrics.WorkerDeploymentBuildIDTag(tv.BuildID(), true)
require.Equal(t, buildIDTag.Value, recordings[0].Tags[buildIDTag.Key])
}
})
}