Files
tasks/common/metrics/task_queues.go
zeekay 5a601d081b rebrand: go.temporal.io/server -> github.com/hanzoai/tasks
Full module path rebrand from Temporal to Hanzo Tasks:
- go.mod module: github.com/hanzoai/tasks
- All internal Go imports updated (1906 files)
- cmd/server renamed to cmd/tasksd
- Binary name: tasksd (was temporal-server)
- Docker images: hanzoai/tasks (was temporalio/server)
- README rewritten with Hanzo Tasks branding
- LLM.md created with integration notes
- Makefile, goreleaser, CI workflows updated
- go.temporal.io/sdk and go.temporal.io/api imports preserved (separate repos)

Fork of Temporal.io (MIT license).
2026-03-19 10:36:40 -07:00

93 lines
2.5 KiB
Go

package metrics
import (
"strconv"
"github.com/hanzoai/tasks/common/tqid"
)
const (
omitted = "__omitted__"
normal = "__normal__"
sticky = "__sticky__"
)
// GetPerTaskQueueFamilyScope returns "namespace" and "taskqueue" tags. "taskqueue" will be "__omitted__" if
// taskQueueBreakdown is false.
func GetPerTaskQueueFamilyScope(
handler Handler,
namespaceName string,
taskQueueFamily *tqid.TaskQueueFamily,
taskQueueBreakdown bool,
tags ...Tag,
) Handler {
metricTaskQueueName := omitted
if taskQueueBreakdown {
metricTaskQueueName = taskQueueFamily.Name()
}
tags = append(tags, NamespaceTag(namespaceName), UnsafeTaskQueueTag(metricTaskQueueName))
return handler.WithTags(tags...)
}
// GetPerTaskQueueScope returns GetPerTaskQueueFamilyScope plus the "task_type" tag.
func GetPerTaskQueueScope(
handler Handler,
namespaceName string,
taskQueue *tqid.TaskQueue,
taskQueueBreakdown bool,
tags ...Tag,
) Handler {
return GetPerTaskQueueFamilyScope(handler, namespaceName, taskQueue.Family(), taskQueueBreakdown,
append(tags, TaskQueueTypeTag(taskQueue.TaskType()))...)
}
// GetPerTaskQueuePartitionIDScope is similar to GetPerTaskQueuePartitionTypeScope, except that the partition tag will
// hold the normal partition ID if partitionIDBreakdown is true.
func GetPerTaskQueuePartitionIDScope(
handler Handler,
namespaceName string,
partition tqid.Partition,
taskQueueBreakdown bool,
partitionIDBreakdown bool,
tags ...Tag,
) Handler {
var value string
if partition == nil {
value = unknownValue
} else if normalPartition, ok := partition.(*tqid.NormalPartition); ok {
if partitionIDBreakdown {
value = strconv.Itoa(normalPartition.PartitionId())
} else {
value = normal
}
} else {
value = sticky
}
return GetPerTaskQueueScope(handler, namespaceName, partition.TaskQueue(), taskQueueBreakdown,
append(tags, PartitionTag(value))...)
}
// GetPerTaskQueuePartitionTypeScope returns GetPerTaskQueueScope scope plus a "partition" tag which
// can be "__normal__", "__sticky__", or "_unknown_".
func GetPerTaskQueuePartitionTypeScope(
handler Handler,
namespaceName string,
partition tqid.Partition,
taskQueueBreakdown bool,
tags ...Tag,
) Handler {
var value string
if partition == nil {
value = unknownValue
} else if _, ok := partition.(*tqid.NormalPartition); ok {
value = normal
} else {
value = sticky
}
return GetPerTaskQueueScope(handler, namespaceName, partition.TaskQueue(), taskQueueBreakdown,
append(tags, PartitionTag(value))...)
}