DataDog / datadogpy

The Datadog Python library
https://datadoghq.com/
Other
612 stars 304 forks source link

[statsd] Add ability to toggle `statsd.disable_buffering` state during runtime #700

Closed sgnn7 closed 2 years ago

sgnn7 commented 2 years ago

What does this PR do?

Description of the Change

While not likely to be useful currently, if/when we enable buffering on the DogStatsd clients by default again we will want to have this feature already in place since the module level statsd may not behave as expected in fork()-based environments. Because datadog.initialize() cannot recreate the instance of the module-level statsd, we need a runtime setting for disable_buffering instead of recreating the instance, making the implementation somewhat constrained in how it is done.

As a side-effect, this change allow use of the module-level statsd instance with buffering enabled which was previously not possible.

Alternate Designs

None that would make sense with the limitations provided.

Possible Drawbacks

Assumptions were made in the logic that datadog.initialize() would be only called once for the application. While there are protections around concurrent invocations, there could be edge cases not covered if multiple concurrent calls to `initialize are made to change this flag or if the data is being added to the buffer while the buffering is being disabled.

Verification Process

Tests covers the underlying functionality of this feature but it can be tested with:

Additional Notes

This feature will be gradually documented as it is expected to be useful only in very niche high-throughput cases.

Release Notes

Review checklist (to be filled by reviewers)

therve commented 2 years ago

/azp run

azure-pipelines[bot] commented 2 years ago
Azure Pipelines successfully started running 2 pipeline(s).