mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-30 14:56:19 +00:00
## What changed? Add archetype metric tag and logical task processing metrics, and add `chasm_pure_task_requests` and `chasm_pure_task_errors` metrics. Archetype metric tab will be applied for all tasks executed, physical and logical, that get added in Executable.go by default. If the archetype is found, the archetype display name will be used for the tag value. Otherwise, will default to `workflow` archetype. For chasm logical pure task metrics, will resolve to `__unknown__` if archetype is not found, since this would be unexpected behavior. ## Why? Components and therefore task types can be used across different archetype executions. In the future with more archetypes, there needs to be visibility for which archetype created the task for execution. ## 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)
69 lines
2.1 KiB
Go
69 lines
2.1 KiB
Go
package history
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"go.opentelemetry.io/otel/trace/noop"
|
|
persistencespb "go.temporal.io/server/api/persistence/v1"
|
|
"go.temporal.io/server/common/clock"
|
|
"go.temporal.io/server/common/cluster"
|
|
"go.temporal.io/server/common/log"
|
|
"go.temporal.io/server/common/metrics"
|
|
"go.temporal.io/server/common/primitives/timestamp"
|
|
"go.temporal.io/server/service/history/shard"
|
|
"go.temporal.io/server/service/history/tasks"
|
|
"go.temporal.io/server/service/history/tests"
|
|
"go.uber.org/mock/gomock"
|
|
)
|
|
|
|
func TestArchivalQueueFactory(t *testing.T) {
|
|
ctrl := gomock.NewController(t)
|
|
defer ctrl.Finish()
|
|
|
|
metricsHandler := metrics.NewMockHandler(ctrl)
|
|
metricsHandler.EXPECT().WithTags(gomock.Any()).DoAndReturn(
|
|
func(tags ...metrics.Tag) metrics.Handler {
|
|
require.Len(t, tags, 1)
|
|
assert.Equal(t, metrics.OperationTagName, tags[0].Key)
|
|
assert.Equal(t, "ArchivalQueueProcessor", tags[0].Value)
|
|
return metricsHandler
|
|
},
|
|
).Times(1)
|
|
|
|
mockShard := shard.NewTestContext(
|
|
ctrl,
|
|
&persistencespb.ShardInfo{
|
|
ShardId: 0,
|
|
RangeId: 1,
|
|
QueueStates: map[int32]*persistencespb.QueueState{
|
|
int32(tasks.CategoryIDArchival): {
|
|
ReaderStates: nil,
|
|
ExclusiveReaderHighWatermark: &persistencespb.TaskKey{
|
|
FireTime: timestamp.TimeNowPtrUtc(),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
tests.NewDynamicConfig(),
|
|
)
|
|
mockShard.Resource.ClusterMetadata.EXPECT().GetCurrentClusterName().Return(cluster.TestCurrentClusterName).AnyTimes()
|
|
|
|
queueFactory := NewArchivalQueueFactory(ArchivalQueueFactoryParams{
|
|
QueueFactoryBaseParams: QueueFactoryBaseParams{
|
|
NamespaceRegistry: mockShard.Resource.GetNamespaceRegistry(),
|
|
ClusterMetadata: mockShard.Resource.GetClusterMetadata(),
|
|
Config: tests.NewDynamicConfig(),
|
|
TimeSource: clock.NewEventTimeSource(),
|
|
MetricsHandler: metricsHandler,
|
|
Logger: log.NewNoopLogger(),
|
|
TracerProvider: noop.NewTracerProvider(),
|
|
},
|
|
})
|
|
queue := queueFactory.CreateQueue(mockShard)
|
|
|
|
require.NotNil(t, queue)
|
|
assert.Equal(t, tasks.CategoryArchival, queue.Category())
|
|
}
|