-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Snowplow tracking for behavior flags (#10721)
* add behavior deprecation snowplow callback * update tests for new callback * update test input with the new required field
- Loading branch information
1 parent
054c6fd
commit d182d06
Showing
5 changed files
with
92 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Under the Hood | ||
body: Add Snowplow tracking for behavior flag deprecations | ||
time: 2024-09-11T16:27:30.293832-04:00 | ||
custom: | ||
Author: mikealfare | ||
Issue: "10552" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import pytest | ||
|
||
from dbt.tracking import ( | ||
disable_tracking, | ||
initialize_from_flags, | ||
track_behavior_change_warn, | ||
) | ||
from dbt_common.behavior_flags import Behavior | ||
from dbt_common.events.event_manager_client import ( | ||
add_callback_to_manager, | ||
cleanup_event_logger, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def snowplow_tracker(mocker): | ||
# initialize `active_user` without writing the cookie to disk | ||
initialize_from_flags(True, "") | ||
mocker.patch("dbt.tracking.User.set_cookie").return_value = {"id": 42} | ||
|
||
# add the relevant callback to the event manager | ||
add_callback_to_manager(track_behavior_change_warn) | ||
|
||
# don't make a call, catch the request | ||
snowplow_tracker = mocker.patch("dbt.tracking.tracker.track_struct_event") | ||
|
||
yield snowplow_tracker | ||
|
||
# teardown | ||
cleanup_event_logger() | ||
disable_tracking() | ||
|
||
|
||
def test_false_evaluation_triggers_snowplow_tracking(snowplow_tracker): | ||
behavior = Behavior( | ||
[{"name": "my_flag", "default": False, "description": "This is a false flag."}], {} | ||
) | ||
if behavior.my_flag: | ||
# trigger a False evaluation | ||
assert False, "This flag should evaluate to false and skip this line" | ||
assert snowplow_tracker.called | ||
|
||
|
||
def test_true_evaluation_does_not_trigger_snowplow_tracking(snowplow_tracker): | ||
behavior = Behavior( | ||
[{"name": "my_flag", "default": True, "description": "This is a true flag."}], {} | ||
) | ||
if behavior.my_flag: | ||
pass | ||
else: | ||
# trigger a True evaluation | ||
assert False, "This flag should evaluate to false and skip this line" | ||
assert not snowplow_tracker.called | ||
|
||
|
||
def test_false_evaluation_does_not_trigger_snowplow_tracking_when_disabled(snowplow_tracker): | ||
disable_tracking() | ||
|
||
behavior = Behavior( | ||
[{"name": "my_flag", "default": False, "description": "This is a false flag."}], {} | ||
) | ||
if behavior.my_flag: | ||
# trigger a False evaluation | ||
assert False, "This flag should evaluate to false and skip this line" | ||
assert not snowplow_tracker.called |