@@ -916,9 +916,10 @@ func newActivityTaskPoller(taskHandler ActivityTaskHandler, service workflowserv
916916}
917917
918918// Poll for a single activity task from the service
919- func (atp * activityTaskPoller ) poll (ctx context.Context ) (* s.PollForActivityTaskResponse , error ) {
919+ func (atp * activityTaskPoller ) poll (ctx context.Context ) (* s.PollForActivityTaskResponse , time. Time , error ) {
920920
921921 atp .metricsScope .Counter (metrics .ActivityPollCounter ).Inc (1 )
922+ startTime := time .Now ()
922923
923924 traceLog (func () {
924925 atp .logger .Debug ("activityTaskPoller::Poll" )
@@ -937,28 +938,27 @@ func (atp *activityTaskPoller) poll(ctx context.Context) (*s.PollForActivityTask
937938 } else {
938939 atp .metricsScope .Counter (metrics .ActivityPollFailedCounter ).Inc (1 )
939940 }
940- return nil , err
941+ return nil , startTime , err
941942 }
942943 if response == nil || len (response .TaskToken ) == 0 {
943944 atp .metricsScope .Counter (metrics .ActivityPollNoTaskCounter ).Inc (1 )
944- return nil , nil
945+ return nil , startTime , nil
945946 }
946947
947- return response , err
948+ return response , startTime , err
948949}
949950
950- type pollFunc func (ctx context.Context ) (* s.PollForActivityTaskResponse , error )
951+ type pollFunc func (ctx context.Context ) (* s.PollForActivityTaskResponse , time. Time , error )
951952
952953func (atp * activityTaskPoller ) pollWithMetricsFunc (
953954 pollFunc pollFunc ) func (ctx context.Context ) (interface {}, error ) {
954955 return func (ctx context.Context ) (interface {}, error ) { return atp .pollWithMetrics (ctx , pollFunc ) }
955956}
956957
957958func (atp * activityTaskPoller ) pollWithMetrics (ctx context.Context ,
958- pollFunc func (ctx context.Context ) (* s.PollForActivityTaskResponse , error )) (interface {}, error ) {
959- startTime := time .Now ()
959+ pollFunc func (ctx context.Context ) (* s.PollForActivityTaskResponse , time.Time , error )) (interface {}, error ) {
960960
961- response , err := pollFunc (ctx )
961+ response , startTime , err := pollFunc (ctx )
962962 if err != nil {
963963 return nil , err
964964 }
@@ -1057,12 +1057,14 @@ func (atp *locallyDispatchedActivityTaskPoller) PollTask() (interface{}, error)
10571057 return activityTask , nil
10581058}
10591059
1060- func (atp * locallyDispatchedActivityTaskPoller ) pollLocallyDispatchedActivity (ctx context.Context ) (* s.PollForActivityTaskResponse , error ) {
1060+ func (atp * locallyDispatchedActivityTaskPoller ) pollLocallyDispatchedActivity (ctx context.Context ) (* s.PollForActivityTaskResponse , time. Time , error ) {
10611061 task := atp .ldaTunnel .getTask ()
10621062 atp .metricsScope .Counter (metrics .LocallyDispatchedActivityPollCounter ).Inc (1 )
1063+ // consider to remove the poll latency metric for local dispatch as unnecessary
1064+ startTime := time .Now ()
10631065 if task == nil {
10641066 atp .metricsScope .Counter (metrics .LocallyDispatchedActivityPollNoTaskCounter ).Inc (1 )
1065- return nil , nil
1067+ return nil , startTime , nil
10661068 }
10671069 // to be backwards compatible, update total poll counter if optimization succeeded only
10681070 atp .metricsScope .Counter (metrics .ActivityPollCounter ).Inc (1 )
@@ -1083,7 +1085,7 @@ func (atp *locallyDispatchedActivityTaskPoller) pollLocallyDispatchedActivity(ct
10831085 response .WorkflowType = task .WorkflowType
10841086 response .WorkflowDomain = task .WorkflowDomain
10851087 response .Attempt = common .Int32Ptr (0 )
1086- return response , nil
1088+ return response , startTime , nil
10871089}
10881090
10891091func reportActivityComplete (ctx context.Context , service workflowserviceclient.Interface , request interface {}, metricsScope tally.Scope ) error {
0 commit comments