-
Notifications
You must be signed in to change notification settings - Fork 1.5k
DBMON-5625 Enable only_custom_queries for sqlserver #21304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
302e263
9085766
b099de0
fcb8df2
ec77aa3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Support `only_custom_queries` configuration option in sqlserver integration. | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ def __init__(self, init_config, instance, log): | |
|
||
self.proc: str = instance.get('stored_procedure') | ||
self.custom_metrics: list[dict] = init_config.get('custom_metrics', []) or [] | ||
self.only_custom_queries: bool = is_affirmative(instance.get('only_custom_queries', False)) | ||
self.ignore_missing_database = is_affirmative(instance.get("ignore_missing_database", False)) | ||
if self.ignore_missing_database: | ||
self.log.warning( | ||
|
@@ -132,6 +133,8 @@ def __init__(self, init_config, instance, log): | |
additional_tags=["raw_query_statement:enabled"] if self.collect_raw_query_statement["enabled"] else [], | ||
) | ||
|
||
self._validate_only_custom_queries(instance) | ||
|
||
def _compile_valid_patterns(self, patterns: list[str]) -> re.Pattern: | ||
valid_patterns = [] | ||
|
||
|
@@ -271,3 +274,19 @@ def _build_database_metrics_configs(self, instance): | |
if value is not None: | ||
config[key] = value | ||
return configurable_metrics | ||
|
||
def _validate_only_custom_queries(self, instance): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's wait for @sethsamuel to return from PTO Monday on this one. We're in the process of reworking config handling / validation for surfacing agent health work. Want to make sure this will play nice with the pattern we're working towards |
||
# Warn about any metric-collecting options that are enabled | ||
if self.only_custom_queries: | ||
if self.dbm_enabled: | ||
self.log.warning( | ||
"only_custom_queries is enabled with DBM. if you don't want to collect DBM metrics, set dbm: false" | ||
) | ||
|
||
if self.proc: | ||
self.log.warning( | ||
"`stored_procedure` is deprecated. to run custom queries, add to the `custom_queries` configuration" | ||
) | ||
|
||
if instance.get('custom_queries', []) == []: | ||
self.log.warning("only_custom_queries is enabled but no custom queries are defined") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -506,6 +506,36 @@ def test_custom_queries(aggregator, dd_run_check, instance_docker, custom_query, | |
aggregator.assert_metric(metric_name, **kwargs) | ||
|
||
|
||
@pytest.mark.integration | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm guessing when store procedure checks are enabled and when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If stored procedure checks are enabled and I think it would be good to validate these things in the config init though; I can add those situations as warning logs. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also, will definitely add tests for that regardless There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah I think we should definitely do that. Thank you! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made the config validation change! I added a test for log output given a certain config, rather than adding extra |
||
@pytest.mark.usefixtures('dd_environment') | ||
def test_only_custom_queries(aggregator, dd_run_check, instance_docker): | ||
"""Test that only_custom_queries=True skips regular metrics but executes custom queries.""" | ||
instance = copy(instance_docker) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll clean this up in a follow up since it's already done all over but just want to point out that this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes sense! I guess updating this to deepcopy() right now wouldn't make much of a difference until we're resetting the instance between tests? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah it's not going to make much of a difference atm and is already done elsewhere. Easier to clean it up and avoid future footguns in a follow up! |
||
instance['only_custom_queries'] = True | ||
instance['custom_queries'] = [ | ||
{ | ||
'query': "SELECT 42 as custom_value", | ||
'columns': [{'name': 'custom_value', 'type': 'gauge'}], | ||
'tags': ['test:only_custom'], | ||
} | ||
] | ||
instance['procedure_metrics'] = {'enabled': False} | ||
|
||
check = SQLServer(CHECK_NAME, {}, [instance]) | ||
dd_run_check(check) | ||
|
||
# Verify that custom query metrics ARE collected | ||
instance_tags = check._config.tags + [ | ||
"database_hostname:{}".format("stubbed.hostname"), | ||
"database_instance:{}".format("stubbed.hostname"), | ||
"ddagenthostname:{}".format("stubbed.hostname"), | ||
"dd.internal.resource:database_instance:{}".format("stubbed.hostname"), | ||
"sqlserver_servername:{}".format(check.static_info_cache.get(STATIC_INFO_SERVERNAME)), | ||
] | ||
aggregator.assert_metric('sqlserver.custom_value', value=42, tags=instance_tags + ['test:only_custom'], count=1) | ||
aggregator.assert_all_metrics_covered() | ||
|
||
|
||
@pytest.mark.integration | ||
@pytest.mark.usefixtures('dd_environment') | ||
def test_load_static_information(aggregator, dd_run_check, instance_docker): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a new config option. We need to change the changelog to
added
and notfixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's technically not a new config option since it exists in the sqlserver conf.yaml already & customers were reporting that it doesnt work as expected. But it's definitely new functionality if it works now so I see how
added
makes more senseThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see yeah it looks like it was added to a bunch of configs in the past, but I don't see how it was ever actually wired up. I'm fine with
fixed
in that caseThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope it was never really wired up. that config was pulled in at the same place
custom_queries
was pulled in, not in the actual integration but by the QueryManager here. so, it was being referenced but it didnt do anything since we dont use the QueryManager in the intended way