Skip to content

Commit

Permalink
(#23551) track project id for deps events
Browse files Browse the repository at this point in the history
  • Loading branch information
drewbanin committed May 12, 2020
1 parent 8686ab9 commit b63a271
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
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'
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

0 comments on commit b63a271

Please sign in to comment.