Skip to content

Commit

Permalink
Only record activity_succeed_endtoend_latency on success (#1481)
Browse files Browse the repository at this point in the history
  • Loading branch information
Quinn-With-Two-Ns authored May 21, 2024
1 parent aa17647 commit 725b428
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
8 changes: 5 additions & 3 deletions internal/internal_task_pollers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1023,9 +1023,11 @@ func (atp *activityTaskPoller) ProcessTask(task interface{}) error {
return reportErr
}

activityMetricsHandler.
Timer(metrics.ActivitySucceedEndToEndLatency).
Record(time.Since(activityTask.task.GetScheduledTime().AsTime()))
if _, ok := request.(*workflowservice.RespondActivityTaskCompletedRequest); ok {
activityMetricsHandler.
Timer(metrics.ActivitySucceedEndToEndLatency).
Record(time.Since(activityTask.task.GetScheduledTime().AsTime()))
}
return nil
}

Expand Down
33 changes: 33 additions & 0 deletions test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1825,6 +1825,39 @@ func (ts *IntegrationTestSuite) TestEndToEndLatencyMetrics() {
ts.Equal(prevNonLocalValue, nonLocal.Value())
}

func (ts *IntegrationTestSuite) TestEndToEndLatencyOnFailureMetrics() {
fetchMetrics := func() (localMetric, nonLocalMetric *metrics.CapturedTimer) {
for _, timer := range ts.metricsHandler.Timers() {
timer := timer
if timer.Name == "temporal_activity_succeed_endtoend_latency" {
nonLocalMetric = timer
} else if timer.Name == "temporal_local_activity_succeed_endtoend_latency" {
localMetric = timer
}
}
return
}

// Confirm no metrics to start
local, nonLocal := fetchMetrics()
ts.Nil(local)
ts.Nil(nonLocal)

// Run regular activity and confirm non-local metric is not emitted
err := ts.executeWorkflow("test-end-to-end-metrics-on-failure-1", ts.workflows.ActivityRetryOnError, nil)
ts.NoError(err)
local, nonLocal = fetchMetrics()
ts.Nil(local)
ts.Nil(nonLocal)

// Run local activity and confirm local metric is not emitted
err = ts.executeWorkflow("test-end-to-end-metrics-on-failure-2", ts.workflows.ActivityRetryOnError, nil)
ts.NoError(err)
local, nonLocal = fetchMetrics()
ts.Nil(local)
ts.Nil(nonLocal)
}

func (ts *IntegrationTestSuite) TestGracefulActivityCompletion() {
// FYI, setup of this test allows the worker to wait to stop for 10 seconds
ctx, cancel := context.WithCancel(context.Background())
Expand Down

0 comments on commit 725b428

Please sign in to comment.