@@ -217,6 +217,50 @@ def test_collect_connection_metrics_config_option(instance, collect_connection_m
217217 )
218218
219219
220+ @pytest .mark .parametrize (
221+ 'add_description_tags,normalize_description_tags,channel_desc,expected_desc_tag' ,
222+ [
223+ (False , True , b'Test Description' , None ), # Disabled
224+ (True , True , b'Test Description' , 'channel_desc:test_description' ), # Enabled + normalized
225+ (True , False , b'Test Description' , 'channel_desc:Test Description' ), # Enabled + raw
226+ (True , True , b'' , None ), # Empty description
227+ ],
228+ )
229+ def test_channel_description_tags (
230+ instance , add_description_tags , normalize_description_tags , channel_desc , expected_desc_tag
231+ ):
232+ """Test channel description tags with different config options."""
233+ instance ['add_description_tags' ] = add_description_tags
234+ instance ['normalize_description_tags' ] = normalize_description_tags
235+
236+ channel_info = {
237+ pymqi .CMQCFC .MQCACH_CHANNEL_NAME : b'TEST.CHANNEL' ,
238+ pymqi .CMQCFC .MQIACH_BATCH_SIZE : 100 ,
239+ }
240+ if channel_desc :
241+ channel_info [pymqi .CMQCFC .MQCACH_DESC ] = channel_desc
242+
243+ collector = _get_mocked_instance (instance )
244+ collector ._discover_channels = Mock (return_value = [channel_info ])
245+ collector .gauge = Mock ()
246+ queue_manager = Mock ()
247+
248+ collector .get_pcf_channel_metrics (queue_manager )
249+
250+ # Find gauge calls with channel-specific tags (skip the first call which is for total channel count)
251+ gauge_calls = collector .gauge .call_args_list
252+ channel_metric_calls = [call for call in gauge_calls if 'channel:TEST.CHANNEL' in call [1 ]['tags' ]]
253+ assert len (channel_metric_calls ) > 0 , "Expected at least one channel-specific metric call"
254+
255+ channel_tags = channel_metric_calls [0 ][1 ]['tags' ]
256+
257+ if expected_desc_tag :
258+ assert expected_desc_tag in channel_tags
259+ else :
260+ desc_tags = [t for t in channel_tags if t .startswith ('channel_desc:' )]
261+ assert len (desc_tags ) == 0
262+
263+
220264def _get_mocked_instance (instance ):
221265 config = IBMMQConfig (instance , {})
222266 collector = ChannelMetricCollector (config , service_check = Mock (), gauge = Mock (), log = Mock ())
0 commit comments