Skip to content

Commit

Permalink
Add shard id to queue processor related metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
taylanisikdemir committed Dec 28, 2023
1 parent d663ce7 commit 4ccb876
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
3 changes: 2 additions & 1 deletion service/history/queue/processor_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package queue
import (
"context"
"fmt"
"strconv"
"sync"
"time"

Expand Down Expand Up @@ -94,7 +95,7 @@ func newProcessorBase(
logger log.Logger,
metricsClient metrics.Client,
) *processorBase {
metricsScope := metricsClient.Scope(options.MetricScope)
metricsScope := metricsClient.Scope(options.MetricScope).Tagged(metrics.ShardIDTag(strconv.Itoa(shard.GetShardID())))
return &processorBase{
shard: shard,
taskProcessor: taskProcessor,
Expand Down
8 changes: 6 additions & 2 deletions service/history/queue/timer_queue_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package queue
import (
"context"
"fmt"
"strconv"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -425,12 +426,15 @@ func (t *timerQueueProcessor) completeTimer() error {
}

newAckLevelTimestamp := newAckLevel.(timerTaskKey).visibilityTimestamp
t.logger.Debugf("Start completing timer task from: %v, to %v", t.ackLevel, newAckLevelTimestamp)
if !t.ackLevel.Before(newAckLevelTimestamp) {
t.logger.Debugf("Skipping timer task completion because new ack level %v is not before ack level %v", newAckLevelTimestamp, t.ackLevel)
return nil
}

t.metricsClient.IncCounter(metrics.TimerQueueProcessorScope, metrics.TaskBatchCompleteCounter)
t.logger.Debugf("Start completing timer task from: %v, to %v", t.ackLevel, newAckLevelTimestamp)
t.metricsClient.Scope(metrics.TimerQueueProcessorScope).
Tagged(metrics.ShardIDTag(strconv.Itoa(t.shard.GetShardID()))).
IncCounter(metrics.TaskBatchCompleteCounter)

for {
pageSize := t.config.TimerTaskDeleteBatchSize()
Expand Down
4 changes: 3 additions & 1 deletion service/history/queue/timer_queue_processor_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"fmt"
"math"
"math/rand"
"strconv"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -542,6 +543,7 @@ func (t *timerQueueProcessorBase) notifyNewTimers(timerTasks []persistence.Task)

isActive := t.options.MetricScope == metrics.TimerActiveQueueProcessorScope
minNewTime := timerTasks[0].GetVisibilityTimestamp()
shardIDTag := metrics.ShardIDTag(strconv.Itoa(t.shard.GetShardID()))
for _, timerTask := range timerTasks {
ts := timerTask.GetVisibilityTimestamp()
if ts.Before(minNewTime) {
Expand All @@ -552,7 +554,7 @@ func (t *timerQueueProcessorBase) notifyNewTimers(timerTasks []persistence.Task)
timerTask.GetType(),
isActive,
)
t.metricsClient.IncCounter(taskScopeIdx, metrics.NewTimerCounter)
t.metricsClient.Scope(taskScopeIdx).Tagged(shardIDTag).IncCounter(metrics.NewTimerNotifyCounter)
}

t.notifyNewTimer(minNewTime)
Expand Down
5 changes: 4 additions & 1 deletion service/history/queue/transfer_queue_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"errors"
"fmt"
"math"
"strconv"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -423,7 +424,9 @@ func (t *transferQueueProcessor) completeTransfer() error {
return nil
}

t.metricsClient.IncCounter(metrics.TransferQueueProcessorScope, metrics.TaskBatchCompleteCounter)
t.metricsClient.Scope(metrics.TransferQueueProcessorScope).
Tagged(metrics.ShardIDTag(strconv.Itoa(t.shard.GetShardID()))).
IncCounter(metrics.TaskBatchCompleteCounter)

for {
pageSize := t.config.TransferTaskDeleteBatchSize()
Expand Down
3 changes: 1 addition & 2 deletions service/history/queue/transfer_queue_processor_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ const (

var (
loadQueueTaskThrottleRetryDelay = 5 * time.Second

persistenceOperationRetryPolicy = common.CreatePersistenceRetryPolicy()
)

Expand Down Expand Up @@ -145,7 +144,7 @@ func newTransferQueueProcessorBase(
transferQueueProcessorBase,
options.ValidationInterval,
logger,
metricsClient.Scope(options.MetricScope),
processorBase.metricsScope,
)
}

Expand Down
9 changes: 4 additions & 5 deletions service/history/queue/transfer_queue_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,10 @@ func newTransferQueueValidator(
) *transferQueueValidator {
timeSource := processor.shard.GetTimeSource()
return &transferQueueValidator{
processor: processor,
timeSource: timeSource,
logger: logger,
metricsScope: metricsScope,

processor: processor,
timeSource: timeSource,
logger: logger,
metricsScope: metricsScope,
pendingTaskInfos: make(map[int64]pendingTaskInfo),
maxReadLevels: make(map[int]task.Key),
minReadTaskID: 0,
Expand Down

0 comments on commit 4ccb876

Please sign in to comment.