-
Notifications
You must be signed in to change notification settings - Fork 306
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 support for distribution context manager and decorator #581
Merged
Conversation
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
dnlserrano
force-pushed
the
distributed-context
branch
from
June 27, 2020 14:04
d8d3ca1
to
3e0d3c7
Compare
Is it possible to get a review here @hush-hush? 🙏 |
hush-hush
requested changes
Jul 20, 2020
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.
On tiny detail but looks good otherwise !
dnlserrano
force-pushed
the
distributed-context
branch
from
July 21, 2020 08:38
3e0d3c7
to
8cd8f3e
Compare
A decorator or context manager that will measure the distribution of a function's/context's run time using custom metric DISTRIBUTION. E.g. of usage follows: @statsd.distributed('user.query.time', sample_rate=0.5) def get_user(user_id): # Do what you need to ... pass # Is equivalent to ... with statsd.distributed('user.query.time', sample_rate=0.5): # Do what you need to ... pass # Is equivalent to ... start = time.time() try: get_user(user_id) finally: statsd.distribution('user.query.time', time.time() - start) Closes DataDog#563
dnlserrano
force-pushed
the
distributed-context
branch
from
July 21, 2020 08:41
8cd8f3e
to
da80e82
Compare
hush-hush
approved these changes
Jul 21, 2020
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
Thanks @dnlserrano for the PR ! |
zippolyte
added
the
changelog/Added
Added features results into a minor version bump
label
Aug 25, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
Takes a stab at #563.
Introduces the ability to use a context manager or decorator for the custom
DISTRIBUTION
metric.Description of the Change
Introduces new
DistributedContextManagerDecorator
which allows one to use a new context manager or decorator (e.g.,statsd.distributed
). It does the same asTimedContextManagerDecorator
(it is a subclass of it afterall), but changes the timing metric to usestatsd.distribution
instead ofstatsd.timing
.Thinking ahead, we do it by re-defining the
self.timing_func
used, which may later be passed in as an option tostatsd.timer
, as discussed here.Alternate Designs
We could have gone with the global switch from the get go, but decided to be more conservative from the start following @hush-hush's comment.
Possible Drawbacks
Not sure if we can afford doing this change at the level of the general
context.py
. I'm not aware if this is used for Statsd-compatible metrics only or if it allows for changes regarding custom metrics, which is the case forDISTRIBUTION
, as far as I'm aware. Appreciate any inputs there.Verification Process
Ran test with both
tox -e flake8
andtox -e py36
locally. Also experimented with the context manager after installing the changes locally usingpip install -e <path_to_cloned_project_dir>
, following yourDEVELOPMENT
guide. Usedjimf/statsd-logger
for quick-and-dirty experiment.Additional Notes
Python noob here, so please bear with. 🐻
Release Notes
Should be backwards compatible since it only introduces new behaviour, it does not break previous usage. Please double-check.
Review checklist (to be filled by reviewers)
changelog/
label attached. If applicable it should have thebackward-incompatible
label attached.do-not-merge/
label attached.kind/
andseverity/
labels attached at least.