Repository navigation
Fix activity operator command metric label collision - #11806
Conversation
|
Claude finished @fretz12's task in 3m 59s —— View job Reviewed 8 files, 4 findings. |
aff4bf5 to
4031d78
Compare
dandavison
left a comment
There was a problem hiding this comment.
Discussed with @fretz12 offline. We're considering making all activity metrics consistent. So activity_{pause,unpause,reset,update_options} would emit once per affected activity when the mutation is applied, rather than once per API request, using the per-activity label schema (matching cancel/terminate etc.) for both SAA and WFA.
|
Claude finished @fretz12's task in 8m 57s —— View job Reviewed 11 files, 4 findings. |
| // ActivityMetricsInfo captures activity metric tags until the mutation commits. | ||
| type ActivityMetricsInfo struct { | ||
| namespaceName string | ||
| taskQueue string | ||
| activityType string | ||
| workflowType string | ||
| versioningBehavior enumspb.VersioningBehavior | ||
| } |
There was a problem hiding this comment.
small — An exported struct, constructor and method carry five strings that only ever become one metrics.Handler; building the handler in the callback removes all three.
The reason the tags are captured inside the update callback and used after it is that activityInfo and mutableState must not be read once the lease is released. metrics.Handler satisfies that just as well as ActivityMetricsInfo — WithTags copies its tag values — so the intermediate type buys nothing. All five call sites already have shardContext and the operation constant in scope at capture time.
Replacing the type with a single function drops ~25 lines from a shared package, one exported type from service/history/workflow, and the []workflow.ActivityMetricsInfo return value threaded through processUnpauseActivityRequest becomes []metrics.Handler.
Suggestion: Replace the type, NewActivityMetricsInfo and MetricsHandler with one function:
// ActivityMetricsHandler returns a handler tagged for the given activity. Callers building it
// during a mutation must do so before the workflow lease is released.
func ActivityMetricsHandler(
shardContext historyi.ShardContext,
mutableState historyi.MutableState,
activityInfo *persistencespb.ActivityInfo,
operation string,
) metrics.Handler {
namespaceName := mutableState.GetNamespaceEntry().Name().String()
taskQueue := activityInfo.GetTaskQueue()
return metrics.GetPerActivityScope(
shardContext.GetMetricsHandler(),
namespaceName,
tqid.UnsafeTaskQueueFamily(namespaceName, taskQueue),
shardContext.GetConfig().BreakdownMetricsByTaskQueue(namespaceName, taskQueue, enumspb.TASK_QUEUE_TYPE_ACTIVITY),
operation,
activityInfo.GetActivityType().GetName(),
mutableState.GetWorkflowType().GetName(),
mutableState.GetEffectiveVersioningBehavior(),
)
}Call sites then collect []metrics.Handler and record with metrics.ActivityPause.With(handler).Record(1).
There was a problem hiding this comment.
Retaining ActivityMetricsInfo intentionally. The mutation callback runs before persistence commits, and constructing the handler there calls Tally WithTags, creating/caching a tagged scope even if persistence later fails. The value object snapshots lease-bound fields while deferring handler construction until after a successful commit. A deferred closure could preserve this behavior, but would make the lifecycle less explicit.
| // ActivityResetScope identifies applied activity reset mutations. | ||
| ActivityResetScope = "ActivityReset" | ||
| // ActivityUpdateOptionsScope tracks UpdateActivityExecutionOptions API calls received by service | ||
| // ActivityUpdateOptionsScope identifies applied activity option mutations. |
There was a problem hiding this comment.
Is there a reason for these comments to use different language from the ActivityTerminatedScope comment?
| WorkflowTypeTag(workflowType), | ||
| ) | ||
| } | ||
|
|
There was a problem hiding this comment.
This is in common/metrics/task_queues.go. Should we create common/metrics/activity.go for it?
There was a problem hiding this comment.
yea i was debating if we should have a new file just for it; you've confirmed
## What changed?
- Changed activity_{pause,unpause,reset,update_options} to emit once per
affected activity when the mutation is applied.
- Updated both WFA and SAA to use the standard per-activity label
schema: namespace, operation, activity type, workflow type, task queue,
versioning behavior, and service name.
- Added shared construction for the standard per-activity metric scope.
- Added functional coverage comparing one WFA request affecting multiple
activities with equivalent SAA per-ID requests.
- Added unit coverage verifying metrics capture the activity’s updated
labels.
## Why?
WFA and SAA emitted the same Prometheus metric names with different
label sets, causing descriptor registration failures and dropped
metrics.
Recording these metrics per affected activity makes their semantics and
labels consistent with other activity event metrics such as cancel,
terminate, success, and failure, while eliminating the Prometheus
collision.
## How did you test it?
- [x] built
- [ ] run locally and tested manually
- [X] covered by existing tests
- [ ] added new unit test(s)
- [X] added new functional test(s)
## Potential risks
WFA metrics change from one recording per API request to one per
affected activity and no longer include activity_targeting_method. This
may increase metric volume for multi-activity requests and require
dashboards using the previous label or request-count semantics to be
updated. This is intentional to establish one consistent per-activity
schema across WFA and SAA.
- Changed activity_{pause,unpause,reset,update_options} to emit once per
affected activity when the mutation is applied.
- Updated both WFA and SAA to use the standard per-activity label
schema: namespace, operation, activity type, workflow type, task queue,
versioning behavior, and service name.
- Added shared construction for the standard per-activity metric scope.
- Added functional coverage comparing one WFA request affecting multiple
activities with equivalent SAA per-ID requests.
- Added unit coverage verifying metrics capture the activity’s updated
labels.
WFA and SAA emitted the same Prometheus metric names with different
label sets, causing descriptor registration failures and dropped
metrics.
Recording these metrics per affected activity makes their semantics and
labels consistent with other activity event metrics such as cancel,
terminate, success, and failure, while eliminating the Prometheus
collision.
- [x] built
- [ ] run locally and tested manually
- [X] covered by existing tests
- [ ] added new unit test(s)
- [X] added new functional test(s)
WFA metrics change from one recording per API request to one per
affected activity and no longer include activity_targeting_method. This
may increase metric volume for multi-activity requests and require
dashboards using the previous label or request-count semantics to be
updated. This is intentional to establish one consistent per-activity
schema across WFA and SAA.
(cherry picked from commit 935fdf5)
## What changed? Backports the 12 merged PRs labeled [release/1.32.0](https://github.com/temporalio/temporal/issues?q=repo%3Atemporalio%2Ftemporal+is%3Apr+label%3Arelease%2F1.32.0) that were not yet on `release/v1.32.x`, applied in `main` merge order. Also fixes mixedbrain test by bumping go version to 1.26.8 in mixedbrain folder (broken by #11928). | # | PR | Author | What / Why | |---|----|--------|------------| | 1 | [#11546](#11546) fix(batcher): scope deterministic request IDs to the batch job ID | @spkane31 | Two batch operations sending the same signal to the same workflow/run ID only delivered one — the request ID was hashed from workflow ID / run ID / signal name, so the second was de-duped in signal logic. Including the batch job ID in the hash keeps separate signals distinct. | | 2 | [#11642](#11642) Fix batch operations targeting paused executions | @fretz12 | A paused execution is still non-terminal, but the old `Running`-only filter silently skipped paused targets. Users issuing a batch terminate/signal/cancel reasonably expect it to apply to them. | | 3 | [#11666](#11666) Fix activity timeout regeneration after unpause | @fretz12 | Timeout tasks that fired while an activity was paused were discarded, but the activity's timer-task status still claimed they existed — preventing recreation after unpause and potentially making the timeout ineffective. Also fixes `ResetActivity` bypassing normal unpause handling, and running activities returning early without clearing paused state. | | 4 | [#11696](#11696) Treat missing Worker Deployment Version as deleted | @rkannan82 | Treats `NotFound` from the Version workflow delete update as success. When a Version workflow is already closed or its history is gone, `NotFound` blocked the Deployment workflow from removing its stale version reference. Fixes #11539. | | 5 | [#11725](#11725) Fix batch activity unpause visibility query scope | @fretz12 | The server replaced the caller's visibility query with the activity-type predicate, which could broaden the batch scope and unpause activities in workflows the caller never selected. | | 6 | [#11806](#11806) Fix activity operator command metric label collision | @fretz12 | WFA and SAA emitted the same Prometheus metric names (`activity_pause`/`unpause`/`reset`/`update_options`) with **different label sets**, causing descriptor registration failures and dropped metrics. Both now use the standard per-activity label schema and emit once per affected activity. **See "Backport adaptation" below.** | | 7 | [#11930](#11930) Prioritize worker versioning workflows | @ShahabT | Worker versioning workflows share the per-namespace worker task queue with other system workflows. Raising their initial workflow-task priority above default keeps versioning operations from queueing behind default-priority work. | | 8 | [#11910](#11910) [Visibility] Fix legacy visibility query converter | @rodrigozhou | Fixes to the legacy visibility query converter for both SQL and Elasticsearch. | | 9 | [#11699](#11699) dynamic partitioning: use probability of AddTask to root partition to estimate overall add task rate | @carlydf | A previous PR changed AddTask load-balancing from uniform random to backlog-aware, invalidating the uniform-distribution assumption behind the add-task-rate estimate. Now estimates from the probability of AddTask hitting the root partition, and guarantees the root retains at least a 1% chance of selection regardless of its backlog. | | 10 | [#11935](#11935) [Visibility] Enable unified query converter by default | @rodrigozhou | Flips the default now that the unified query converter is stable and ready to replace the old one. Depends on #11910 and #11801. | ## How did you test it? - [x] built — `go build ./...` - [x] `make fmt` — no changes - [x] `go vet -tags disable_grpc_modules,test_dep ./tests/...` — clean - [x] `make GOLANGCI_LINT_FIX=false GOLANGCI_LINT_BASE_REV=origin/release/v1.32.x lint-code` — **0 issues** - [x] covered by existing tests — 21 affected packages, **20 pass** --------- Co-authored-by: Sean Kane <[email protected]> Co-authored-by: Fred Tzeng <[email protected]> Co-authored-by: Kannan <[email protected]> Co-authored-by: Shahab Tajik <[email protected]> Co-authored-by: Rodrigo Zhou <[email protected]> Co-authored-by: Carly de Frondeville <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Vladyslav Simonenko <[email protected]>
What changed?
Why?
WFA and SAA emitted the same Prometheus metric names with different label sets, causing descriptor registration failures and dropped metrics.
Recording these metrics per affected activity makes their semantics and labels consistent with other activity event metrics such as cancel, terminate, success, and failure, while eliminating the Prometheus collision.
How did you test it?
Potential risks
WFA metrics change from one recording per API request to one per affected activity and no longer include activity_targeting_method. This may increase metric volume for multi-activity requests and require dashboards using the previous label or request-count semantics to be updated. This is intentional to establish one consistent per-activity schema across WFA and SAA.