From 191ecf2d4fc43b80bd6f858d1ec2885f8dd67815 Mon Sep 17 00:00:00 2001 From: Alik Kurdyukov Date: Wed, 20 Sep 2023 18:54:03 +0400 Subject: [PATCH 1/6] fix conflict for real not minimal snowplow tracker --- core/dbt/tracking.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/core/dbt/tracking.py b/core/dbt/tracking.py index e73a089154b..db49ed5fa00 100644 --- a/core/dbt/tracking.py +++ b/core/dbt/tracking.py @@ -10,6 +10,7 @@ import pytz import requests from snowplow_tracker import Emitter, SelfDescribingJson, Subject, Tracker +from snowplow_tracker import __version__ as snowplow_version # type: ignore from snowplow_tracker import logger as sp_logger from dbt import version as dbt_version @@ -49,17 +50,20 @@ RUN_MODEL_SPEC = "iglu:com.dbt/run_model/jsonschema/1-0-3" PLUGIN_GET_NODES = "iglu:com.dbt/plugin_get_nodes/jsonschema/1-0-0" +# workaround in case real snowplow tracker is in the env +INIT_KW_ARGS = {"buffer_size": 30} if snowplow_version == '0.0.2' else {"batch_size": 30} + class TimeoutEmitter(Emitter): def __init__(self) -> None: super().__init__( COLLECTOR_URL, protocol=COLLECTOR_PROTOCOL, - buffer_size=30, on_failure=self.handle_failure, method="post", # don't set this. byte_limit=None, + **INIT_KW_ARGS, ) @staticmethod @@ -103,11 +107,20 @@ def http_get(self, payload): emitter = TimeoutEmitter() -tracker = Tracker( - emitter, - namespace="cf", - app_id="dbt", -) + +# workaround in case real snowplow tracker is in the env +if snowplow_version == '0.0.2': + tracker = Tracker( + emitter, + namespace="cf", + app_id="dbt", + ) +else: + tracker = Tracker( + "cf", + emitters=emitter, + app_id="dbt", + ) class User: From 506ed29cfc568b78408f633204b427777d967909 Mon Sep 17 00:00:00 2001 From: Alik Kurdyukov Date: Fri, 29 Sep 2023 15:04:06 +0400 Subject: [PATCH 2/6] fix mypy errors --- 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 db49ed5fa00..5da80874ed4 100644 --- a/core/dbt/tracking.py +++ b/core/dbt/tracking.py @@ -51,7 +51,7 @@ PLUGIN_GET_NODES = "iglu:com.dbt/plugin_get_nodes/jsonschema/1-0-0" # workaround in case real snowplow tracker is in the env -INIT_KW_ARGS = {"buffer_size": 30} if snowplow_version == '0.0.2' else {"batch_size": 30} +INIT_KW_ARGS = {"buffer_size": 30} if snowplow_version == "0.0.2" else {"batch_size": 30} class TimeoutEmitter(Emitter): @@ -109,7 +109,7 @@ def http_get(self, payload): emitter = TimeoutEmitter() # workaround in case real snowplow tracker is in the env -if snowplow_version == '0.0.2': +if snowplow_version == "0.0.2": tracker = Tracker( emitter, namespace="cf", From 69aafc89f38266cc2d10a923ff4d5182e9ac813e Mon Sep 17 00:00:00 2001 From: Alik Kurdyukov Date: Sat, 30 Sep 2023 12:13:27 +0400 Subject: [PATCH 3/6] fix mypy by ignoring --- core/dbt/tracking.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/dbt/tracking.py b/core/dbt/tracking.py index 5da80874ed4..e494a411ac6 100644 --- a/core/dbt/tracking.py +++ b/core/dbt/tracking.py @@ -120,7 +120,7 @@ def http_get(self, payload): "cf", emitters=emitter, app_id="dbt", - ) + ) # type: ignore class User: From 1e158aeab2eac2050157710f1f7e78cdd73cfc44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez-Mondrag=C3=B3n?= Date: Tue, 6 Feb 2024 15:24:55 -0600 Subject: [PATCH 4/6] Add changelog note --- .changes/unreleased/Fixes-20240206-152435.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Fixes-20240206-152435.yaml diff --git a/.changes/unreleased/Fixes-20240206-152435.yaml b/.changes/unreleased/Fixes-20240206-152435.yaml new file mode 100644 index 00000000000..d5cecf873fd --- /dev/null +++ b/.changes/unreleased/Fixes-20240206-152435.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Fix conflict with newer versions of Snowplow tracker +time: 2024-02-06T15:24:35.778891-06:00 +custom: + Author: edgarrmondragon akurdyukov + Issue: "8719" From 277b3c9c21eb983b2800a7e38477a109b8398141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez-Mondrag=C3=B3n?= Date: Tue, 6 Feb 2024 15:47:58 -0600 Subject: [PATCH 5/6] Use keyword arguments in tracker initialization for compatibility Using a kwarg should make this compatible: https://github.com/snowplow/snowplow-python-tracker/commit/f2c6b3642ebc4a21606dbed01a7f714fa35c97b1 --- core/dbt/tracking.py | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/core/dbt/tracking.py b/core/dbt/tracking.py index e494a411ac6..c28be8c68ea 100644 --- a/core/dbt/tracking.py +++ b/core/dbt/tracking.py @@ -10,7 +10,7 @@ import pytz import requests from snowplow_tracker import Emitter, SelfDescribingJson, Subject, Tracker -from snowplow_tracker import __version__ as snowplow_version # type: ignore +from snowplow_tracker import __version__ as snowplow_version # type: ignore from snowplow_tracker import logger as sp_logger from dbt import version as dbt_version @@ -107,20 +107,11 @@ def http_get(self, payload): emitter = TimeoutEmitter() - -# workaround in case real snowplow tracker is in the env -if snowplow_version == "0.0.2": - tracker = Tracker( - emitter, - namespace="cf", - app_id="dbt", - ) -else: - tracker = Tracker( - "cf", - emitters=emitter, - app_id="dbt", - ) # type: ignore +tracker = Tracker( + emitters=emitter, + namespace="cf", + app_id="dbt", +) class User: From 893640480117dffcbeb1f521914e71e385623159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez-Mondrag=C3=B3n?= Date: Tue, 6 Feb 2024 16:01:54 -0600 Subject: [PATCH 6/6] Consider more specific range of compatible versions --- core/dbt/tracking.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/dbt/tracking.py b/core/dbt/tracking.py index c28be8c68ea..ff7b9e7ebb9 100644 --- a/core/dbt/tracking.py +++ b/core/dbt/tracking.py @@ -9,6 +9,7 @@ import logbook import pytz import requests +from packaging.version import Version from snowplow_tracker import Emitter, SelfDescribingJson, Subject, Tracker from snowplow_tracker import __version__ as snowplow_version # type: ignore from snowplow_tracker import logger as sp_logger @@ -50,8 +51,13 @@ RUN_MODEL_SPEC = "iglu:com.dbt/run_model/jsonschema/1-0-3" PLUGIN_GET_NODES = "iglu:com.dbt/plugin_get_nodes/jsonschema/1-0-0" +SNOWPLOW_TRACKER_VERSION = Version(snowplow_version) + # workaround in case real snowplow tracker is in the env -INIT_KW_ARGS = {"buffer_size": 30} if snowplow_version == "0.0.2" else {"batch_size": 30} +# the argument was renamed in https://github.com/snowplow/snowplow-python-tracker/commit/39fd50a3aff98a5efdd5c5c7fb5518fe4761305b +INIT_KW_ARGS = ( + {"buffer_size": 30} if SNOWPLOW_TRACKER_VERSION < Version("0.13.0") else {"batch_size": 30} +) class TimeoutEmitter(Emitter):