From c63fc07267097a6d76667211f02290eeb46ef191 Mon Sep 17 00:00:00 2001 From: Ian Knox Date: Mon, 27 Mar 2023 19:32:32 -0500 Subject: [PATCH 1/5] replaced tracking events removed in click work --- core/dbt/task/base.py | 9 +++++++++ core/dbt/tracking.py | 46 ++++++++++++++++++++++++++++++++++--------- events/README.md | 3 +++ 3 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 events/README.md diff --git a/core/dbt/task/base.py b/core/dbt/task/base.py index 5aa12b05ca8..a21cfcdc164 100644 --- a/core/dbt/task/base.py +++ b/core/dbt/task/base.py @@ -76,6 +76,15 @@ def __init__(self, args, config, project=None): self.args = args self.config = config self.project = config if isinstance(config, Project) else project + breakpoint() + if dbt.tracking.active_user is not None: + dbt.tracking.track_project_id({"project_id": self.project.hashed_name()}) + dbt.tracking.track_adapter_info( + { + "adapter_type": getattr(self.config.credentials, "type", None), + "adapter_unique_id": self.config.credentials.hashed_unique_field(), + } + ) @classmethod def pre_init_hook(cls, args): diff --git a/core/dbt/tracking.py b/core/dbt/tracking.py index f488babe002..8c1ef50c959 100644 --- a/core/dbt/tracking.py +++ b/core/dbt/tracking.py @@ -30,20 +30,22 @@ COLLECTOR_URL = "fishtownanalytics.sinter-collect.com" COLLECTOR_PROTOCOL = "https" +DBT_INVOCATION_ENV = "DBT_INVOCATION_ENV" -INVOCATION_SPEC = "iglu:com.dbt/invocation/jsonschema/1-0-2" -PLATFORM_SPEC = "iglu:com.dbt/platform/jsonschema/1-0-0" -RUN_MODEL_SPEC = "iglu:com.dbt/run_model/jsonschema/1-0-2" -INVOCATION_ENV_SPEC = "iglu:com.dbt/invocation_env/jsonschema/1-0-0" -PACKAGE_INSTALL_SPEC = "iglu:com.dbt/package_install/jsonschema/1-0-0" -RPC_REQUEST_SPEC = "iglu:com.dbt/rpc_request/jsonschema/1-0-1" +ADAPTER_INFO_SPEC = "iglu:com.dbt/adapter_info/jsonschema/1-0-0" DEPRECATION_WARN_SPEC = "iglu:com.dbt/deprecation_warn/jsonschema/1-0-0" -LOAD_ALL_TIMING_SPEC = "iglu:com.dbt/load_all_timing/jsonschema/1-0-3" -RESOURCE_COUNTS = "iglu:com.dbt/resource_counts/jsonschema/1-0-0" EXPERIMENTAL_PARSER = "iglu:com.dbt/experimental_parser/jsonschema/1-0-0" +INVOCATION_ENV_SPEC = "iglu:com.dbt/invocation_env/jsonschema/1-0-0" +INVOCATION_SPEC = "iglu:com.dbt/invocation/jsonschema/1-0-2" +LOAD_ALL_TIMING_SPEC = "iglu:com.dbt/load_all_timing/jsonschema/1-0-3" +PACKAGE_INSTALL_SPEC = "iglu:com.dbt/package_install/jsonschema/1-0-0" PARTIAL_PARSER = "iglu:com.dbt/partial_parser/jsonschema/1-0-1" +PLATFORM_SPEC = "iglu:com.dbt/platform/jsonschema/1-0-0" +PROJECT_ID_SPEC = "iglu:com.dbt/project_id/jsonschema/1-0-0" +RESOURCE_COUNTS = "iglu:com.dbt/resource_counts/jsonschema/1-0-0" +RPC_REQUEST_SPEC = "iglu:com.dbt/rpc_request/jsonschema/1-0-1" RUNNABLE_TIMING = "iglu:com.dbt/runnable/jsonschema/1-0-0" -DBT_INVOCATION_ENV = "DBT_INVOCATION_ENV" +RUN_MODEL_SPEC = "iglu:com.dbt/run_model/jsonschema/1-0-2" class TimeoutEmitter(Emitter): @@ -210,6 +212,32 @@ def track(user, *args, **kwargs): fire_event(SendEventFailure()) +def track_project_id(options): + assert active_user is not None, "Cannot track project_id when active user is None" + context = [SelfDescribingJson(PROJECT_ID_SPEC, options)] + + track( + active_user, + category="dbt", + action="project_id", + label=get_invocation_id(), + context=context, + ) + + +def track_adapter_info(options): + assert active_user is not None, "Cannot track adapter_info when active user is None" + context = [SelfDescribingJson(ADAPTER_INFO_SPEC, options)] + + track( + active_user, + category="dbt", + action="adapter_info", + label=get_invocation_id(), + context=context, + ) + + def track_invocation_start(invocation_context): data = {"progress": "start", "result_type": None, "result": None} data.update(invocation_context) diff --git a/events/README.md b/events/README.md new file mode 100644 index 00000000000..53bcc2b4078 --- /dev/null +++ b/events/README.md @@ -0,0 +1,3 @@ +The events outlined here exist to support "very very old versions of dbt-core, which expected to look directly at the HEAD branch of this github repo to find validation schemas". + +Eventually these should go away (see https://github.com/dbt-labs/dbt-core/issues/7228) From c1c2f5cb7a6ece1504bfb97a550ef224eb9897f0 Mon Sep 17 00:00:00 2001 From: Ian Knox Date: Mon, 27 Mar 2023 19:35:12 -0500 Subject: [PATCH 2/5] remove errant breakpoint --- core/dbt/task/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/dbt/task/base.py b/core/dbt/task/base.py index a21cfcdc164..19beabb11c5 100644 --- a/core/dbt/task/base.py +++ b/core/dbt/task/base.py @@ -76,7 +76,7 @@ def __init__(self, args, config, project=None): self.args = args self.config = config self.project = config if isinstance(config, Project) else project - breakpoint() + if dbt.tracking.active_user is not None: dbt.tracking.track_project_id({"project_id": self.project.hashed_name()}) dbt.tracking.track_adapter_info( From 913595244711bcef754fcb553836a2ab0d45f53e Mon Sep 17 00:00:00 2001 From: Ian Knox Date: Mon, 27 Mar 2023 19:39:09 -0500 Subject: [PATCH 3/5] changelog --- .changes/unreleased/Fixes-20230327-193850.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Fixes-20230327-193850.yaml diff --git a/.changes/unreleased/Fixes-20230327-193850.yaml b/.changes/unreleased/Fixes-20230327-193850.yaml new file mode 100644 index 00000000000..5d0e5de3998 --- /dev/null +++ b/.changes/unreleased/Fixes-20230327-193850.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Recreates missing tracking events +time: 2023-03-27T19:38:50.657292-05:00 +custom: + Author: iknox-fa + Issue: 6097 6098 From 278bdaa5f6713a35239c93237ca768cd8aaa7572 Mon Sep 17 00:00:00 2001 From: Ian Knox Date: Tue, 28 Mar 2023 10:48:58 -0500 Subject: [PATCH 4/5] updated for missing creds/projects --- core/dbt/task/base.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/core/dbt/task/base.py b/core/dbt/task/base.py index 19beabb11c5..8946f627293 100644 --- a/core/dbt/task/base.py +++ b/core/dbt/task/base.py @@ -78,11 +78,26 @@ def __init__(self, args, config, project=None): self.project = config if isinstance(config, Project) else project if dbt.tracking.active_user is not None: - dbt.tracking.track_project_id({"project_id": self.project.hashed_name()}) + + # N.B. The none checking below is largely due to incomplete projects used in the testing + # and to support tasks that don't require a complete project or a complete config (debug, init). + project_id = None if self.project is None else self.project.hashed_name() + adapter_type = ( + getattr(self.config.credentials, "type", None) + if hasattr(self.config, "credentials") + else None + ) + adapter_unique_id = ( + self.config.credentials.hashed_unique_field() + if hasattr(self.config, "credentials") + else None + ) + + dbt.tracking.track_project_id({"project_id": project_id}) dbt.tracking.track_adapter_info( { - "adapter_type": getattr(self.config.credentials, "type", None), - "adapter_unique_id": self.config.credentials.hashed_unique_field(), + "adapter_type": adapter_type, + "adapter_unique_id": adapter_unique_id, } ) From 4f88a0ed2c36fb07379884147fbece5cc839728c Mon Sep 17 00:00:00 2001 From: Ian Knox Date: Tue, 28 Mar 2023 12:57:49 -0500 Subject: [PATCH 5/5] updated schema versions --- core/dbt/tracking.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/dbt/tracking.py b/core/dbt/tracking.py index 8c1ef50c959..594ec952c30 100644 --- a/core/dbt/tracking.py +++ b/core/dbt/tracking.py @@ -32,7 +32,7 @@ COLLECTOR_PROTOCOL = "https" DBT_INVOCATION_ENV = "DBT_INVOCATION_ENV" -ADAPTER_INFO_SPEC = "iglu:com.dbt/adapter_info/jsonschema/1-0-0" +ADAPTER_INFO_SPEC = "iglu:com.dbt/adapter_info/jsonschema/1-0-1" DEPRECATION_WARN_SPEC = "iglu:com.dbt/deprecation_warn/jsonschema/1-0-0" EXPERIMENTAL_PARSER = "iglu:com.dbt/experimental_parser/jsonschema/1-0-0" INVOCATION_ENV_SPEC = "iglu:com.dbt/invocation_env/jsonschema/1-0-0" @@ -41,7 +41,7 @@ PACKAGE_INSTALL_SPEC = "iglu:com.dbt/package_install/jsonschema/1-0-0" PARTIAL_PARSER = "iglu:com.dbt/partial_parser/jsonschema/1-0-1" PLATFORM_SPEC = "iglu:com.dbt/platform/jsonschema/1-0-0" -PROJECT_ID_SPEC = "iglu:com.dbt/project_id/jsonschema/1-0-0" +PROJECT_ID_SPEC = "iglu:com.dbt/project_id/jsonschema/1-0-1" RESOURCE_COUNTS = "iglu:com.dbt/resource_counts/jsonschema/1-0-0" RPC_REQUEST_SPEC = "iglu:com.dbt/rpc_request/jsonschema/1-0-1" RUNNABLE_TIMING = "iglu:com.dbt/runnable/jsonschema/1-0-0"