Skip to content
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

Adding user_id to metrics #1539

Merged
merged 8 commits into from
Feb 14, 2020
Merged

Adding user_id to metrics #1539

merged 8 commits into from
Feb 14, 2020

Conversation

josemazo
Copy link
Contributor

@josemazo josemazo requested a review from Jesus89 February 13, 2020 14:14
cartoframes/utils/metrics.py Outdated Show resolved Hide resolved
cartoframes/utils/metrics.py Outdated Show resolved Hide resolved
Copy link
Member

@Jesus89 Jesus89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! I have added a comment about the format of the metrics, but the rest LGTM!

@@ -79,11 +80,17 @@ def build_metrics_data(event_name):
'runtime_env': get_runtime_env()
}

if not isinstance(extra_metrics_data, dict):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need @cmongut @ilbambino for the definition of the metrics structure. Maybe they require "user_id" instead of a field called "extra", so I think we could merge both dictionaries (metrics_data + extra_metrics_data)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it isn't defined. But the extra part is almost an error. The just uploaded commit it only adds the extra key if the extra_metrics_data is not a dict.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't add the extra key until it's required from Product, so I think we can remove the extra_metrics_data as != dict and return just {}

@@ -93,7 +100,13 @@ def decorator_func(func):
@functools.wraps(func)
def wrapper_func(*args, **kwargs):
result = func(*args, **kwargs)
post_metrics(event_name)

credentials = get_parameter_from_decorator('credentials', func, *args, **kwargs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would extract this to a function build_extra_metrics_data

@@ -334,7 +335,8 @@ def is_uuid(text):
def get_credentials(credentials=None):
from ..auth import defaults
_credentials = credentials or defaults.get_default_credentials()
check_credentials(_credentials)
if credentials is not None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this added? If credentials is None but you have default_credentials it should call check_credentials too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some tests that have no credentials configured, and check_credentials raises an exception.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, in that case, I would try to pass a real Credential instance to those specific tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The failing tests were the Map ones, and the Map class doesn't accept a Credentials parameter, so I've used the set_default_credentials function and created a new unset_default_credentails becuase if not, the test_source_no_credentials test fails because it has the default credentials in the global variables.

@@ -524,3 +526,18 @@ def fn(*args, **kw):
except Exception:
pass
return fn


def get_parameter_from_decorator(parameter_name, func, *args, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!

@josemazo
Copy link
Contributor Author

Ready for CR again!

@josemazo
Copy link
Contributor Author

Ready for re-CR!

@josemazo
Copy link
Contributor Author

Adding PEP448! 💪

Copy link
Member

@Jesus89 Jesus89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!! LGTM.

Let's ping @ilbambino, so he can include it in the metrics dashboard.

@Jesus89 Jesus89 merged commit b244f78 into develop Feb 14, 2020
@Jesus89 Jesus89 deleted the josema/ch58519/track_user branch February 14, 2020 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants