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

[statsd] option to time in ms #78

Merged
merged 1 commit into from
Aug 20, 2015
Merged

[statsd] option to time in ms #78

merged 1 commit into from
Aug 20, 2015

Conversation

yannmh
Copy link
Member

@yannmh yannmh commented Aug 6, 2015

use_ms option to report timed values in milliseconds instead of
seconds (default False).

examples:

from statsd import statsd

statsd.use_ms = True

statsd.timed('this.will.use.ms')
def foo():
      # pass

from statsd import statsd
statsd.timed('this.will.use.seconds')
def foo():
      # pass

statsd.timed('this.will.use.ms', use_ms=True):
def foo():
      # pass

Fix #10, and inspired by #10, #67
Thanks @g-- !

@yannmh yannmh self-assigned this Aug 6, 2015
@olivielpeau
Copy link
Member

LGTM! ⏰

self.statsd.timing(self.metric, time() - self.start,
self.tags, self.sample_rate)
elapsed = time() - self.start
use_ms = self.statsd.use_ms or self.use_ms
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm unsure this really makes sense, someone could declare a statsd object with use_ms as True, then explicitly make a _TimedContextManagerDecorator with use_ms as False and this would resort to using milliseconds...is that expected?

Does this object even need this property or can it just pull it off its statsd object?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @clokep, this is, indeed, unexpected.

I think having this property is worth: it makes convenient to switch specific timers from s to ms without altering the overall statsd configuration.

Copy link
Contributor

Choose a reason for hiding this comment

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

I realized after writing this that if the decorator had it, then it had to be passed into here. I think the logic on this statement probably needs to be rethough (likely: if self.use_ms is not explicitly passed in, then default to self.statsd.use_ms).

`use_ms` option to report timed values in milliseconds instead of
seconds (default False).

examples:
```
from statsd import statsd

statsd.use_ms = True

statsd.timed('this.will.use.ms')
def foo():
      # pass

from statsd import statsd
statsd.timed('this.will.use.seconds')
def foo():
      # pass

statsd.timed('this.will.use.ms', use_ms=True):
def foo():
      # pass
```

Fix #10, #67 (thanks @g--)
@yannmh yannmh force-pushed the yann/timers-in-ms branch from 617f7c9 to 7de341c Compare August 19, 2015 20:04
@yannmh
Copy link
Member Author

yannmh commented Aug 19, 2015

Thanks @clokep. I adressed the points you mentionned and rebased my work.

@olivielpeau can you take a second look at it when you have a chance ?

@olivielpeau
Copy link
Member

Indeed it's better now! LGTM

yannmh added a commit that referenced this pull request Aug 20, 2015
@yannmh yannmh merged commit 1eed1b8 into master Aug 20, 2015
@yannmh yannmh deleted the yann/timers-in-ms branch August 20, 2015 14:05
@yannmh yannmh mentioned this pull request Aug 21, 2015
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