From df04db5cf4229aa855e3361ab784c12633b42aaa Mon Sep 17 00:00:00 2001 From: Buduzz Date: Tue, 1 Nov 2022 14:58:30 +0100 Subject: [PATCH] feat: Implemented better backoff version checking and added unit test for the feature --- .../pkg_resources/__init__.py | 23 +++++++++++++++++++ .../tests/test_otlp_exporter_mixin.py | 5 ++++ 2 files changed, 28 insertions(+) create mode 100644 exporter/opentelemetry-exporter-otlp-proto-grpc/pkg_resources/__init__.py diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/pkg_resources/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/pkg_resources/__init__.py new file mode 100644 index 00000000000..d78a87562aa --- /dev/null +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/pkg_resources/__init__.py @@ -0,0 +1,23 @@ + +import toml + +deps = toml.load('./exporter/opentelemetry-exporter-otlp-proto-grpc/pyproject.toml')['project'] +dependencies = deps['dependencies'] +backoff = dependencies[0].split(';')[0] +info = backoff.split() +package_name = info[0] +package_version = info[-1] + +pkgs = dict([(package_name, package_version)]) + + +def package_version(r): + def wrapper(f): + r.version = pkgs[f] + return r + return wrapper + +@package_version +def get_distribution(package_name): + return pkgs[package_name] + diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py index 81a874af705..bfb75970406 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py @@ -113,3 +113,8 @@ def trailing_metadata(self): "while exporting mock, retrying in 0s." ), ) + + def test_backoff_version_checking(self): + import pkg_resources + backoff_version = pkg.get_distribution('backoff').version + self.assertEqual(backoff_version, '2.0.0')