Skip to content

Commit cbfd974

Browse files
authored
deprecate schemas_collection, deadlock_collection and xe_collection config option (DataDog#20599)
* deprecate schemas_collection, deadlock_collection and xe_collection config option * add changelog * sync config * sync config * fix tests * fix tests * fix deprecation version
1 parent 0a3f7d4 commit cbfd974

9 files changed

Lines changed: 256 additions & 34 deletions

File tree

sqlserver/assets/configuration/spec.yaml

Lines changed: 132 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -907,8 +907,8 @@ files:
907907
- name: collect_raw_query_statement
908908
description: |
909909
Configure the collection of raw query statements in query activity, and XE events.
910-
To collect raw query statements from XE events, set `xe_collection.query_completions.enabled` and
911-
`xe_collection.query_errors.enabled` to `true`.
910+
To collect raw query statements from XE events, set `collect_xe.query_completions.enabled` and
911+
`collect_xe.query_errors.enabled` to `true`.
912912
Raw query statements and execution plans may contain sensitive information (e.g., passwords)
913913
or personally identifiable information in query text.
914914
Enabling this option will allow the collection and ingestion of raw query statements and
@@ -987,9 +987,37 @@ files:
987987
type: number
988988
example: 1800
989989
display_default: 300
990+
- name: collect_schemas
991+
description: |
992+
Configure collection of schemas. If `database_autodiscovery` is not enabled, data is collected
993+
only for the database configured with `database` parameter.
994+
options:
995+
- name: enabled
996+
description: |
997+
Enable schema collection. Requires `dbm: true`. Defaults to false.
998+
value:
999+
type: boolean
1000+
example: false
1001+
- name: collection_interval
1002+
description: |
1003+
Set the database schema collection interval (in seconds). Defaults to 600 seconds.
1004+
value:
1005+
type: number
1006+
example: 600
1007+
- name: max_execution_time
1008+
description: |
1009+
Set the maximum time for schema collection (in seconds). Defaults to 10 seconds.
1010+
Capped by `collect_schemas.collection_interval`
1011+
value:
1012+
type: number
1013+
example: 10
9901014
- name: schemas_collection
1015+
hidden: true
1016+
deprecation:
1017+
Agent version: 7.69.0
1018+
Migration: Use `collect_schemas` instead.
9911019
description: |
992-
Available for Agent 7.56 and newer.
1020+
DEPRECATED: Use `collect_schemas` instead.
9931021
Configure collection of schemas. If `database_autodiscovery` is not enabled, data is collected
9941022
only for the database configured with `database` parameter.
9951023
options:
@@ -1020,8 +1048,82 @@ files:
10201048
value:
10211049
example: false
10221050
type: boolean
1051+
- name: collect_xe
1052+
description: |
1053+
Configure the collection of events from XE (Extended Events) sessions. Requires `dbm: true`.
1054+
1055+
Set `collect_raw_query_statement.enabled` to `true` to collect the raw query statements for each event.
1056+
options:
1057+
- name: debug_sample_events
1058+
description: |
1059+
Set the maximum number of XE events to log in debug mode per collection. Used for troubleshooting.
1060+
This only affects logging when debug mode is enabled. Defaults to 3.
1061+
hidden: true
1062+
value:
1063+
type: integer
1064+
example: 3
1065+
display_default: 3
1066+
- name: query_completions
1067+
description: |
1068+
Configure the collection of completed queries from the `datadog_query_completions` XE session.
1069+
1070+
Set `query_completions.enabled` to `true` to enable the collection of query completion events.
1071+
1072+
Use `query_completions.collection_interval` to set the interval (in seconds) for the collection of
1073+
query completion events. Defaults to 10 seconds. If you intend on updating this value,
1074+
it is strongly recommended to use a consistent value throughout all SQL Server agent deployments.
1075+
1076+
Use `query_completions.max_events` to set the maximum number of query completion events to process
1077+
per collection. Note that SQL Server's ring buffer has a maximum of 1000 events per query,
1078+
so values above 1000 will still be capped at 1000 by the database engine. Defaults to 1000.
1079+
value:
1080+
type: object
1081+
properties:
1082+
- name: enabled
1083+
type: boolean
1084+
example: false
1085+
- name: collection_interval
1086+
type: number
1087+
example: 10
1088+
display_default: 10
1089+
- name: max_events
1090+
type: integer
1091+
example: 1000
1092+
display_default: 1000
1093+
- name: query_errors
1094+
description: |
1095+
Configure the collection of query errors from the `datadog_query_errors` XE session.
1096+
1097+
Set `query_errors.enabled` to `true` to enable the collection of query error events.
1098+
1099+
Use `query_errors.collection_interval` to set the interval (in seconds) for the collection of
1100+
query error events. Defaults to 10 seconds. If you intend on updating this value,
1101+
it is strongly recommended to use a consistent value throughout all SQL Server agent deployments.
1102+
1103+
Use `query_errors.max_events` to set the maximum number of query error events to process
1104+
per collection. Note that SQL Server's ring buffer has a maximum of 1000 events per query,
1105+
so values above 1000 will still be capped at 1000 by the database engine. Defaults to 1000.
1106+
value:
1107+
type: object
1108+
properties:
1109+
- name: enabled
1110+
type: boolean
1111+
example: false
1112+
- name: collection_interval
1113+
type: number
1114+
example: 10
1115+
display_default: 10
1116+
- name: max_events
1117+
type: integer
1118+
example: 1000
1119+
display_default: 1000
10231120
- name: xe_collection
1121+
hidden: true
1122+
deprecation:
1123+
Agent version: 7.69.0
1124+
Migration: Use `collect_xe` instead.
10241125
description: |
1126+
DEPRECATED: Use `collect_xe` instead.
10251127
Configure the collection of events from XE (Extended Events) sessions. Requires `dbm: true`.
10261128
10271129
Set `collect_raw_query_statement.enabled` to `true` to collect the raw query statements for each event.
@@ -1089,8 +1191,35 @@ files:
10891191
type: integer
10901192
example: 1000
10911193
display_default: 1000
1194+
- name: collect_deadlocks
1195+
description: |
1196+
Configure the collection of deadlock data.
1197+
options:
1198+
- name: enabled
1199+
description: |
1200+
Enable the collection of deadlock data. Requires `dbm: true`. Disabled by default.
1201+
value:
1202+
type: boolean
1203+
example: false
1204+
- name: collection_interval
1205+
description: |
1206+
Set the interval for collecting deadlock data, in seconds. Defaults to 600 seconds.
1207+
value:
1208+
type: number
1209+
example: 600
1210+
- name: max_deadlocks
1211+
description: |
1212+
Set the maximum number of deadlocks to retrieve per collection.
1213+
value:
1214+
type: number
1215+
example: 100
10921216
- name: deadlocks_collection
1217+
hidden: true
1218+
deprecation:
1219+
Agent version: 7.69.0
1220+
Migration: Use `collect_deadlocks` instead.
10931221
description: |
1222+
DEPRECATED: Use `collect_deadlocks` instead.
10941223
Configure the collection of deadlock data.
10951224
options:
10961225
- name: enabled

sqlserver/changelog.d/20599.added

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add new collect_* configuration options (collect_schemas, collect_deadlocks, collect_xe) to replace deprecated *_collection options while maintaining backward compatibility.

sqlserver/datadog_checks/sqlserver/config.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ def __init__(self, init_config, instance, log):
5555
self.procedure_metrics_config: dict = instance.get('procedure_metrics', {}) or {}
5656
self.settings_config: dict = instance.get('collect_settings', {}) or {}
5757
self.activity_config: dict = instance.get('query_activity', {}) or {}
58-
self.schema_config: dict = instance.get('schemas_collection', {}) or {}
59-
self.deadlocks_config: dict = instance.get('deadlocks_collection', {}) or {}
60-
self.xe_collection_config: dict = instance.get('xe_collection', {}) or {}
58+
# Backward compatibility: check new names first, then fall back to old names
59+
self.schema_config: dict = instance.get('collect_schemas', instance.get('schemas_collection', {})) or {}
60+
self.deadlocks_config: dict = instance.get('collect_deadlocks', instance.get('deadlocks_collection', {})) or {}
61+
self.xe_collection_config: dict = instance.get('collect_xe', instance.get('xe_collection', {})) or {}
6162
self.cloud_metadata: dict = {}
6263
aws: dict = instance.get('aws', {}) or {}
6364
gcp: dict = instance.get('gcp', {}) or {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# (C) Datadog, Inc. 2025-present
2+
# All rights reserved
3+
# Licensed under a 3-clause BSD style license (see LICENSE)
4+
5+
6+
def instance():
7+
return {
8+
'deadlocks_collection': {'Agent version': '7.69.0', 'Migration': 'Use `collect_deadlocks` instead.'},
9+
'schemas_collection': {'Agent version': '7.69.0', 'Migration': 'Use `collect_schemas` instead.'},
10+
'xe_collection': {'Agent version': '7.69.0', 'Migration': 'Use `collect_xe` instead.'},
11+
}

sqlserver/datadog_checks/sqlserver/config_models/instance.py

Lines changed: 60 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from datadog_checks.base.utils.functions import identity
1818
from datadog_checks.base.utils.models import validation
1919

20-
from . import defaults, validators
20+
from . import defaults, deprecations, validators
2121

2222

2323
class AgentJobs(BaseModel):
@@ -48,6 +48,16 @@ class Azure(BaseModel):
4848
fully_qualified_domain_name: Optional[str] = None
4949

5050

51+
class CollectDeadlocks(BaseModel):
52+
model_config = ConfigDict(
53+
arbitrary_types_allowed=True,
54+
frozen=True,
55+
)
56+
collection_interval: Optional[float] = None
57+
enabled: Optional[bool] = None
58+
max_deadlocks: Optional[float] = None
59+
60+
5161
class CollectRawQueryStatement(BaseModel):
5262
model_config = ConfigDict(
5363
arbitrary_types_allowed=True,
@@ -56,6 +66,16 @@ class CollectRawQueryStatement(BaseModel):
5666
enabled: Optional[bool] = None
5767

5868

69+
class CollectSchemas(BaseModel):
70+
model_config = ConfigDict(
71+
arbitrary_types_allowed=True,
72+
frozen=True,
73+
)
74+
collection_interval: Optional[float] = None
75+
enabled: Optional[bool] = None
76+
max_execution_time: Optional[float] = None
77+
78+
5979
class CollectSettings(BaseModel):
6080
model_config = ConfigDict(
6181
arbitrary_types_allowed=True,
@@ -65,6 +85,36 @@ class CollectSettings(BaseModel):
6585
enabled: Optional[bool] = None
6686

6787

88+
class QueryCompletions(BaseModel):
89+
model_config = ConfigDict(
90+
arbitrary_types_allowed=True,
91+
frozen=True,
92+
)
93+
collection_interval: Optional[float] = Field(None, examples=[10])
94+
enabled: Optional[bool] = Field(None, examples=[False])
95+
max_events: Optional[int] = Field(None, examples=[1000])
96+
97+
98+
class QueryErrors(BaseModel):
99+
model_config = ConfigDict(
100+
arbitrary_types_allowed=True,
101+
frozen=True,
102+
)
103+
collection_interval: Optional[float] = Field(None, examples=[10])
104+
enabled: Optional[bool] = Field(None, examples=[False])
105+
max_events: Optional[int] = Field(None, examples=[1000])
106+
107+
108+
class CollectXe(BaseModel):
109+
model_config = ConfigDict(
110+
arbitrary_types_allowed=True,
111+
frozen=True,
112+
)
113+
debug_sample_events: Optional[int] = None
114+
query_completions: Optional[QueryCompletions] = None
115+
query_errors: Optional[QueryErrors] = None
116+
117+
68118
class CustomQuery(BaseModel):
69119
model_config = ConfigDict(
70120
arbitrary_types_allowed=True,
@@ -357,26 +407,6 @@ class SchemasCollection(BaseModel):
357407
max_execution_time: Optional[float] = None
358408

359409

360-
class QueryCompletions(BaseModel):
361-
model_config = ConfigDict(
362-
arbitrary_types_allowed=True,
363-
frozen=True,
364-
)
365-
collection_interval: Optional[float] = Field(None, examples=[10])
366-
enabled: Optional[bool] = Field(None, examples=[False])
367-
max_events: Optional[int] = Field(None, examples=[1000])
368-
369-
370-
class QueryErrors(BaseModel):
371-
model_config = ConfigDict(
372-
arbitrary_types_allowed=True,
373-
frozen=True,
374-
)
375-
collection_interval: Optional[float] = Field(None, examples=[10])
376-
enabled: Optional[bool] = Field(None, examples=[False])
377-
max_events: Optional[int] = Field(None, examples=[1000])
378-
379-
380410
class XeCollection(BaseModel):
381411
model_config = ConfigDict(
382412
arbitrary_types_allowed=True,
@@ -400,8 +430,11 @@ class InstanceConfig(BaseModel):
400430
autodiscovery_include: Optional[tuple[str, ...]] = None
401431
aws: Optional[Aws] = None
402432
azure: Optional[Azure] = None
433+
collect_deadlocks: Optional[CollectDeadlocks] = None
403434
collect_raw_query_statement: Optional[CollectRawQueryStatement] = None
435+
collect_schemas: Optional[CollectSchemas] = None
404436
collect_settings: Optional[CollectSettings] = None
437+
collect_xe: Optional[CollectXe] = None
405438
command_timeout: Optional[int] = None
406439
connection_string: Optional[str] = None
407440
connector: Optional[str] = None
@@ -448,6 +481,12 @@ class InstanceConfig(BaseModel):
448481
username: Optional[str] = None
449482
xe_collection: Optional[XeCollection] = None
450483

484+
@model_validator(mode='before')
485+
def _handle_deprecations(cls, values, info):
486+
fields = info.context['configured_fields']
487+
validation.utils.handle_deprecations('instances', deprecations.instance(), fields, info.context)
488+
return values
489+
451490
@model_validator(mode='before')
452491
def _initial_validation(cls, values):
453492
return validation.core.initialize_config(getattr(validators, 'initialize_instance', identity)(values))

sqlserver/datadog_checks/sqlserver/data/conf.yaml.example

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -657,8 +657,8 @@ instances:
657657
# keep_identifier_quotation: false
658658

659659
## Configure the collection of raw query statements in query activity, and XE events.
660-
## To collect raw query statements from XE events, set `xe_collection.query_completions.enabled` and
661-
## `xe_collection.query_errors.enabled` to `true`.
660+
## To collect raw query statements from XE events, set `collect_xe.query_completions.enabled` and
661+
## `collect_xe.query_errors.enabled` to `true`.
662662
## Raw query statements and execution plans may contain sensitive information (e.g., passwords)
663663
## or personally identifiable information in query text.
664664
## Enabling this option will allow the collection and ingestion of raw query statements and
@@ -783,11 +783,10 @@ instances:
783783
#
784784
# ignore_missing_database: false
785785

786-
## Available for Agent 7.56 and newer.
787786
## Configure collection of schemas. If `database_autodiscovery` is not enabled, data is collected
788787
## only for the database configured with `database` parameter.
789788
#
790-
# schemas_collection:
789+
# collect_schemas:
791790

792791
## @param enabled - boolean - optional - default: false
793792
## Enable schema collection. Requires `dbm: true`. Defaults to false.
@@ -801,7 +800,7 @@ instances:
801800

802801
## @param max_execution_time - number - optional - default: 10
803802
## Set the maximum time for schema collection (in seconds). Defaults to 10 seconds.
804-
## Capped by `schemas_collection.collection_interval`
803+
## Capped by `collect_schemas.collection_interval`
805804
#
806805
# max_execution_time: 10
807806

@@ -816,7 +815,7 @@ instances:
816815
##
817816
## Set `collect_raw_query_statement.enabled` to `true` to collect the raw query statements for each event.
818817
#
819-
# xe_collection:
818+
# collect_xe:
820819

821820
## @param query_completions - mapping - optional
822821
## Configure the collection of completed queries from the `datadog_query_completions` XE session.
@@ -850,7 +849,7 @@ instances:
850849

851850
## Configure the collection of deadlock data.
852851
#
853-
# deadlocks_collection:
852+
# collect_deadlocks:
854853

855854
## @param enabled - boolean - optional - default: false
856855
## Enable the collection of deadlock data. Requires `dbm: true`. Disabled by default.

sqlserver/tests/test_deadlocks.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,3 +364,15 @@ def test_deadlock_calls_obfuscator(deadlocks_collection_instance):
364364
result_string = result_string.replace('\t', '').replace('\n', '')
365365
result_string = re.sub(r'\s{2,}', ' ', result_string)
366366
assert expected_xml_string == result_string
367+
368+
369+
@pytest.mark.unit
370+
def test_collect_deadlocks_config(dbm_instance):
371+
dbm_instance['collect_deadlocks'] = {"enabled": True, 'collection_interval': 0.2}
372+
check = SQLServer(CHECK_NAME, {}, [dbm_instance])
373+
assert check._config.deadlocks_config == {"enabled": True, 'collection_interval': 0.2}
374+
375+
dbm_instance.pop('collect_deadlocks')
376+
dbm_instance['deadlocks_collection'] = {"enabled": True, 'collection_interval': 0.3}
377+
check = SQLServer(CHECK_NAME, {}, [dbm_instance])
378+
assert check._config.deadlocks_config == {"enabled": True, 'collection_interval': 0.3}

0 commit comments

Comments
 (0)