Skip to content

Commit c93e34c

Browse files
committed
Add poll throttle latency metric
1 parent 07a93c0 commit c93e34c

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

common/metrics/defs.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,8 @@ const (
549549
LeaseFailureCounter
550550
ConditionFailedErrorCounter
551551
RespondQueryTaskFailedCounter
552-
ThrottleErrorCounter
552+
PollThrottleLatency
553+
PollThrottleCounter
553554
)
554555

555556
// MetricDefs record the metrics for all services
@@ -626,7 +627,8 @@ var MetricDefs = map[ServiceIdx]map[int]metricDefinition{
626627
LeaseFailureCounter: {metricName: "lease.failures"},
627628
ConditionFailedErrorCounter: {metricName: "condition-failed-errors"},
628629
RespondQueryTaskFailedCounter: {metricName: "respond-query-failed"},
629-
ThrottleErrorCounter: {metricName: "throttle.errors"},
630+
PollThrottleLatency: {metricName: "poll.throttle.latency"},
631+
PollThrottleCounter: {metricName: "poll.throttle.count"},
630632
},
631633
}
632634

service/matching/matchingEngine_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ func (s *matchingEngineSuite) TestSyncMatchActivities() {
526526
if maxDispatch == 0 {
527527
wg.Wait()
528528
s.Error(pollErr)
529-
s.Contains(pollErr.Error(), "ServiceBusyError")
529+
s.Contains(pollErr.Error(), "TaskList dispatch exceeded limit")
530530
time.Sleep(dispatchTTL) // Sleep should be atleast ttl so max Dispatch gets updated
531531
zeroDispatchCt++
532532
continue
@@ -704,7 +704,7 @@ func (s *matchingEngineSuite) concurrentPublishConsumeActivities(
704704
},
705705
})
706706
if err != nil {
707-
s.Contains(err.Error(), "ServiceBusyError")
707+
s.Contains(err.Error(), "TaskList dispatch exceeded limit")
708708
throttleMu.Lock()
709709
throttleCt++
710710
throttleMu.Unlock()

service/matching/taskListManager.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package matching
2222

2323
import (
2424
"context"
25+
"errors"
2526
"fmt"
2627
"sync"
2728
"sync/atomic"
@@ -409,11 +410,14 @@ func (c *taskListManagerImpl) getTask(ctx context.Context) (*getTaskResult, erro
409410
}
410411

411412
// Wait till long poll expiration for token. If token acquired, proceed.
412-
if err := c.rateLimiter.Wait(ctx, c.config.LongPollExpirationInterval); err != nil {
413-
c.metricsClient.IncCounter(scope, metrics.ThrottleErrorCounter)
413+
stopWatch := c.metricsClient.StartTimer(scope, metrics.PollThrottleLatency)
414+
err := c.rateLimiter.Wait(ctx, c.config.LongPollExpirationInterval)
415+
stopWatch.Stop()
416+
if err != nil {
417+
c.metricsClient.IncCounter(scope, metrics.PollThrottleCounter)
414418
msg := fmt.Sprintf("TaskList dispatch exceeded limit: %s", err.Error())
415419
// TODO: It's the client that's busy, not the server. Doesn't fit into any other error.
416-
return nil, createServiceBusyError(msg)
420+
return nil, errors.New(msg)
417421
}
418422
select {
419423
case task, ok := <-c.taskBuffer:

0 commit comments

Comments
 (0)