Skip to content
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

snowflake disable generic tags #9854

Merged
merged 29 commits into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5edc487
Transform generic tags
hithwen Aug 5, 2021
b96708b
Add config option
hithwen Aug 5, 2021
9536ca7
Disable generic tags
hithwen Aug 5, 2021
2955964
Fix config
hithwen Aug 5, 2021
0030e5d
Merge branch 'js/generic-tags-feature' into js/snowflake-disable-gene…
hithwen Aug 5, 2021
1709858
Fix config
hithwen Aug 5, 2021
e332ec8
Sync models
hithwen Aug 6, 2021
63fce14
Merge branch 'js/generic-tags-feature' into js/snowflake-disable-gene…
hithwen Aug 6, 2021
e0b8244
Sync config
hithwen Aug 6, 2021
3c74c98
Cache config in init
hithwen Aug 6, 2021
6b47fbc
Override variable instead of config dict
hithwen Aug 6, 2021
9ae9150
Merge branch 'js/generic-tags-feature' into js/snowflake-disable-gene…
hithwen Aug 6, 2021
08e0396
Merge remote-tracking branch 'origin/master' into js/generic-tags-fea…
hithwen Aug 18, 2021
48b1885
Small perf improvement
hithwen Aug 18, 2021
9e0e1f0
Merge remote-tracking branch 'origin/master' into js/generic-tags-fea…
hithwen Aug 23, 2021
39f1e4c
Apply PR review
hithwen Aug 23, 2021
e29cab7
Update config models
hithwen Aug 23, 2021
b89b09f
Merge branch 'js/generic-tags-feature' into js/snowflake-disable-gene…
hithwen Aug 23, 2021
084add6
Added unit test
hithwen Aug 23, 2021
019a1cf
Merge remote-tracking branch 'origin/master' into js/snowflake-disabl…
hithwen Sep 9, 2021
cdbde1b
Override _normalize_tags_type to always emit non generic tags
hithwen Sep 9, 2021
8406fea
Remove generic tags check
hithwen Sep 9, 2021
6d434fe
Fix super call
hithwen Sep 9, 2021
d3d4259
Add unit test
hithwen Sep 9, 2021
0d58309
Improve test
hithwen Sep 9, 2021
7c08606
Bump base requirement
hithwen Sep 9, 2021
7f591ea
Merge remote-tracking branch 'origin/master' into js/snowflake-disabl…
hithwen Sep 13, 2021
4655b82
Add unit test
hithwen Sep 13, 2021
a5f1eac
Update test_unit.py
hithwen Sep 13, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions snowflake/assets/configuration/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,5 @@ files:
min_collection_interval.display_default: 3600
min_collection_interval.value.example: 3600
min_collection_interval.enabled: 3600
disable_generic_tags.hidden: False
disable_generic_tags.enabled: True
20 changes: 19 additions & 1 deletion snowflake/datadog_checks/snowflake/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import snowflake.connector as sf

from datadog_checks.base import AgentCheck, ConfigurationError
from datadog_checks.base import AgentCheck, ConfigurationError, to_native_string
from datadog_checks.base.utils.db import QueryManager

from . import queries
Expand Down Expand Up @@ -156,3 +156,21 @@ def _collect_version(self):
else:
if version:
self.set_metadata('version', version)

# override
def _normalize_tags_type(self, tags, device_name=None, metric_name=None):
if self.disable_generic_tags:
return super(SnowflakeCheck, self)._normalize_tags_type(tags, device_name, metric_name)

# If disable_generic_tags is not enabled, for each generic tag we emmit both the generic and the non generic
# version to ease transition.
normalized_tags = []
for tag in tags:
if tag is not None:
try:
tag = to_native_string(tag)
except UnicodeError:
self.log.warning('Encoding error with tag `%s` for metric `%s`, ignoring tag', tag, metric_name)
continue
normalized_tags.extend(list({tag, self.degeneralise_tag(tag)}))
return normalized_tags
6 changes: 6 additions & 0 deletions snowflake/datadog_checks/snowflake/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,9 @@ instances:
## This is useful for cluster-level checks.
#
# empty_default_hostname: false

## @param disable_generic_tags - boolean - optional - default: false
## Generic tags such as `cluster` will be replaced by <integration_name>_cluster to avoid
## getting mixed with other integraton tags.
#
disable_generic_tags: true
2 changes: 1 addition & 1 deletion snowflake/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_dependencies():
return f.readlines()


