mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-02 12:22:18 +00:00
## What changed? This PR produces the metric workflow_duration, when the workflow execution completes. ## Why? Currently there is no metric that captures the duration of the workflow execution. It's also valuable to have the duration broken down by task queue, namespace, workflow type, which this PR enables ## How did you test it? - [X] built - [X] run locally and tested manually - [X] covered by existing tests - [X] added new unit test(s) - [ ] added new functional test(s)
66 lines
2.3 KiB
Go
66 lines
2.3 KiB
Go
package workflow
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
enumspb "go.temporal.io/api/enums/v1"
|
|
"go.temporal.io/server/common/dynamicconfig"
|
|
"go.temporal.io/server/common/log"
|
|
"go.temporal.io/server/common/metrics"
|
|
"go.temporal.io/server/common/metrics/metricstest"
|
|
"go.temporal.io/server/common/namespace"
|
|
"go.temporal.io/server/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_duration_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_duration_milliseconds")
|
|
require.Error(t, err)
|
|
}
|