-
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
make tracking use the profile directory, and suppress errors (#1180) #1186
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,6 @@ | |
COLLECTOR_URL = "fishtownanalytics.sinter-collect.com" | ||
COLLECTOR_PROTOCOL = "https" | ||
|
||
COOKIE_PATH = os.path.join(os.path.expanduser('~'), '.dbt/.user.yml') | ||
|
||
INVOCATION_SPEC = 'iglu:com.dbt/invocation/jsonschema/1-0-0' | ||
PLATFORM_SPEC = 'iglu:com.dbt/platform/jsonschema/1-0-0' | ||
RUN_MODEL_SPEC = 'iglu:com.dbt/run_model/jsonschema/1-0-0' | ||
|
@@ -35,8 +33,9 @@ | |
|
||
class User(object): | ||
|
||
def __init__(self): | ||
def __init__(self, cookie_dir): | ||
self.do_not_track = True | ||
self.cookie_dir = cookie_dir | ||
|
||
self.id = None | ||
self.invocation_id = str(uuid.uuid4()) | ||
|
@@ -45,6 +44,10 @@ def __init__(self): | |
def state(self): | ||
return "do not track" if self.do_not_track else "tracking" | ||
|
||
@property | ||
def cookie_path(self): | ||
return os.path.join(self.cookie_dir, '.user.yml') | ||
|
||
def initialize(self): | ||
self.do_not_track = False | ||
|
||
|
@@ -56,21 +59,20 @@ def initialize(self): | |
tracker.set_subject(subject) | ||
|
||
def set_cookie(self): | ||
cookie_dir = os.path.dirname(COOKIE_PATH) | ||
user = {"id": str(uuid.uuid4())} | ||
|
||
dbt.clients.system.make_directory(cookie_dir) | ||
dbt.clients.system.make_directory(self.cookie_dir) | ||
|
||
with open(COOKIE_PATH, "w") as fh: | ||
with open(self.cookie_path, "w") as fh: | ||
yaml.dump(user, fh) | ||
|
||
return user | ||
|
||
def get_cookie(self): | ||
if not os.path.isfile(COOKIE_PATH): | ||
if not os.path.isfile(self.cookie_path): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it possible to defer the creation of this cookie until the profile is loaded? With the current implementation, dbt will create a cookie if it doesn't exist in the specified profile directory. That means if you errantly specify an incorrect profile dir, dbt will litter .user.yml files all over the place. This won't affect tracking and i don't think it will cause any problems for the end-user, but it's not so polite :) I figure we can only create the cookie if dbt is able to find and load the profiles.yml file. To be sure: I tested this out, and dbt does not send events if the profiles.yml file is unloadable, which is good. This is mostly a cosmetic/tidyness comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's possible, but not easy - I would estimate it at a few days of work, as a ton of main.py would have to be refactored. We start doing tracking things before we load a profile - really before we ever even start inspecting which command was passed, so we don't even know if we will load a profile! And sometimes, in order to load a profile we actually need to load the project first so we can figure out the profile name, etc... Accordingly, per our slack conversation, I'm going to merge this as-is - we should get this fix in to grace-kelly, even if it's a bit less than optimal. I am very enthusiastic about the idea of refactoring main.py to support this behavior - currently even answering the question "does this command require profile, project, both or neither" requires checking multiple functions and carefully walking through behavior, and I don't like that. We could also handle the issues raised in #1189 when/if we do that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. totally agree @beckjake, thanks for the color. Ship it! |
||
user = self.set_cookie() | ||
else: | ||
with open(COOKIE_PATH, "r") as fh: | ||
with open(self.cookie_path, "r") as fh: | ||
try: | ||
user = yaml.safe_load(fh) | ||
if user is None: | ||
|
@@ -266,10 +268,15 @@ def flush(): | |
|
||
def do_not_track(): | ||
global active_user | ||
active_user = User() | ||
active_user = User(None) | ||
|
||
|
||
def initialize_tracking(): | ||
def initialize_tracking(cookie_dir): | ||
global active_user | ||
active_user = User() | ||
active_user.initialize() | ||
active_user = User(cookie_dir) | ||
try: | ||
active_user.initialize() | ||
except Exception: | ||
logger.debug('Got an exception trying to initialize tracking', | ||
exc_info=True) | ||
active_user = User(None) |
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 lost
DbtProjectError
hereThere 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.
It was a double-import that I incorrectly added at some point - see 2 lines down where we import it again from
dbt.exceptions
! Same goes forDbtProfileError
.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.
dang. idk where it is in the code, but i saw this when supplying a
--profiles-dir
that did not contain a profiles.yml: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.
(we actually import DbtProjectError twice below)
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.
We actually import
DbtProfileError
twice in a row, ugh... fixed