@@ -108,7 +108,7 @@ func (s *workflowSuite) Test_NormalFlowShouldRescheduleActivity_UpdatesWorkflowE
108108 request := s .newRespondActivityTaskFailedRequest (uc )
109109 s .setupStubs (uc )
110110
111- s .expectTimerMetricsRecorded (uc , s .shardContext )
111+ s .expectRetryMetricsRecorded (uc , s .shardContext )
112112 s .workflowContext .EXPECT ().UpdateWorkflowExecutionAsActive (ctx , s .shardContext ).Return (nil )
113113
114114 _ , err := Invoke (ctx , request , s .shardContext , s .workflowConsistencyChecker )
@@ -246,7 +246,7 @@ func (s *workflowSuite) Test_LastHeartBeatDetailsExist_UpdatesMutableState() {
246246 Namespace : request .FailedRequest .GetNamespace (),
247247 })
248248
249- s .expectTimerMetricsRecorded (uc , s .shardContext )
249+ s .expectRetryMetricsRecorded (uc , s .shardContext )
250250
251251 _ , err := Invoke (
252252 ctx ,
@@ -294,7 +294,7 @@ func (s *workflowSuite) Test_NoMoreRetriesAndMutableStateHasNoPendingTasks_WillR
294294 })
295295 s .setupStubs (uc )
296296 request := s .newRespondActivityTaskFailedRequest (uc )
297- s .expectTimerMetricsRecorded (uc , s .shardContext )
297+ s .expectTerminalFailureMetricsRecorded (uc , s .shardContext )
298298 s .currentMutableState .EXPECT ().AddActivityTaskFailedEvent (
299299 uc .scheduledEventId ,
300300 uc .startedEventId ,
@@ -436,8 +436,9 @@ func (s *workflowSuite) setupShardContext(registry namespace.Registry) *historyi
436436 return shardContext
437437}
438438
439- func (s * workflowSuite ) expectTimerMetricsRecorded (uc UsecaseConfig , shardContext * historyi.MockShardContext ) {
439+ func (s * workflowSuite ) expectRetryMetricsRecorded (uc UsecaseConfig , shardContext * historyi.MockShardContext ) {
440440 timer := metrics .NewMockTimerIface (s .controller )
441+ counter := metrics .NewMockCounterIface (s .controller )
441442 tags := []metrics.Tag {
442443 metrics .OperationTag (metrics .HistoryRespondActivityTaskFailedScope ),
443444 metrics .WorkflowTypeTag (uc .wfType .Name ),
@@ -446,12 +447,39 @@ func (s *workflowSuite) expectTimerMetricsRecorded(uc UsecaseConfig, shardContex
446447 metrics .UnsafeTaskQueueTag (uc .taskQueueId ),
447448 }
448449
449- timer .EXPECT ().Record (
450- gomock .Any (),
451- )
452450 metricsHandler := metrics .NewMockHandler (s .controller )
453451 metricsHandler .EXPECT ().WithTags (tags ).Return (metricsHandler )
452+
453+ timer .EXPECT ().Record (gomock .Any ()).Times (2 ) // ActivityE2ELatency and ActivityAttemptDuration
454+ metricsHandler .EXPECT ().Timer (metrics .ActivityE2ELatency .Name ()).Return (timer )
455+ metricsHandler .EXPECT ().Timer (metrics .ActivityAttemptDuration .Name ()).Return (timer )
456+ // ActivityE2EDuration is NOT recorded for retries
457+ counter .EXPECT ().Record (int64 (1 ))
458+ metricsHandler .EXPECT ().Counter (metrics .ActivityRetryCount .Name ()).Return (counter )
459+
460+ shardContext .EXPECT ().GetMetricsHandler ().Return (metricsHandler ).AnyTimes ()
461+ }
462+
463+ func (s * workflowSuite ) expectTerminalFailureMetricsRecorded (uc UsecaseConfig , shardContext * historyi.MockShardContext ) {
464+ timer := metrics .NewMockTimerIface (s .controller )
465+ counter := metrics .NewMockCounterIface (s .controller )
466+ tags := []metrics.Tag {
467+ metrics .OperationTag (metrics .HistoryRespondActivityTaskFailedScope ),
468+ metrics .WorkflowTypeTag (uc .wfType .Name ),
469+ metrics .ActivityTypeTag (uc .activityType ),
470+ metrics .NamespaceTag (uc .namespaceName .String ()),
471+ metrics .UnsafeTaskQueueTag (uc .taskQueueId ),
472+ }
473+
474+ metricsHandler := metrics .NewMockHandler (s .controller )
475+ metricsHandler .EXPECT ().WithTags (tags ).Return (metricsHandler )
476+
477+ timer .EXPECT ().Record (gomock .Any ()).Times (3 ) // ActivityE2ELatency, ActivityAttemptDuration, and ActivityE2EDuration
454478 metricsHandler .EXPECT ().Timer (metrics .ActivityE2ELatency .Name ()).Return (timer )
479+ metricsHandler .EXPECT ().Timer (metrics .ActivityAttemptDuration .Name ()).Return (timer )
480+ metricsHandler .EXPECT ().Timer (metrics .ActivityE2EDuration .Name ()).Return (timer ) // Recorded for terminal failures
481+ counter .EXPECT ().Record (int64 (1 ))
482+ metricsHandler .EXPECT ().Counter (metrics .ActivityFailedCount .Name ()).Return (counter )
455483
456484 shardContext .EXPECT ().GetMetricsHandler ().Return (metricsHandler ).AnyTimes ()
457485}
0 commit comments