From b63a271d5582892750ec18ec2f3d33bb09d19e7a Mon Sep 17 00:00:00 2001 From: Drew Banin Date: Mon, 11 May 2020 16:43:51 -0400 Subject: [PATCH 1/2] (#23551) track project id for deps events --- CHANGELOG.md | 3 +++ core/dbt/task/deps.py | 25 ++++++++++++------- core/dbt/tracking.py | 10 ++++++-- .../033_event_tracking_test/test_events.py | 13 ++++++++++ 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59f0a3bbbc1..4e2e4ba857c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,9 @@ - Fix for making schema tests work for community plugin [dbt-sqlserver](https://github.com/mikaelene/dbt-sqlserver) [#2414](https://github.com/fishtown-analytics/dbt/pull/2414) - Fix a bug where quoted uppercase schemas on snowflake were not processed properly during cache building. ([#2403](https://github.com/fishtown-analytics/dbt/issues/2403), [#2411](https://github.com/fishtown-analytics/dbt/pull/2411)) +### Under the hood +- Track distinct project hashes in anonymous usage metrics for package downloads ([#2351](https://github.com/fishtown-analytics/dbt/issues/2351), [#2429](https://github.com/fishtown-analytics/dbt/pull/2429)) + Contributors: - [@azhard](https://github.com/azhard) [#2413](https://github.com/fishtown-analytics/dbt/pull/2413) - [@mikaelene](https://github.com/mikaelene) [#2414](https://github.com/fishtown-analytics/dbt/pull/2414) diff --git a/core/dbt/task/deps.py b/core/dbt/task/deps.py index 94522e588b6..1b6cc325292 100644 --- a/core/dbt/task/deps.py +++ b/core/dbt/task/deps.py @@ -23,16 +23,23 @@ def __init__(self, args, config: UnsetProfileConfig): def track_package_install( self, package_name: str, source_type: str, version: str ) -> None: - version = 'local' if source_type == 'local' else version + # Hub packages do not need to be hashed, as they are public + # Use the string 'local' for local package versions + if source_type == 'local': + version = 'local' + elif source_type != 'hub': + package_name = dbt.utils.md5(package_name) + version = dbt.utils.md5(version) - h_package_name = dbt.utils.md5(package_name) - h_version = dbt.utils.md5(version) - - dbt.tracking.track_package_install({ - "name": h_package_name, - "source": source_type, - "version": h_version - }) + dbt.tracking.track_package_install( + self.config, + self.config.args, + { + "name": package_name, + "source": source_type, + "version": version + } + ) def run(self): system.make_directory(self.config.modules_path) diff --git a/core/dbt/tracking.py b/core/dbt/tracking.py index f42c22d404a..8d7dbc2f24e 100644 --- a/core/dbt/tracking.py +++ b/core/dbt/tracking.py @@ -299,11 +299,17 @@ def track_rpc_request(options): ) -def track_package_install(options): - context = [SelfDescribingJson(PACKAGE_INSTALL_SPEC, options)] +def track_package_install(config, args, options): assert active_user is not None, \ 'Cannot track package installs when active user is None' + invocation_data = get_invocation_context(active_user, config, args) + + context = [ + SelfDescribingJson(INVOCATION_SPEC, invocation_data), + SelfDescribingJson(PACKAGE_INSTALL_SPEC, options) + ] + track( active_user, category="dbt", diff --git a/test/integration/033_event_tracking_test/test_events.py b/test/integration/033_event_tracking_test/test_events.py index acb3312333c..d0c3b487966 100644 --- a/test/integration/033_event_tracking_test/test_events.py +++ b/test/integration/033_event_tracking_test/test_events.py @@ -224,6 +224,19 @@ def test__postgres_event_tracking_compile(self): @use_profile("postgres") def test__postgres_event_tracking_deps(self): package_context = [ + { + 'schema': 'iglu:com.dbt/invocation/jsonschema/1-0-1', + 'data': { + 'project_id': '098f6bcd4621d373cade4e832627b4f6', + 'user_id': ANY, + 'invocation_id': ANY, + 'version': ANY, + 'command': 'deps', + 'run_type': 'regular', + 'options': None, + 'adapter_type': 'postgres' + } + }, { 'schema': 'iglu:com.dbt/package_install/jsonschema/1-0-0', 'data': { From 2a8940415defeee4a2b8964e6a905328662e5c60 Mon Sep 17 00:00:00 2001 From: Drew Banin Date: Mon, 11 May 2020 20:57:00 -0400 Subject: [PATCH 2/2] quiet new pep8 check --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index bb0e2296675..b607cc96a84 100644 --- a/tox.ini +++ b/tox.ini @@ -6,7 +6,7 @@ requires = tox-pip-version [testenv:flake8] basepython = python3.6 -commands = /bin/bash -c '$(which flake8) --select=E,W,F --ignore=W504 core/dbt plugins/*/dbt' +commands = /bin/bash -c '$(which flake8) --select=E,W,F --ignore=W504,E741 core/dbt plugins/*/dbt' deps = -r ./dev_requirements.txt