@@ -5232,6 +5232,131 @@ func (*testTaskManager) CountTaskQueuesByBuildId(context.Context, *persistence.C
52325232 return 0 , nil
52335233}
52345234
5235+ // TestLoggerAndMetricsForPartition_BreakdownEnabled verifies partition and taskqueue tag values
5236+ // with the default BreakdownMetricsByTaskQueue=true: normal queues show their name, sticky queues
5237+ // show the base name, and worker-commands queues get partition=__worker_commands__ with
5238+ // taskqueue=__omitted__.
5239+ func TestLoggerAndMetricsForPartition_BreakdownEnabled (t * testing.T ) {
5240+ t .Parallel ()
5241+
5242+ controller := gomock .NewController (t )
5243+ ns , mockNamespaceCache := createMockNamespaceCache (controller , matchingTestNamespace )
5244+ config := defaultTestConfig ()
5245+ e := createTestMatchingEngine (log .NewTestLogger (), controller , config , nil , mockNamespaceCache )
5246+ captureHandler := metricstest .NewCaptureHandler ()
5247+ e .metricsHandler = captureHandler
5248+
5249+ tests := []struct {
5250+ name string
5251+ partition tqid.Partition
5252+ expectTQValue string
5253+ expectPartitionTag string
5254+ }{
5255+ {
5256+ name : "normal task queue uses actual queue name" ,
5257+ partition : newRootPartition (ns .ID ().String (), "my-task-queue" , enumspb .TASK_QUEUE_TYPE_NEXUS ),
5258+ expectTQValue : "my-task-queue" ,
5259+ expectPartitionTag : "0" ,
5260+ },
5261+ {
5262+ name : "worker-commands queue gets __worker_commands__ partition and __omitted__ taskqueue" ,
5263+ partition : newTestTaskQueue (ns .ID ().String (), "my-task-queue" , enumspb .TASK_QUEUE_TYPE_NEXUS ).WorkerCommandsPartition ("/temporal-sys/worker-commands/ns/key" ),
5264+ expectTQValue : "__omitted__" ,
5265+ expectPartitionTag : "__worker_commands__" ,
5266+ },
5267+ {
5268+ name : "sticky task queue uses base queue name" ,
5269+ partition : newTestTaskQueue (ns .ID ().String (), "my-task-queue" , enumspb .TASK_QUEUE_TYPE_WORKFLOW ).StickyPartition (uuid .NewString ()),
5270+ expectTQValue : "my-task-queue" ,
5271+ expectPartitionTag : "__sticky__" ,
5272+ },
5273+ }
5274+
5275+ for _ , tc := range tests {
5276+ t .Run (tc .name , func (t * testing.T ) {
5277+ capture := captureHandler .StartCapture ()
5278+ tqConfig := newTaskQueueConfig (tc .partition .TaskQueue (), config , matchingTestNamespace )
5279+ _ , _ , handler := e .loggerAndMetricsForPartition (ns , tc .partition , tqConfig )
5280+ metrics .PollSuccessPerTaskQueueCounter .With (handler ).Record (1 )
5281+ snap := capture .Snapshot ()
5282+ captureHandler .StopCapture (capture )
5283+ recordings := snap ["poll_success" ]
5284+ require .NotEmpty (t , recordings , "expected poll_success metric to be recorded" )
5285+ found := false
5286+ for _ , rec := range recordings {
5287+ if rec .Tags ["taskqueue" ] == tc .expectTQValue && rec .Tags ["partition" ] == tc .expectPartitionTag {
5288+ found = true
5289+ }
5290+ }
5291+ assert .True (t , found , "expected taskqueue=%q partition=%q, got: %v" , tc .expectTQValue , tc .expectPartitionTag , recordings )
5292+ })
5293+ }
5294+ }
5295+
5296+ // TestLoggerAndMetricsForPartition_BreakdownDisabled verifies behavior with BreakdownMetricsByTaskQueue=false:
5297+ // normal and sticky queues get taskqueue=__omitted__, and worker-commands queues also get __omitted__
5298+ // with partition=__worker_commands__.
5299+ func TestLoggerAndMetricsForPartition_BreakdownDisabled (t * testing.T ) {
5300+ t .Parallel ()
5301+
5302+ controller := gomock .NewController (t )
5303+ ns , mockNamespaceCache := createMockNamespaceCache (controller , matchingTestNamespace )
5304+ dc := dynamicconfig.StaticClient {
5305+ dynamicconfig .MetricsBreakdownByTaskQueue .Key (): false ,
5306+ }
5307+ config := NewConfig (dynamicconfig .NewCollection (dc , log .NewNoopLogger ()))
5308+ config .LongPollExpirationInterval = dynamicconfig .GetDurationPropertyFnFilteredByTaskQueue (100 * time .Millisecond )
5309+ e := createTestMatchingEngine (log .NewTestLogger (), controller , config , nil , mockNamespaceCache )
5310+ captureHandler := metricstest .NewCaptureHandler ()
5311+ e .metricsHandler = captureHandler
5312+
5313+ tests := []struct {
5314+ name string
5315+ partition tqid.Partition
5316+ expectTQValue string
5317+ expectPartitionTag string
5318+ }{
5319+ {
5320+ name : "normal task queue is omitted when breakdown disabled" ,
5321+ partition : newRootPartition (ns .ID ().String (), "my-task-queue" , enumspb .TASK_QUEUE_TYPE_NEXUS ),
5322+ expectTQValue : "__omitted__" ,
5323+ expectPartitionTag : "0" ,
5324+ },
5325+ {
5326+ name : "worker-commands queue gets __worker_commands__ partition when breakdown disabled" ,
5327+ partition : newTestTaskQueue (ns .ID ().String (), "my-task-queue" , enumspb .TASK_QUEUE_TYPE_NEXUS ).WorkerCommandsPartition ("/temporal-sys/worker-commands/ns/key" ),
5328+ expectTQValue : "__omitted__" ,
5329+ expectPartitionTag : "__worker_commands__" ,
5330+ },
5331+ {
5332+ name : "sticky task queue is omitted when breakdown disabled" ,
5333+ partition : newTestTaskQueue (ns .ID ().String (), "my-task-queue" , enumspb .TASK_QUEUE_TYPE_WORKFLOW ).StickyPartition (uuid .NewString ()),
5334+ expectTQValue : "__omitted__" ,
5335+ expectPartitionTag : "__sticky__" ,
5336+ },
5337+ }
5338+
5339+ for _ , tc := range tests {
5340+ t .Run (tc .name , func (t * testing.T ) {
5341+ capture := captureHandler .StartCapture ()
5342+ tqConfig := newTaskQueueConfig (tc .partition .TaskQueue (), config , matchingTestNamespace )
5343+ _ , _ , handler := e .loggerAndMetricsForPartition (ns , tc .partition , tqConfig )
5344+ metrics .PollSuccessPerTaskQueueCounter .With (handler ).Record (1 )
5345+ snap := capture .Snapshot ()
5346+ captureHandler .StopCapture (capture )
5347+ recordings := snap ["poll_success" ]
5348+ require .NotEmpty (t , recordings , "expected poll_success metric to be recorded" )
5349+ found := false
5350+ for _ , rec := range recordings {
5351+ if rec .Tags ["taskqueue" ] == tc .expectTQValue && rec .Tags ["partition" ] == tc .expectPartitionTag {
5352+ found = true
5353+ }
5354+ }
5355+ assert .True (t , found , "expected taskqueue=%q partition=%q, got: %v" , tc .expectTQValue , tc .expectPartitionTag , recordings )
5356+ })
5357+ }
5358+ }
5359+
52355360func TestConvertPollWorkflowTaskQueueResponse (t * testing.T ) {
52365361 t .Parallel ()
52375362
0 commit comments