Skip to content

fix(metrics): report DogStatsD timer durations in milliseconds - #72112

Open
waterWang wants to merge 1 commit into
apache:mainfrom
waterWang:fix-dogstatsd-timer-use-ms
Open

fix(metrics): report DogStatsD timer durations in milliseconds#72112
waterWang wants to merge 1 commit into
apache:mainfrom
waterWang:fix-dogstatsd-timer-use-ms

Conversation

@waterWang

Copy link
Copy Markdown

closes #72110

Problem

With [metrics] statsd_datadog_enabled = True, every metric emitted via Stats.timer() is under-reported by 1000x. Stats.timing() metrics are unaffected, so units become inconsistent on the same backend.

datadog's timed() context manager defaults to use_ms=False, so it reports the elapsed time in seconds even though the metric is sent with the |ms type. Airflow's Timer measures in milliseconds (1000.0 * (time.perf_counter() - start)).

Fix

Pass use_ms=True to dogstatsd.timed() in SafeDogStatsdLogger.timer() so elapsed times are reported in milliseconds, consistent with Stats.timing() and Airflow's own Timer.duration.

Tests

Updated the existing TestDogStats.test_timer assertion to expect use_ms=True.

datadog's ``timed()`` context manager defaults to ``use_ms=False``, which reports
the elapsed time in seconds even though the metric is sent with the ``|ms`` type.
Airflow's ``Timer`` measures in milliseconds, so with ``statsd_datadog_enabled``
every ``Stats.timer()`` metric was under-reported by 1000x while ``Stats.timing()``
metrics were unaffected. Pass ``use_ms=True`` to keep the units consistent.

Fixes apache#72110

@ColtenOuO ColtenOuO left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The PR title should follow the same suggestion in #71880

@ColtenOuO

Copy link
Copy Markdown
Contributor

Also, the issue author mentioned they were already planning to submit a PR for this. It might not be ideal to open a PR over them, so you might want to keep that in mind when picking up issues in the future.

Please check my comment in your previously PR.

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.

DogStatsD backend emits Stats.timer() metrics in seconds instead of milliseconds

2 participants