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

66 lines
2.3 KiB
Go

package workflow
import (
"testing"
"time"
"github.com/stretchr/testify/require"
enumspb "go.temporal.io/api/enums/v1"
"github.com/hanzoai/tasks/common/dynamicconfig"
"github.com/hanzoai/tasks/common/log"
"github.com/hanzoai/tasks/common/metrics"
"github.com/hanzoai/tasks/common/metrics/metricstest"
"github.com/hanzoai/tasks/common/namespace"
"github.com/hanzoai/tasks/service/history/configs"
"google.golang.org/protobuf/types/known/timestamppb"
)
func TestEmitWorkflowCompletionStats_WorkflowDuration(t *testing.T) {
logger := log.NewTestLogger()
testHandler, _ := metricstest.NewHandler(logger, metrics.ClientConfig{})
testNamespace := namespace.Name("test-namespace")
config := &configs.Config{
BreakdownMetricsByTaskQueue: dynamicconfig.GetBoolPropertyFnFilteredByTaskQueue(true),
}
completionMetric := completionMetric{
initialized: true,
isWorkflow: true,
taskQueue: "test-task-queue",
namespaceState: "active",
workflowTypeName: "test-workflow",
status: enumspb.WORKFLOW_EXECUTION_STATUS_COMPLETED,
startTime: timestamppb.New(time.Unix(100, 0)),
closeTime: timestamppb.New(time.Unix(130, 0)),
}
emitWorkflowCompletionStats(testHandler, testNamespace, completionMetric, config)
snapshot, err := testHandler.Snapshot()
require.NoError(t, err)
buckets, err := snapshot.Histogram("workflow_schedule_to_close_latency_milliseconds",
metrics.StringTag("namespace", "test-namespace"),
metrics.StringTag("namespace_state", "active"),
metrics.StringTag("workflowType", "test-workflow"),
metrics.StringTag("operation", "CompletionStats"),
metrics.StringTag("taskqueue", "test-task-queue"),
metrics.StringTag("otel_scope_name", "temporal"),
metrics.StringTag("otel_scope_version", ""),
)
require.NoError(t, err)
require.NotEmpty(t, buckets)
}
func TestEmitWorkflowCompletionStats_SkipNonWorkflow(t *testing.T) {
logger := log.NewTestLogger()
testHandler, _ := metricstest.NewHandler(logger, metrics.ClientConfig{})
testNamespace := namespace.Name("test-namespace")
completionMetric := completionMetric{isWorkflow: false}
emitWorkflowCompletionStats(testHandler, testNamespace, completionMetric, nil)
snapshot, err := testHandler.Snapshot()
require.NoError(t, err)
_, err = snapshot.Histogram("workflow_schedule_to_close_latency_milliseconds")
require.Error(t, err)
}