Skip to content

Add task_latency_processing_no_persistence metric and context counter#9367

Merged
awln-temporal merged 4 commits intomainfrom
task-processing-latency-no-persistence
Mar 12, 2026
Merged

Add task_latency_processing_no_persistence metric and context counter#9367
awln-temporal merged 4 commits intomainfrom
task-processing-latency-no-persistence

Conversation

@awln-temporal
Copy link
Copy Markdown
Contributor

@awln-temporal awln-temporal commented Feb 19, 2026

What changed?

Add task_processing_no_persistence_latency metric and context counter. Allows any task to emit this metric as long as TaskPersistenceLatency Counter is incremented.

This metric is emitted by Executable MetricsHandler, which adds namespace, operation, taskType, serviceName as Metric Tags.

In this change, only Visibility tasks publish task_processing_no_persistence_latency.

Why?

Separate Visibility task latency from persistence, and allow any other task to emit this metric in the future.

How did you test it?

  • built
  • run locally and tested manually
  • covered by existing tests
  • added new unit test(s)
  • added new functional test(s)

@awln-temporal awln-temporal requested review from a team as code owners February 19, 2026 22:57
@awln-temporal awln-temporal force-pushed the task-processing-latency-no-persistence branch from 0c551c8 to b4999cb Compare February 20, 2026 02:36
@rodrigozhou rodrigozhou requested a review from yycptt February 20, 2026 17:07
Comment on lines +815 to +823
// TaskPersistenceLatency is used only as a context key for accumulating persistence duration (ContextCounterAdd/Get); not emitted as a metric.
TaskPersistenceLatency = NewTimerDef(
"task_persistence_latency",
WithDescription("Context key for persistence duration; not emitted."),
)
TaskProcessingLatencyNoPersistence = NewTimerDef(
"task_latency_processing_no_persistence",
WithDescription("Latency for processing a history task one time excluding persistence."),
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need both? typically no_xxx_latency is good enough for monitoring and alerting purpose.
and xxx_latency can be estimated from latency - no_xxx_latency.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the first is not an actual metric, just a context key to track the persistence latency timer. In the actual metric calculation, we only publish TaskProcessingLatencyNoPersistence. Similar to how we calculate Task processing without UserAttemptLatency, we just track a timer specific for UserAttemptLatency in order to calculate task_processing_no_user_latency etc.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can rename the metric if we would like to no_persistency_latency as well

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I didn't realize we are already using this approach in other places. Thanks for the context!

I don't really have an opinion on the naming, either no_xxx_latency, or latency_no_xxx works for me. Maybe follow what we have for other metrics.

@rodrigozhou rodrigozhou requested a review from yycptt February 24, 2026 17:54
// emit total attempt latency so that we know how much time a task will occpy a worker goroutine
metrics.TaskProcessingLatency.With(e.metricsHandler).Record(attemptLatency)

if persistenceDuration, ok := metrics.ContextCounterGet(ctx, metrics.TaskPersistenceLatency.Name()); ok {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ContextCounterGet will return 0,true even if the key is not present:

return result, true

I think this is an issue in ContextCounterGet(). We should change that to return true only if that key is present.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! yeah with the issue we will have this metric for all other task types as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed, thanks for checking this

@awln-temporal awln-temporal merged commit 7d3956b into main Mar 12, 2026
70 checks passed
@awln-temporal awln-temporal deleted the task-processing-latency-no-persistence branch March 12, 2026 16:58
stephanos pushed a commit that referenced this pull request Mar 12, 2026
…#9367)

## What changed?
Add `task_processing_no_persistence_latency` metric and context counter.
Allows any task to emit this metric as long as TaskPersistenceLatency
Counter is incremented.

This metric is emitted by Executable MetricsHandler, which adds
`namespace`, `operation`, `taskType`, `serviceName` as Metric Tags.

In this change, only Visibility tasks publish
`task_processing_no_persistence_latency`.

## Why?
Separate Visibility task latency from persistence, and allow any other
task to emit this metric in the future.

## How did you test it?
- [X] built
- [X] run locally and tested manually
- [X] covered by existing tests
- [X] added new unit test(s)
- [ ] added new functional test(s)
birme pushed a commit to eyevinn-osaas/temporal that referenced this pull request Mar 23, 2026
…temporalio#9367)

## What changed?
Add `task_processing_no_persistence_latency` metric and context counter.
Allows any task to emit this metric as long as TaskPersistenceLatency
Counter is incremented.

This metric is emitted by Executable MetricsHandler, which adds
`namespace`, `operation`, `taskType`, `serviceName` as Metric Tags.

In this change, only Visibility tasks publish
`task_processing_no_persistence_latency`.

## Why?
Separate Visibility task latency from persistence, and allow any other
task to emit this metric in the future.

## How did you test it?
- [X] built
- [X] run locally and tested manually
- [X] covered by existing tests
- [X] added new unit test(s)
- [ ] added new functional test(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants