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

Track project id for deps events #2429

Merged
merged 2 commits into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 16 additions & 9 deletions core/dbt/task/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Copy link
Contributor

@clrcrl clrcrl Jun 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
version = 'local'
package_name = dbt.utils.md5(package_name)
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)
Expand Down
10 changes: 8 additions & 2 deletions core/dbt/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 13 additions & 0 deletions test/integration/033_event_tracking_test/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down