@@ -281,14 +281,8 @@ func (p *ReplicationTaskProcessorImpl) sendFetchMessageRequest() <-chan *replica
281281func (p * ReplicationTaskProcessorImpl ) processResponse (response * replicationspb.ReplicationMessages ) {
282282
283283 p .syncShardChan <- response .GetSyncShardStatus ()
284- // Note here we check replication tasks instead of hasMore. The expectation is that in a steady state
285- // we will receive replication tasks but hasMore is false (meaning that we are always catching up).
286- // So hasMore might not be a good indicator for additional wait.
287- if len (response .ReplicationTasks ) == 0 {
288- backoffDuration := p .noTaskRetrier .NextBackOff ()
289- time .Sleep (backoffDuration )
290- return
291- }
284+ scope := p .metricsClient .Scope (metrics .ReplicationTaskFetcherScope , metrics .TargetClusterTag (p .sourceCluster ))
285+ batchRequestStartTime := time .Now ()
292286
293287 for _ , replicationTask := range response .ReplicationTasks {
294288 err := p .processSingleTask (replicationTask )
@@ -298,9 +292,18 @@ func (p *ReplicationTaskProcessorImpl) processResponse(response *replicationspb.
298292 }
299293 }
300294
295+ // Note here we check replication tasks instead of hasMore. The expectation is that in a steady state
296+ // we will receive replication tasks but hasMore is false (meaning that we are always catching up).
297+ // So hasMore might not be a good indicator for additional wait.
298+ if len (response .ReplicationTasks ) == 0 {
299+ backoffDuration := p .noTaskRetrier .NextBackOff ()
300+ time .Sleep (backoffDuration )
301+ } else {
302+ scope .RecordTimer (metrics .ReplicationTasksAppliedLatency , time .Now ().Sub (batchRequestStartTime ))
303+ }
304+
301305 p .lastProcessedMessageID = response .GetLastRetrievedMessageId ()
302306 p .lastRetrievedMessageID = response .GetLastRetrievedMessageId ()
303- scope := p .metricsClient .Scope (metrics .ReplicationTaskFetcherScope , metrics .TargetClusterTag (p .sourceCluster ))
304307 scope .UpdateGauge (metrics .LastRetrievedMessageID , float64 (p .lastRetrievedMessageID ))
305308 p .noTaskRetrier .Reset ()
306309}
0 commit comments