Skip to content

Commit

Permalink
fix: standardizing timeout calculation in measurement consumer collec…
Browse files Browse the repository at this point in the history
…t to nanoseconds
  • Loading branch information
mdcg committed Jul 23, 2024
1 parent 8749168 commit 79cabe8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,18 @@ def collect(
metric_reader_storage = self._reader_storages[metric_reader]
# for now, just use the defaults
callback_options = CallbackOptions()
deadline_ns = time_ns() + timeout_millis * 10**6
deadline_ns = time_ns() + (timeout_millis * 1e6)

default_timeout_millis = 10000 * 10**6
default_timeout_ns = 10000 * 1e6

for async_instrument in self._async_instruments:

remaining_time = deadline_ns - time_ns()

if remaining_time < default_timeout_millis:
if remaining_time < default_timeout_ns:

callback_options = CallbackOptions(
timeout_millis=remaining_time
timeout_millis=remaining_time / 1e6
)

measurements = async_instrument.callback(callback_options)
Expand Down
8 changes: 7 additions & 1 deletion opentelemetry-sdk/tests/metrics/test_measurement_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,13 @@ def sleep_1(*args, **kwargs):
-1
].kwargs["timeout_millis"]

self.assertAlmostEqual(
round(10000 - callback_options_time_call),
1000.0,
places=1
)

self.assertLess(
callback_options_time_call,
10000 * 10**6,
10000,
)

0 comments on commit 79cabe8

Please sign in to comment.