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

Add support for passing timedeltas to StatsClientBase.timing #104

Closed
wants to merge 2 commits into from

Conversation

zeebonk
Copy link
Contributor

@zeebonk zeebonk commented Feb 26, 2018

This pull request adds support for passing timedeltas to StatsClientBase.timing.

In situations where you have timedeltas, code like this:

statsd.timining('my_timing_stat', td.total_seconds() * 1000.)

Would reduce to:

statsd.timing('my_timing_stat', td)

As total_seconds was introduced in Python 2.7 the transformation to milliseconds will be done using regular arithmetic based on the example from the python docs.

@jsocol
Copy link
Owner

jsocol commented Aug 21, 2018

Hi @zeebonk! Thanks for this patch—sorry and it took me a while to get to it. I've done a little clean-up—in particular I dropped Python 2.6 so I updated the code to use timedelta.total_seconds() per your comment—and merged it in as #111.

@zeebonk zeebonk deleted the timedelta_timing branch August 22, 2018 06:11
jsocol added a commit that referenced this pull request Aug 22, 2018
- Drop support for Python 2.5, 2.6, 3.2, 3.3 (#108, #116).
- Add UnixSocketStatsClient (#76, #112).
- Add support for timedeltas in timing() (#104, #111).
- Fix timer decorator with partial functions (#85).
- Remove ABCMeta metaclass (incompatible with Py3) (#109).
- Refactor client module (#115).
- Various doc updates (#99, #102, #110, #113, #114).
@jsocol jsocol mentioned this pull request Aug 22, 2018
nshenkman added a commit to klaviyo/pystatsd that referenced this pull request Feb 26, 2020
* Bug: Fix timer decorator with partial functions (jsocol#85)

* Update badges

* Drop support for old Python versions

Leave Python 2.6, 3.2, and 3.3 out. Let's focus on >=3.4 (and we'll
still support 2.7 because it's easy).

* Skip IPv6 resolution test

Since early June[1], IPv6 loopback address resolution has been flaky on
TravisCI. It seems that it should have been flaky even earlier, or
there's something strange going on. For now, skip the test. We can come
back to diagnosing once master is (otherwise) passing.

This failure first started on Python 2.6, but quickly spread to all
versions. It appears to pass occasionally, but not on any consistent
version. Lately it seems to fail more or less all the time, though on
the latest cron build, it did pass on Pypy[2].

[1]: https://travis-ci.org/jsocol/pystatsd/builds/387167216
[2]: https://travis-ci.org/jsocol/pystatsd/builds/417687774

* Remove dependency on ABCMeta.

StatsClientBase and PipelineBase are not intended to be public APIs, and
the syntax for metaclasses introduces some complexity between Python 2
and 3.

Since ABCMeta and abc.abstractmethod were only being used to guarantee
that internal subclasses implemented these methods correctly, and
there's no external behavioral issues on Python 3, where the metaclass
has been ignored for years, let's remove the metaclass and rely on
NotImplementedError() and the test suite as a backstop.

Fixes jsocol#106.

* Fix minor nits, spelling and unused imports

* Add a document about tagging metrics

Collecting thoughts that have been spread across several GitHub issues
and pull requests into one place, a reference to use from now on when
the discussion of tags comes up.

* Add timedelta support to Client.timing

Allow passing datetime.timedelta objects directly to
StatsClient.timing(), automatically converting to milliseconds.

* Simplify timer decorator

* Introduce UnixSocketStatsClient class.

New client for handling sending stats through Unix domains sockets.

* Update Sphinx directives in docs

Tweaks a lot of doc references to use better Sphinx tooling. Shouldn't
break any existing links, but may get to a point where we don't need
quite as many named references.

* Fix wrapping in reference docs

* Use Python-domain Sphinx references

* Remove redundant reference points

* Refactor client module into package

The client module just broke 300 lines and had a lot of functionality in
it. This breaks the single file up into a package and reduces a decent
amount of duplication. Makes a few related changes:

- Replaces old Python __future__ imports with new ones
- Removes __all__ in favor of fewer imports
- Refactors common stream code into StreamClientBase
- Renames TCPPipeline to StreamPipeline for consistency (this is not a
  public class name)

* Remove old version classifiers

* Version 3.3

- Drop support for Python 2.5, 2.6, 3.2, 3.3 (jsocol#108, jsocol#116).
- Add UnixSocketStatsClient (jsocol#76, jsocol#112).
- Add support for timedeltas in timing() (jsocol#104, jsocol#111).
- Fix timer decorator with partial functions (jsocol#85).
- Remove ABCMeta metaclass (incompatible with Py3) (jsocol#109).
- Refactor client module (jsocol#115).
- Various doc updates (jsocol#99, jsocol#102, jsocol#110, jsocol#113, jsocol#114).

Co-authored-by: Mathieu Leplatre <mathieu@leplat.re>
Co-authored-by: James Socol <me@jamessocol.com>
Co-authored-by: Jorge Maroto <patoroco@gmail.com>
Co-authored-by: Gijs van der Voort <vandervoort.gijs@gmail.com>
Co-authored-by: Michael <michael-k@users.noreply.github.com>
Co-authored-by: hintofbasil <CuteCondemnedPenguin@shadowmail.co.uk>
Co-authored-by: Jason Parker <jason.thomas.parker@gmail.com>
csestelo pushed a commit to Destygo/pystatsd that referenced this pull request Jul 18, 2022
* v0.2

Clean up

Vincent review

Translations by bubble

Rename enums back

Update use_case_executor/adapters/flow_validation/node_data/answer_data.py

Co-authored-by: Vincent GENTY <Wellan89@users.noreply.github.com>

Update use_case_executor/adapters/flow_validation/node_data/answer_data.py

Co-authored-by: Vincent GENTY <Wellan89@users.noreply.github.com>

Update use_case_executor/adapters/flow_validation/node_data/answer_data.py

Co-authored-by: Vincent GENTY <Wellan89@users.noreply.github.com>

Update use_case_executor/adapters/flow_validation/node_data/answer_data.py

Co-authored-by: Vincent GENTY <Wellan89@users.noreply.github.com>

Update use_case_executor/adapters/flow_validation/node_data/answer_data.py

Co-authored-by: Vincent GENTY <Wellan89@users.noreply.github.com>

Update use_case_executor/adapters/flow_validation/node_data/answer_data.py

Co-authored-by: Vincent GENTY <Wellan89@users.noreply.github.com>

Review

Fix legacy flow difference

Compatibility API

Vincent review

New format + marshmallow validation

Cleanup + requirements

Live review

Copy old validation

Rename test files for unicity

Fix test

Use case versions migration

Use case versions migration

Verbose downgrade

ADR

Rename bubble sequence + cleanup

Fix precommit refs

Update scripts/schema_version_migrations/migration_utils.py

Co-authored-by: Vincent GENTY <Wellan89@users.noreply.github.com>

Update tests/adapters/flow_validation_v_0_1/test_flow_validation_success_v_0_1.py

Co-authored-by: Vincent GENTY <Wellan89@users.noreply.github.com>

Update tests/adapters/flow_validation_v_0_1/test_flow_validation_success_v_0_1.py

Co-authored-by: Vincent GENTY <Wellan89@users.noreply.github.com>

Update tests/adapters/flow_validation_v_0_1/test_flow_validation_success_v_0_1.py

Co-authored-by: Vincent GENTY <Wellan89@users.noreply.github.com>

Update tests/api/namespace/use_case/test_v0_1_compatibility.py

Co-authored-by: Vincent GENTY <Wellan89@users.noreply.github.com>

Update use_case_executor/adapters/flow_validation/node_data/answer_data/answer_data.py

Co-authored-by: Vincent GENTY <Wellan89@users.noreply.github.com>

Update use_case_executor/adapters/flow_validation_v0_1/node.py

Co-authored-by: Vincent GENTY <Wellan89@users.noreply.github.com>

Clarifications

* Allow bubbles with missing language

* Update migration process

* Fix test

* Precommits and little fixes

* Fix requirements

* Review
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.

None yet

2 participants