Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions common/metrics/metric_defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,8 @@ var (
ForceLoadedTaskQueuePartitions = NewCounterDef("force_loaded_task_queue_partitions_count")
ForceLoadedTaskQueuePartitionUnnecessarilyCounter = NewCounterDef("force_loaded_task_queue_partition_unnecessarily_count")
LoadedPhysicalTaskQueueGauge = NewGaugeDef("loaded_physical_task_queue_count")
PendingPolls = NewGaugeDef("pending_polls")
WorkerCountPerTaskQueue = NewGaugeDef("worker_count")
TaskQueueStartedCounter = NewCounterDef("task_queue_started")
TaskQueueStoppedCounter = NewCounterDef("task_queue_stopped")
TaskWriteThrottlePerTaskQueueCounter = NewCounterDef("task_write_throttle_count")
Expand Down
9 changes: 9 additions & 0 deletions service/matching/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,19 @@ func (tm *TaskMatcher) poll(
defer func() {
if pollMetadata.forwardedFrom == "" {
// Only recording for original polls
var pollResult string
if err == nil {
pollResult = "dispatch"
} else if errors.Is(err, errNoTasks) {
pollResult = "timeout"
} else {
pollResult = "failed"
}
metrics.PollLatencyPerTaskQueue.With(tm.metricsHandler).Record(
time.Since(start),
metrics.StringTag("forwarded", strconv.FormatBool(forwardedPoll)),
metrics.StringTag(metrics.TaskPriorityTagName, ""),
metrics.StringTag("result", pollResult),
)
}

Expand Down
12 changes: 11 additions & 1 deletion service/matching/physical_task_queue_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,11 @@ func (c *physicalTaskQueueManagerImpl) PollTask(
c.liveness.markAlive()

c.currentPolls.Add(1)
defer c.currentPolls.Add(-1)
metrics.PendingPolls.With(c.metricsHandler).Record(float64(c.currentPolls.Load()))
defer func() {
c.currentPolls.Add(-1)
metrics.PendingPolls.With(c.metricsHandler).Record(float64(c.currentPolls.Load()))
}()

namespaceId := namespace.ID(c.queue.NamespaceId())
namespaceEntry, err := c.namespaceRegistry.GetNamespaceByID(namespaceId)
Expand Down Expand Up @@ -596,11 +600,17 @@ func (c *physicalTaskQueueManagerImpl) DispatchNexusTask(

func (c *physicalTaskQueueManagerImpl) UpdatePollerInfo(id pollerIdentity, pollMetadata *pollMetadata) {
c.pollerHistory.updatePollerInfo(id, pollMetadata)
if c.queue.Partition().IsRoot() {
metrics.WorkerCountPerTaskQueue.With(c.metricsHandler).Record(float64(c.pollerHistory.size()))
}
}

func (c *physicalTaskQueueManagerImpl) RemovePoller(id pollerIdentity) {
if c.pollerHistory != nil {
c.pollerHistory.removePoller(id)
if c.queue.Partition().IsRoot() {
metrics.WorkerCountPerTaskQueue.With(c.metricsHandler).Record(float64(c.pollerHistory.size()))
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions service/matching/poller_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ func (pollers *pollerHistory) getPollerInfo(earliestAccessTime time.Time) []*tas
return result
}

func (pollers *pollerHistory) size() int {
return pollers.history.Size()
}

func defaultRPS(wrapper *wrapperspb.DoubleValue) float64 {
if wrapper != nil {
return wrapper.Value
Expand Down
5 changes: 5 additions & 0 deletions service/matching/pri_matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ func (tm *priTaskMatcher) poll(
start := time.Now()
pollWasForwarded := false
var priority int32
pollResult := "failed"

defer func() {
// TODO(pri): can we consolidate all the metrics code below?
Expand All @@ -611,6 +612,7 @@ func (tm *priTaskMatcher) poll(
time.Since(start),
metrics.StringTag("forwarded", strconv.FormatBool(pollWasForwarded)),
metrics.MatchingTaskPriorityTag(priority),
metrics.StringTag("result", pollResult),
)
}
}()
Expand All @@ -631,11 +633,13 @@ func (tm *priTaskMatcher) poll(
}

if res == nil {
pollResult = "timeout"
return nil, errNoTasks // only possible for MatchPollerImmediately
} else if res.ctxErr != nil {
if res.ctxErrIdx == 0 {
metrics.PollTimeoutPerTaskQueueCounter.With(tm.metricsHandler).Record(1)
}
pollResult = "timeout"
return nil, errNoTasks
}

Expand All @@ -646,6 +650,7 @@ func (tm *priTaskMatcher) poll(
task := res.task
pollWasForwarded = task.isStarted() // true if this poll was forwarded _from_ this matcher
priority = task.getPriority().GetPriorityKey()
pollResult = "dispatch"

if !pollWasForwarded {
// Only record these metrics on the parent for forwarded polls
Expand Down
Loading