From 79cabe8ecba22336504222349f45234fedcdb3c9 Mon Sep 17 00:00:00 2001 From: Mauro de Carvalho Date: Tue, 23 Jul 2024 13:39:23 -0300 Subject: [PATCH 1/6] fix: standardizing timeout calculation in measurement consumer collect to nanoseconds --- .../sdk/metrics/_internal/measurement_consumer.py | 8 ++++---- .../tests/metrics/test_measurement_consumer.py | 8 +++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/measurement_consumer.py b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/measurement_consumer.py index c5e81678dcb..4310061b823 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/measurement_consumer.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/measurement_consumer.py @@ -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) diff --git a/opentelemetry-sdk/tests/metrics/test_measurement_consumer.py b/opentelemetry-sdk/tests/metrics/test_measurement_consumer.py index 19c514c13e8..9030768664b 100644 --- a/opentelemetry-sdk/tests/metrics/test_measurement_consumer.py +++ b/opentelemetry-sdk/tests/metrics/test_measurement_consumer.py @@ -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, ) From b69dbc64b625815a163fc11268e900a965f55d1a Mon Sep 17 00:00:00 2001 From: Mauro de Carvalho Date: Tue, 23 Jul 2024 18:06:04 -0300 Subject: [PATCH 2/6] style: apply formatter --- opentelemetry-sdk/tests/metrics/test_measurement_consumer.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/opentelemetry-sdk/tests/metrics/test_measurement_consumer.py b/opentelemetry-sdk/tests/metrics/test_measurement_consumer.py index 9030768664b..e8907e9ccb8 100644 --- a/opentelemetry-sdk/tests/metrics/test_measurement_consumer.py +++ b/opentelemetry-sdk/tests/metrics/test_measurement_consumer.py @@ -181,9 +181,7 @@ def sleep_1(*args, **kwargs): ].kwargs["timeout_millis"] self.assertAlmostEqual( - round(10000 - callback_options_time_call), - 1000.0, - places=1 + round(10000 - callback_options_time_call), 1000.0, places=1 ) self.assertLess( From 0260d6416f2727e3ab62fe270f6ed1d930249a15 Mon Sep 17 00:00:00 2001 From: Mauro de Carvalho Date: Tue, 23 Jul 2024 18:14:24 -0300 Subject: [PATCH 3/6] update CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05ae64c1531..b3115ef0be9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1621,4 +1621,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#3778](https://github.com/open-telemetry/opentelemetry-python/pull/3778)) - Fix license field in pyproject.toml files ([#3803](https://github.com/open-telemetry/opentelemetry-python/pull/3803)) - +- Standardizing timeout calculation in measurement consumer collect to nanoseconds + ([#4074](https://github.com/open-telemetry/opentelemetry-python/pull/4074)) \ No newline at end of file From a4a836d29ce6bf52d91f7b2fd06de6e3823536ff Mon Sep 17 00:00:00 2001 From: Mauro de Carvalho Date: Tue, 23 Jul 2024 18:55:44 -0300 Subject: [PATCH 4/6] typo: update CHANGELOG.md --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3115ef0be9..a7baa168d72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +- Standardizing timeout calculation in measurement consumer collect to nanoseconds + ([#4074](https://github.com/open-telemetry/opentelemetry-python/pull/4074)) - optional scope attributes for logger creation ([#4035](https://github.com/open-telemetry/opentelemetry-python/pull/4035)) - optional scope attribute for tracer creation @@ -1621,5 +1623,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#3778](https://github.com/open-telemetry/opentelemetry-python/pull/3778)) - Fix license field in pyproject.toml files ([#3803](https://github.com/open-telemetry/opentelemetry-python/pull/3803)) -- Standardizing timeout calculation in measurement consumer collect to nanoseconds - ([#4074](https://github.com/open-telemetry/opentelemetry-python/pull/4074)) \ No newline at end of file + From d9b13f1af3f3d1ce39466830f5ee79cf9ead70d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Em=C3=ADdio=20Neto?= <9735060+emdneto@users.noreply.github.com> Date: Tue, 23 Jul 2024 19:11:24 -0300 Subject: [PATCH 5/6] Update opentelemetry-sdk/tests/metrics/test_measurement_consumer.py --- opentelemetry-sdk/tests/metrics/test_measurement_consumer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry-sdk/tests/metrics/test_measurement_consumer.py b/opentelemetry-sdk/tests/metrics/test_measurement_consumer.py index e8907e9ccb8..164bdc6d1be 100644 --- a/opentelemetry-sdk/tests/metrics/test_measurement_consumer.py +++ b/opentelemetry-sdk/tests/metrics/test_measurement_consumer.py @@ -181,7 +181,7 @@ def sleep_1(*args, **kwargs): ].kwargs["timeout_millis"] self.assertAlmostEqual( - round(10000 - callback_options_time_call), 1000.0, places=1 + round(10000 - callback_options_time_call), 1000, delta=1 ) self.assertLess( From c35bafb04f7e249a6bec871af25dd4c10a5b89de Mon Sep 17 00:00:00 2001 From: Mauro de Carvalho Date: Tue, 23 Jul 2024 19:26:05 -0300 Subject: [PATCH 6/6] fix: removing unnecessary test --- opentelemetry-sdk/tests/metrics/test_measurement_consumer.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/opentelemetry-sdk/tests/metrics/test_measurement_consumer.py b/opentelemetry-sdk/tests/metrics/test_measurement_consumer.py index e8907e9ccb8..91a49955b70 100644 --- a/opentelemetry-sdk/tests/metrics/test_measurement_consumer.py +++ b/opentelemetry-sdk/tests/metrics/test_measurement_consumer.py @@ -180,10 +180,6 @@ 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,