@@ -77,4 +77,55 @@ def test_only_fresh_metrics_are_collected
7777 assert_equal expected , metrics . map ( &:metric_text )
7878 end
7979 end
80+
81+ def test_collecting_metrics_with_custom_labels
82+ collector . collect (
83+ "custom_labels" => { "service" => "payments" , "env" => "prod" } ,
84+ "process" => {
85+ "busy" => 3 ,
86+ "concurrency" => 10 ,
87+ "labels" => {
88+ "labels" => "lab_a" ,
89+ "queues" => "critical,default" ,
90+ "quiet" => "false" ,
91+ "tag" => "main" ,
92+ "hostname" => "sidekiq-host" ,
93+ "identity" => "sidekiq-host:1" ,
94+ } ,
95+ } ,
96+ )
97+
98+ metrics = collector . metrics
99+ expected = [
100+ 'sidekiq_process_busy{service="payments",env="prod",labels="lab_a",queues="critical,default",quiet="false",tag="main",hostname="sidekiq-host",identity="sidekiq-host:1"} 3' ,
101+ 'sidekiq_process_concurrency{service="payments",env="prod",labels="lab_a",queues="critical,default",quiet="false",tag="main",hostname="sidekiq-host",identity="sidekiq-host:1"} 10' ,
102+ ]
103+ assert_equal expected , metrics . map ( &:metric_text )
104+ end
105+
106+ def test_custom_labels_overridden_by_process_labels
107+ collector . collect (
108+ "custom_labels" => { "service" => "billing" , "tag" => "override" } ,
109+ "process" => {
110+ "busy" => 4 ,
111+ "concurrency" => 8 ,
112+ "labels" => {
113+ "labels" => "lab_x" ,
114+ "queues" => "default" ,
115+ "quiet" => "true" ,
116+ "tag" => "real_tag" ,
117+ "hostname" => "host-1" ,
118+ "identity" => "host-1:2" ,
119+ } ,
120+ } ,
121+ )
122+
123+ # tag should be from process labels (real_tag) not custom_labels (override)
124+ metrics = collector . metrics
125+ expected = [
126+ 'sidekiq_process_busy{service="billing",tag="real_tag",labels="lab_x",queues="default",quiet="true",hostname="host-1",identity="host-1:2"} 4' ,
127+ 'sidekiq_process_concurrency{service="billing",tag="real_tag",labels="lab_x",queues="default",quiet="true",hostname="host-1",identity="host-1:2"} 8' ,
128+ ]
129+ assert_equal expected , metrics . map ( &:metric_text )
130+ end
80131end
0 commit comments