-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add Snowplow tracking for behavior flags #10721
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c4b411f
changelog
mikealfare 407001c
add behavior deprecation snowplow callback
mikealfare b3bf1a1
add behavior deprecation snowplow callback
mikealfare ec049a9
add testing
mikealfare f49ae26
add testing
mikealfare 12f6436
update tests for new callback
mikealfare 2678087
update names to reflect the new event name in dbt-common
mikealfare 1e20bd8
update test input with the new required field
mikealfare File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,59 @@ | ||
import pytest | ||
|
||
from dbt.tracking import ( | ||
disable_tracking, | ||
initialize_from_flags, | ||
track_behavior_deprecation_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_deprecation_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}], {}) | ||
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}], {}) | ||
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}], {}) | ||
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want snowplow tracking for behavior flags regardless of the log setting. It should only be turned off when the user turns off tracking. However, this is handled outside of the event manager. The downside is that tests need to be updated for this, though it appears to only be one test.