@@ -508,55 +508,37 @@ def test_custom_queries(aggregator, dd_run_check, instance_docker, custom_query,
508
508
509
509
@pytest .mark .integration
510
510
@pytest .mark .usefixtures ('dd_environment' )
511
- @pytest .mark .parametrize (
512
- "custom_query, assert_metrics" ,
513
- [
514
- (
515
- {
516
- 'query' : "SELECT letter, num FROM (VALUES (97, 'a'), (98, 'b')) AS t (num,letter)" ,
517
- 'columns' : [{'name' : 'customtag' , 'type' : 'tag' }, {'name' : 'num' , 'type' : 'gauge' }],
518
- 'tags' : ['query:custom' ],
519
- },
520
- [
521
- ("sqlserver.num" , {"value" : 97 , "tags" : ["customtag:a" , "query:custom" ]}),
522
- ("sqlserver.num" , {"value" : 98 , "tags" : ["customtag:b" , "query:custom" ]}),
523
- ],
524
- ),
525
- (
526
- {
527
- 'query' : "EXEC exampleProcWithoutNocount" ,
528
- 'columns' : [{'name' : 'value' , 'type' : 'gauge' }],
529
- 'tags' : ['hello:there' ],
530
- },
531
- [
532
- ("sqlserver.value" , {"value" : 1 , "tags" : ["hello:there" ]}),
533
- ],
534
- ),
535
- ],
536
- )
537
- def test_custom_queries_only (aggregator , dd_run_check , instance_docker , custom_query , assert_metrics ):
511
+ def test_only_custom_queries (aggregator , dd_run_check , instance_docker ):
512
+ """Test that only_custom_queries=True skips regular metrics but executes custom queries."""
538
513
instance = copy (instance_docker )
539
- instance ['custom_queries' ] = [custom_query ]
540
514
instance ['only_custom_queries' ] = True
515
+ instance ['custom_queries' ] = [
516
+ {
517
+ 'query' : "SELECT 42 as custom_value" ,
518
+ 'columns' : [{'name' : 'custom_value' , 'type' : 'gauge' }],
519
+ 'tags' : ['test:only_custom' ],
520
+ }
521
+ ]
541
522
instance ['procedure_metrics' ] = {'enabled' : False }
542
523
543
524
check = SQLServer (CHECK_NAME , {}, [instance ])
544
525
dd_run_check (check )
545
526
546
- for metric_name , kwargs in assert_metrics :
547
- kwargs = copy (kwargs )
548
- kwargs ['tags' ] = (
549
- check ._config .tags
550
- + [
551
- "database_hostname:{}" .format ("stubbed.hostname" ),
552
- "database_instance:{}" .format ("stubbed.hostname" ),
553
- "ddagenthostname:{}" .format ("stubbed.hostname" ),
554
- "dd.internal.resource:database_instance:{}" .format ("stubbed.hostname" ),
555
- "sqlserver_servername:{}" .format (check .static_info_cache .get (STATIC_INFO_SERVERNAME )),
556
- ]
557
- + kwargs .get ('tags' , [])
558
- )
559
- aggregator .assert_metric (metric_name , ** kwargs )
527
+ # Verify that regular integration metrics are NOT collected
528
+ # (These would normally be collected by default)
529
+ aggregator .assert_metric ('sqlserver.cache.hit_ratio' , count = 0 )
530
+ aggregator .assert_metric ('sqlserver.broker_activation.tasks_running' , count = 0 )
531
+
532
+ # Verify that custom query metrics ARE collected
533
+ instance_tags = check ._config .tags + [
534
+ "database_hostname:{}" .format ("stubbed.hostname" ),
535
+ "database_instance:{}" .format ("stubbed.hostname" ),
536
+ "ddagenthostname:{}" .format ("stubbed.hostname" ),
537
+ "dd.internal.resource:database_instance:{}" .format ("stubbed.hostname" ),
538
+ "sqlserver_servername:{}" .format (check .static_info_cache .get (STATIC_INFO_SERVERNAME )),
539
+ ]
540
+
541
+ aggregator .assert_metric ('sqlserver.custom_value' , value = 42 , tags = instance_tags + ['test:only_custom' ], count = 1 )
560
542
561
543
562
544
@pytest .mark .integration
0 commit comments