CHECKS_BASE_REQ = 'datadog-checks-base>=20.1.0'
CHECKS_BASE_REQ = 'datadog-checks-base>=21.2.0'


setup(
Expand Down
2 changes: 2 additions & 0 deletions snowflake/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
'database': 'SNOWFLAKE',
'schema': 'ACCOUNT_USAGE',
'role': 'ACCOUNTADMIN',
'disable_generic_tags': True,
}
OAUTH_INSTANCE = {
'user': 'testuser',
Expand All @@ -24,6 +25,7 @@
'role': 'ACCOUNTADMIN',
'authenticator': 'oauth',
'token': 'testtoken',
'disable_generic_tags': True,
}

EXPECTED_TAGS = ['account:test_acct.us-central1.gcp']
Expand Down
4 changes: 2 additions & 2 deletions snowflake/tests/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ def test_mock_data(dd_agent_check, datadog_agent, instance):

aggregator.assert_metric(
'snowflake.billing.cloud_service.sum',
tags=EXPECTED_TAGS + ['service_type:WAREHOUSE_METERING', 'service:COMPUTE_WH'],
tags=EXPECTED_TAGS + ['service_type:WAREHOUSE_METERING', 'snowflake_service:COMPUTE_WH'],
)
aggregator.assert_metric(
'snowflake.billing.cloud_service.avg',
tags=EXPECTED_TAGS + ['service_type:WAREHOUSE_METERING', 'service:COMPUTE_WH'],
tags=EXPECTED_TAGS + ['service_type:WAREHOUSE_METERING', 'snowflake_service:COMPUTE_WH'],
)
aggregator.assert_metric('snowflake.billing.total_credit.sum')
aggregator.assert_metric('snowflake.billing.total_credit.avg')
Expand Down
2 changes: 1 addition & 1 deletion snowflake/tests/test_snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_credit_usage_metrics(dd_run_check, aggregator, instance):
Decimal('1.066997500000'),
)
]
expected_tags = EXPECTED_TAGS + ['service_type:WAREHOUSE_METERING', 'service:COMPUTE_WH']
expected_tags = EXPECTED_TAGS + ['service_type:WAREHOUSE_METERING', 'snowflake_service:COMPUTE_WH']
with mock.patch('datadog_checks.snowflake.SnowflakeCheck.execute_query_raw', return_value=expected_credit_usage):
check = SnowflakeCheck(CHECK_NAME, {}, [instance])
check._conn = mock.MagicMock()
Expand Down
20 changes: 19 additions & 1 deletion snowflake/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from datadog_checks.snowflake import SnowflakeCheck, queries

from .common import CHECK_NAME
from .common import CHECK_NAME, EXPECTED_TAGS

PROXY_CONFIG = {'http': 'http_host', 'https': 'https_host', 'no_proxy': 'uri1,uri2;uri3,uri4'}
INVALID_PROXY = {'http': 'unused', 'https': 'unused', 'no_proxy': 'unused'}
Expand Down Expand Up @@ -204,3 +204,21 @@ def test_metric_group_exceptions(instance):
check.log.warning.assert_called_once_with(
"Invalid metric_groups found in snowflake conf.yaml: fake.metric.group"
)


def test_emit_generic_and_non_generic_tags_by_default(instance):
instance = copy.deepcopy(instance)
instance['disable_generic_tags'] = False
check = SnowflakeCheck(CHECK_NAME, {}, [instance])
tags = EXPECTED_TAGS + ['service_type:WAREHOUSE_METERING', 'service:COMPUTE_WH']
normalised_tags = tags + ['snowflake_service:COMPUTE_WH']
assert set(normalised_tags) == set(check._normalize_tags_type(tags))


def test_emit_non_generic_tags_when_disabled(instance):
instance = copy.deepcopy(instance)
instance['disable_generic_tags'] = True
check = SnowflakeCheck(CHECK_NAME, {}, [instance])
tags = EXPECTED_TAGS + ['service_type:WAREHOUSE_METERING', 'service:COMPUTE_WH']
normalised_tags = EXPECTED_TAGS + ['service_type:WAREHOUSE_METERING', 'snowflake_service:COMPUTE_WH']
assert set(normalised_tags) == set(check._normalize_tags_type(tags))
2 changes: 0 additions & 2 deletions snowflake/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,3 @@ passenv =
commands =
pip install -r requirements.in
pytest -v {posargs}
setenv =
DDEV_SKIP_GENERIC_TAGS_CHECK=true