Skip to content

Commit d10b952

Browse files
authored
Add full_server_name support as template variable to sqlserver template config key (#20342)
* Add support as template variable to sqlserver template config key * changelog entry * do not treat instancename as a snowflake for fallback * updated config * updated config * fix unit test * fix tests * fix conf
1 parent 88af1c4 commit d10b952

File tree

7 files changed

+62
-52
lines changed

7 files changed

+62
-52
lines changed

sqlserver/assets/configuration/spec.yaml

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ files:
8080
default: false
8181
- name: database_identifier
8282
description: |
83-
Controls how the database is identified. The default value is the resolved hostname for the instance,
83+
Controls how the database is identified. The default value is the resolved hostname for the instance,
8484
which respects the `reported_hostname` option.
8585
8686
This value will be used as-is for the display name of the instance but will be normalized
@@ -91,7 +91,7 @@ files:
9191
value:
9292
type: string
9393
display_default: "$resolved_hostname"
94-
example: "$env-$resolved_hostname:$port"
94+
example: "$env-$resolved_hostname-$full_server_name"
9595
description: |
9696
The template to use for the database identifier. The default value is `$resolved_hostname`.
9797
You can use the following variables, prefixed by `$` in the template:
@@ -103,6 +103,7 @@ files:
103103
- database: The connection database.
104104
- server_name: The resolved server name of the instance.
105105
- instance_name: The resolved instance name of the instance.
106+
- full_server_name: The resolved full server name of the instance i.e. the value returned by `@@SERVERNAME`.
106107
In addition, you can use any key from the `tags` section of the configuration.
107108
default: "$resolved_hostname"
108109
- name: database_autodiscovery
@@ -173,9 +174,9 @@ files:
173174
174175
Set `ao_metrics.enabled` to true to enable collection of AlwaysOn metrics. Defaults to false.
175176
176-
When `ao_metrics.enabled` is True, use `ao_metrics.availability_group` to specify the
177-
resource group id of a specific availability group that you would like to monitor.
178-
If no availability group is specified, then we will collect AlwaysOn metrics for all
177+
When `ao_metrics.enabled` is True, use `ao_metrics.availability_group` to specify the
178+
resource group id of a specific availability group that you would like to monitor.
179+
If no availability group is specified, then we will collect AlwaysOn metrics for all
179180
availability groups on the current replica.
180181
181182
Primary replicas may emit metrics for remote secondary replicas
@@ -202,7 +203,7 @@ files:
202203
203204
Set `db_backup_metrics.enabled` to true to enable collection of database backup metrics. Defaults to true.
204205
205-
Use `db_backup_metrics.collection_interval` to set the interval (in seconds) for the collection of
206+
Use `db_backup_metrics.collection_interval` to set the interval (in seconds) for the collection of
206207
database backup metrics. Defaults to 300 seconds (5 minutes). If you intend on updating this value,
207208
it is strongly recommended to use a consistent value throughout all SQL Server agent deployments.
208209
hidden: true
@@ -242,11 +243,11 @@ files:
242243
example: true
243244
- name: db_fragmentation_metrics
244245
description: |
245-
Configure collection of database fragmentation metrics.
246-
Note these queries can be resource intensive on large datasets. Recommend to limit these via
246+
Configure collection of database fragmentation metrics.
247+
Note these queries can be resource intensive on large datasets. Recommend to limit these via
247248
autodiscovery or specific database instances.
248249
249-
Set `db_fragmentation_metrics.enabled` to true to enable collection of
250+
Set `db_fragmentation_metrics.enabled` to true to enable collection of
250251
database index fragmentation statistics. Defaults to false.
251252
252253
Use `db_fragmentation_metrics.enabled_tempdb` to enable collection of database index fragmentation statistics
@@ -343,7 +344,7 @@ files:
343344
type: boolean
344345
example: true
345346
- name: master_files_metrics
346-
description: |
347+
description: |
347348
Configure collection of database file size and state from `sys.master_files`
348349
349350
Set `master_files_metrics.enabled` to true to enable collection of database file size and state metrics.
@@ -356,7 +357,7 @@ files:
356357
example: false
357358
- name: primary_log_shipping_metrics
358359
description: |
359-
Configure collection of metrics for a log shipping setup. Required to run against the
360+
Configure collection of metrics for a log shipping setup. Required to run against the
360361
primary instance in a transaction log shipping configuration. Note that
361362
the Datadog user needs to be present in msdb and must be added to the db_datareader role.
362363
@@ -370,7 +371,7 @@ files:
370371
example: false
371372
- name: secondary_log_shipping_metrics
372373
description: |
373-
Configure collection of metrics for a log shipping setup. Required to run against the
374+
Configure collection of metrics for a log shipping setup. Required to run against the
374375
secondary instance in a transaction log shipping configuration. Note that
375376
the Datadog user needs to be present in msdb and must be added to the db_datareader role.
376377
@@ -410,7 +411,7 @@ files:
410411
description: |
411412
Configure collection of tempdb file space usage metrics for how space is used in tempdb data files.
412413
413-
Set `tempdb_file_space_usage_metrics.enabled` to true to enable collection of
414+
Set `tempdb_file_space_usage_metrics.enabled` to true to enable collection of
414415
tempdb file space usage metrics. Defaults to true.
415416
value:
416417
type: object
@@ -420,7 +421,7 @@ files:
420421
example: true
421422
- name: xe_metrics
422423
description: |
423-
Configure collection of extended events (XE) metrics.
424+
Configure collection of extended events (XE) metrics.
424425
425426
Set `xe_metrics.enabled` to true to enable collection of extended events metrics. Defaults to false.
426427
value:
@@ -889,12 +890,12 @@ files:
889890
- name: collect_raw_query_statement
890891
description: |
891892
Configure the collection of raw query statements in query activity, execution plans, and XE events.
892-
To collect raw query statements from XE events, set `xe_collection.query_completions.enabled` and
893+
To collect raw query statements from XE events, set `xe_collection.query_completions.enabled` and
893894
`xe_collection.query_errors.enabled` to `true`.
894895
Raw query statements and execution plans may contain sensitive information (e.g., passwords)
895896
or personally identifiable information in query text.
896-
Enabling this option will allow the collection and ingestion of raw query statements and
897-
execution plans into Datadog, which can then become viewable in query samples or explain plans.
897+
Enabling this option will allow the collection and ingestion of raw query statements and
898+
execution plans into Datadog, which can then become viewable in query samples or explain plans.
898899
This option is disabled by default.
899900
Note: Collection of raw query statements is currently in preview.
900901
If you are interested in participating, please reach out to your Datadog Customer Success Manager.
@@ -1022,13 +1023,13 @@ files:
10221023
Configure the collection of completed queries from the `datadog_query_completions` XE session.
10231024
10241025
Set `query_completions.enabled` to `true` to enable the collection of query completion events.
1025-
1026-
Use `query_completions.collection_interval` to set the interval (in seconds) for the collection of
1026+
1027+
Use `query_completions.collection_interval` to set the interval (in seconds) for the collection of
10271028
query completion events. Defaults to 10 seconds. If you intend on updating this value,
10281029
it is strongly recommended to use a consistent value throughout all SQL Server agent deployments.
1029-
1030-
Use `query_completions.max_events` to set the maximum number of query completion events to process
1031-
per collection. Note that SQL Server's ring buffer has a maximum of 1000 events per query,
1030+
1031+
Use `query_completions.max_events` to set the maximum number of query completion events to process
1032+
per collection. Note that SQL Server's ring buffer has a maximum of 1000 events per query,
10321033
so values above 1000 will still be capped at 1000 by the database engine. Defaults to 1000.
10331034
value:
10341035
type: object
@@ -1049,13 +1050,13 @@ files:
10491050
Configure the collection of query errors from the `datadog_query_errors` XE session.
10501051
10511052
Set `query_errors.enabled` to `true` to enable the collection of query error events.
1052-
1053-
Use `query_errors.collection_interval` to set the interval (in seconds) for the collection of
1053+
1054+
Use `query_errors.collection_interval` to set the interval (in seconds) for the collection of
10541055
query error events. Defaults to 10 seconds. If you intend on updating this value,
10551056
it is strongly recommended to use a consistent value throughout all SQL Server agent deployments.
1056-
1057-
Use `query_errors.max_events` to set the maximum number of query error events to process
1058-
per collection. Note that SQL Server's ring buffer has a maximum of 1000 events per query,
1057+
1058+
Use `query_errors.max_events` to set the maximum number of query error events to process
1059+
per collection. Note that SQL Server's ring buffer has a maximum of 1000 events per query,
10591060
so values above 1000 will still be capped at 1000 by the database engine. Defaults to 1000.
10601061
value:
10611062
type: object

sqlserver/changelog.d/20342.added

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add $full_server_name support as template variable to sqlserver template config key

sqlserver/datadog_checks/sqlserver/const.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
# Keys of the static info cache, used to cache server info which does not change
2525
STATIC_INFO_SERVERNAME = 'servername'
2626
STATIC_INFO_INSTANCENAME = 'instancename'
27+
STATIC_INFO_FULL_SERVERNAME = 'full_servername'
2728
STATIC_INFO_VERSION = 'version'
2829
STATIC_INFO_MAJOR_VERSION = 'major_version'
2930
STATIC_INFO_ENGINE_EDITION = 'engine_edition'

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

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ instances:
8585
#
8686
# exclude_hostname: false
8787

88-
## Controls how the database is identified. The default value is the resolved hostname for the instance,
88+
## Controls how the database is identified. The default value is the resolved hostname for the instance,
8989
## which respects the `reported_hostname` option.
9090
##
9191
## This value will be used as-is for the display name of the instance but will be normalized
@@ -105,9 +105,10 @@ instances:
105105
## - database: The connection database.
106106
## - server_name: The resolved server name of the instance.
107107
## - instance_name: The resolved instance name of the instance.
108+
## - full_server_name: The resolved full server name of the instance i.e. the value returned by `@@SERVERNAME`.
108109
## In addition, you can use any key from the `tags` section of the configuration.
109110
#
110-
# template: $env-$resolved_hostname:$port
111+
# template: $env-$resolved_hostname-$full_server_name
111112

112113
## @param database_autodiscovery - boolean - optional - default: false
113114
## Auto-discover and monitor databases. Supported for the metrics check.
@@ -165,9 +166,9 @@ instances:
165166
##
166167
## Set `ao_metrics.enabled` to true to enable collection of AlwaysOn metrics. Defaults to false.
167168
##
168-
## When `ao_metrics.enabled` is True, use `ao_metrics.availability_group` to specify the
169-
## resource group id of a specific availability group that you would like to monitor.
170-
## If no availability group is specified, then we will collect AlwaysOn metrics for all
169+
## When `ao_metrics.enabled` is True, use `ao_metrics.availability_group` to specify the
170+
## resource group id of a specific availability group that you would like to monitor.
171+
## If no availability group is specified, then we will collect AlwaysOn metrics for all
171172
## availability groups on the current replica.
172173
##
173174
## Primary replicas may emit metrics for remote secondary replicas
@@ -179,11 +180,11 @@ instances:
179180
# ao_metrics: {}
180181

181182
## @param db_fragmentation_metrics - mapping - optional
182-
## Configure collection of database fragmentation metrics.
183-
## Note these queries can be resource intensive on large datasets. Recommend to limit these via
183+
## Configure collection of database fragmentation metrics.
184+
## Note these queries can be resource intensive on large datasets. Recommend to limit these via
184185
## autodiscovery or specific database instances.
185186
##
186-
## Set `db_fragmentation_metrics.enabled` to true to enable collection of
187+
## Set `db_fragmentation_metrics.enabled` to true to enable collection of
187188
## database index fragmentation statistics. Defaults to false.
188189
##
189190
## Use `db_fragmentation_metrics.enabled_tempdb` to enable collection of database index fragmentation statistics
@@ -247,7 +248,7 @@ instances:
247248
# master_files_metrics: {}
248249

249250
## @param primary_log_shipping_metrics - mapping - optional
250-
## Configure collection of metrics for a log shipping setup. Required to run against the
251+
## Configure collection of metrics for a log shipping setup. Required to run against the
251252
## primary instance in a transaction log shipping configuration. Note that
252253
## the Datadog user needs to be present in msdb and must be added to the db_datareader role.
253254
##
@@ -257,7 +258,7 @@ instances:
257258
# primary_log_shipping_metrics: {}
258259

259260
## @param secondary_log_shipping_metrics - mapping - optional
260-
## Configure collection of metrics for a log shipping setup. Required to run against the
261+
## Configure collection of metrics for a log shipping setup. Required to run against the
261262
## secondary instance in a transaction log shipping configuration. Note that
262263
## the Datadog user needs to be present in msdb and must be added to the db_datareader role.
263264
##
@@ -277,13 +278,13 @@ instances:
277278
## @param tempdb_file_space_usage_metrics - mapping - optional
278279
## Configure collection of tempdb file space usage metrics for how space is used in tempdb data files.
279280
##
280-
## Set `tempdb_file_space_usage_metrics.enabled` to true to enable collection of
281+
## Set `tempdb_file_space_usage_metrics.enabled` to true to enable collection of
281282
## tempdb file space usage metrics. Defaults to true.
282283
#
283284
# tempdb_file_space_usage_metrics: {}
284285

285286
## @param xe_metrics - mapping - optional
286-
## Configure collection of extended events (XE) metrics.
287+
## Configure collection of extended events (XE) metrics.
287288
##
288289
## Set `xe_metrics.enabled` to true to enable collection of extended events metrics. Defaults to false.
289290
#
@@ -647,12 +648,12 @@ instances:
647648
# keep_identifier_quotation: false
648649

649650
## Configure the collection of raw query statements in query activity, execution plans, and XE events.
650-
## To collect raw query statements from XE events, set `xe_collection.query_completions.enabled` and
651+
## To collect raw query statements from XE events, set `xe_collection.query_completions.enabled` and
651652
## `xe_collection.query_errors.enabled` to `true`.
652653
## Raw query statements and execution plans may contain sensitive information (e.g., passwords)
653654
## or personally identifiable information in query text.
654-
## Enabling this option will allow the collection and ingestion of raw query statements and
655-
## execution plans into Datadog, which can then become viewable in query samples or explain plans.
655+
## Enabling this option will allow the collection and ingestion of raw query statements and
656+
## execution plans into Datadog, which can then become viewable in query samples or explain plans.
656657
## This option is disabled by default.
657658
## Note: Collection of raw query statements is currently in preview.
658659
## If you are interested in participating, please reach out to your Datadog Customer Success Manager.
@@ -813,12 +814,12 @@ instances:
813814
##
814815
## Set `query_completions.enabled` to `true` to enable the collection of query completion events.
815816
##
816-
## Use `query_completions.collection_interval` to set the interval (in seconds) for the collection of
817+
## Use `query_completions.collection_interval` to set the interval (in seconds) for the collection of
817818
## query completion events. Defaults to 10 seconds. If you intend on updating this value,
818819
## it is strongly recommended to use a consistent value throughout all SQL Server agent deployments.
819820
##
820-
## Use `query_completions.max_events` to set the maximum number of query completion events to process
821-
## per collection. Note that SQL Server's ring buffer has a maximum of 1000 events per query,
821+
## Use `query_completions.max_events` to set the maximum number of query completion events to process
822+
## per collection. Note that SQL Server's ring buffer has a maximum of 1000 events per query,
822823
## so values above 1000 will still be capped at 1000 by the database engine. Defaults to 1000.
823824
#
824825
# query_completions: {}
@@ -828,12 +829,12 @@ instances:
828829
##
829830
## Set `query_errors.enabled` to `true` to enable the collection of query error events.
830831
##
831-
## Use `query_errors.collection_interval` to set the interval (in seconds) for the collection of
832+
## Use `query_errors.collection_interval` to set the interval (in seconds) for the collection of
832833
## query error events. Defaults to 10 seconds. If you intend on updating this value,
833834
## it is strongly recommended to use a consistent value throughout all SQL Server agent deployments.
834835
##
835-
## Use `query_errors.max_events` to set the maximum number of query error events to process
836-
## per collection. Note that SQL Server's ring buffer has a maximum of 1000 events per query,
836+
## Use `query_errors.max_events` to set the maximum number of query error events to process
837+
## per collection. Note that SQL Server's ring buffer has a maximum of 1000 events per query,
837838
## so values above 1000 will still be capped at 1000 by the database engine. Defaults to 1000.
838839
#
839840
# query_errors: {}

sqlserver/datadog_checks/sqlserver/sqlserver.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
PERF_RAW_LARGE_FRACTION,
8484
SERVICE_CHECK_NAME,
8585
STATIC_INFO_ENGINE_EDITION,
86+
STATIC_INFO_FULL_SERVERNAME,
8687
STATIC_INFO_INSTANCENAME,
8788
STATIC_INFO_MAJOR_VERSION,
8889
STATIC_INFO_RDS,
@@ -340,6 +341,8 @@ def database_identifier(self):
340341
tag_dict['server_name'] = self.static_info_cache.get(STATIC_INFO_SERVERNAME)
341342
if self.static_info_cache.get(STATIC_INFO_INSTANCENAME) is not None:
342343
tag_dict['instance_name'] = self.static_info_cache.get(STATIC_INFO_INSTANCENAME)
344+
if self.static_info_cache.get(STATIC_INFO_FULL_SERVERNAME) is not None:
345+
tag_dict['full_server_name'] = self.static_info_cache.get(STATIC_INFO_FULL_SERVERNAME)
343346
self._database_identifier = template.safe_substitute(**tag_dict)
344347
return self._database_identifier
345348

@@ -394,6 +397,7 @@ def load_static_information(self):
394397
)
395398
self.static_info_cache[STATIC_INFO_SERVERNAME] = servername
396399
self.static_info_cache[STATIC_INFO_INSTANCENAME] = instancename
400+
self.static_info_cache[STATIC_INFO_FULL_SERVERNAME] = full_servername
397401

398402
self.tags.append("sqlserver_servername:{}".format(servername))
399403
self.non_internal_tags.append("sqlserver_servername:{}".format(servername))

0 commit comments

Comments
 (0)