Files
tasks/service/history/workflow/update/util.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

112 lines
3.1 KiB
Go

package update
import (
"fmt"
"go.opentelemetry.io/otel/trace"
"github.com/hanzoai/tasks/common/log"
"github.com/hanzoai/tasks/common/log/tag"
"github.com/hanzoai/tasks/common/metrics"
"github.com/hanzoai/tasks/common/softassert"
"github.com/hanzoai/tasks/common/telemetry"
"google.golang.org/protobuf/proto"
)
type (
instrumentation struct {
log log.Logger
metrics metrics.Handler
tracer trace.Tracer
namespace string
}
)
var (
noopInstrumentation = instrumentation{
log: log.NewNoopLogger(),
metrics: metrics.NoopMetricsHandler,
tracer: telemetry.NoopTracer,
}
)
func (i *instrumentation) countRequestMsg() {
i.oneOf(metrics.MessageTypeRequestWorkflowExecutionUpdateCounter.Name())
}
func (i *instrumentation) countAcceptanceMsg() {
i.oneOf(metrics.MessageTypeAcceptWorkflowExecutionUpdateCounter.Name())
}
func (i *instrumentation) countRejectionMsg() {
i.oneOf(metrics.MessageTypeRejectWorkflowExecutionUpdateCounter.Name())
}
func (i *instrumentation) countResponseMsg() {
i.oneOf(metrics.MessageTypeRespondWorkflowExecutionUpdateCounter.Name())
}
func (i *instrumentation) countRateLimited() {
i.oneOf(metrics.WorkflowExecutionUpdateRequestRateLimited.Name())
}
func (i *instrumentation) countRegistrySizeLimited(updateCount, registrySize, payloadSize int) {
i.oneOf(metrics.WorkflowExecutionUpdateRegistrySizeLimited.Name())
i.log.Warn("update registry size limit reached",
tag.Int("registry-size", registrySize),
tag.Int("payload-size", payloadSize),
tag.Int("update-count", updateCount),
tag.String("namespace", i.namespace),
)
}
func (i *instrumentation) countTooMany() {
i.oneOf(metrics.WorkflowExecutionUpdateTooMany.Name())
}
func (i *instrumentation) countAborted(updateID string, reason AbortReason) {
i.metrics.Counter(metrics.WorkflowExecutionUpdateAborted.Name()).
Record(1, metrics.ReasonTag(metrics.ReasonString(reason.String())))
i.log.Debug("update aborted",
tag.String("reason", reason.String()),
tag.String("update-id", updateID),
)
}
func (i *instrumentation) countSent() {
i.oneOf(metrics.WorkflowExecutionUpdateSentToWorker.Name())
}
func (i *instrumentation) countSentAgain() {
i.oneOf(metrics.WorkflowExecutionUpdateSentToWorkerAgain.Name())
}
func (i *instrumentation) invalidStateTransition(updateID string, msg proto.Message, state state) {
softassert.Fail(
i.log,
"invalid state transition attempted",
tag.ComponentWorkflowUpdate,
tag.String("update-id", updateID),
tag.String("message", fmt.Sprintf("%T", msg)),
tag.Stringer("state", state),
tag.String("namespace", i.namespace),
)
}
func (i *instrumentation) updateRegistrySize(size int) {
i.metrics.Histogram(metrics.WorkflowExecutionUpdateRegistrySize.Name(), metrics.Bytes).Record(int64(size))
}
func (i *instrumentation) oneOf(counterName string) {
i.metrics.Counter(counterName).Record(1)
}
func (i *instrumentation) stateChange(updateID string, from, to state) {
i.log.Debug(
"update state change",
tag.ComponentWorkflowUpdate,
tag.String("update-id", updateID),
tag.Stringer("from-state", from),
tag.Stringer("to-state", to),
)
}