diff --git a/hq_superset/metrics.py b/hq_superset/metrics.py new file mode 100644 index 0000000..13d359e --- /dev/null +++ b/hq_superset/metrics.py @@ -0,0 +1,10 @@ +from typing import Dict, List +from superset_config import SERVER_ENVIRONMENT + + +def get_tags(tag_values: Dict[str, str]) -> List[str]: + tag_values.update({"env": SERVER_ENVIRONMENT}) + + return [ + f'{name}:{value}' for name, value in tag_values.items() + ] diff --git a/hq_superset/models.py b/hq_superset/models.py index 904c9df..a81d7b7 100644 --- a/hq_superset/models.py +++ b/hq_superset/models.py @@ -6,6 +6,7 @@ OAuth2TokenMixin, ) from cryptography.fernet import MultiFernet +from datadog import statsd from superset import db from superset_config import SKIP_DATASET_CHANGE_FOR_DOMAINS @@ -16,6 +17,7 @@ get_fernet_keys, get_hq_database, ) +from hq_superset.metrics import get_tags import logging logger = logging.getLogger(__name__) @@ -34,6 +36,10 @@ class DataSetChange: data: list[dict[str, Any]] def update_dataset(self): + with statsd.timed('cca.dataset_change.timer', tags=get_tags({"datasource": self.data_source_id})): + self._update_dataset() + + def _update_dataset(self): """ Updates a dataset with ``self.data``. diff --git a/hq_superset/tests/config_for_tests.py b/hq_superset/tests/config_for_tests.py index 46f23c2..f5c2737 100644 --- a/hq_superset/tests/config_for_tests.py +++ b/hq_superset/tests/config_for_tests.py @@ -68,3 +68,5 @@ CUSTOM_SECURITY_MANAGER = oauth.CommCareSecurityManager USER_DOMAIN_ROLE_EXPIRY = 60 # minutes SKIP_DATASET_CHANGE_FOR_DOMAINS = [] + +SERVER_ENVIRONMENT = "test" diff --git a/setup.py b/setup.py index 8c7ad79..3dcccee 100644 --- a/setup.py +++ b/setup.py @@ -23,6 +23,7 @@ 'Werkzeug==2.3.3', 'WTForms==2.3.3', 'ddtrace==2.17.0rc2', + 'datadog==0.50.2', ], extras_require={ 'dev': [ diff --git a/superset_config.example.py b/superset_config.example.py index 809e0e7..fbd4e45 100644 --- a/superset_config.example.py +++ b/superset_config.example.py @@ -191,3 +191,5 @@ class CeleryConfig: USER_DOMAIN_ROLE_EXPIRY = 60 # minutes SKIP_DATASET_CHANGE_FOR_DOMAINS = [] + +SERVER_ENVIRONMENT = 'changeme' # staging, production, etc. \ No newline at end of file