diff --git a/.changelog/5436.fixed b/.changelog/5436.fixed new file mode 100644 index 0000000000..b6e2f1c49e --- /dev/null +++ b/.changelog/5436.fixed @@ -0,0 +1 @@ +`opentelemetry-configuration`: resolve false-positive warning logs for newer schema minor version diff --git a/opentelemetry-configuration/src/opentelemetry/configuration/README.md b/opentelemetry-configuration/src/opentelemetry/configuration/README.md index 93ff263497..b6c4ffb922 100644 --- a/opentelemetry-configuration/src/opentelemetry/configuration/README.md +++ b/opentelemetry-configuration/src/opentelemetry/configuration/README.md @@ -21,7 +21,9 @@ Which fields of the configuration schema the Python SDK actually applies at runt tox -e generate-config-from-jsonschema ``` -3. Update any version string references in tests and source: +3. Bump `_SUPPORTED_SCHEMA_MAJOR` / `_SUPPORTED_SCHEMA_MINOR` in `file/_loader.py` to the version of the vendored schema. + +4. Update any version string references in tests and source: ```sh grep -r "OLD_VERSION" opentelemetry-configuration/ diff --git a/opentelemetry-configuration/src/opentelemetry/configuration/file/_loader.py b/opentelemetry-configuration/src/opentelemetry/configuration/file/_loader.py index c4fcdf8f88..933ec10b57 100644 --- a/opentelemetry-configuration/src/opentelemetry/configuration/file/_loader.py +++ b/opentelemetry-configuration/src/opentelemetry/configuration/file/_loader.py @@ -46,7 +46,7 @@ # warning. See # https://github.com/open-telemetry/opentelemetry-configuration/blob/main/VERSIONING.md _SUPPORTED_SCHEMA_MAJOR = 1 -_SUPPORTED_SCHEMA_MINOR = 0 +_SUPPORTED_SCHEMA_MINOR = 1 _schema_cache: list[dict] = [] diff --git a/opentelemetry-configuration/tests/file/test_loader.py b/opentelemetry-configuration/tests/file/test_loader.py index ea9689008b..d02465beb8 100644 --- a/opentelemetry-configuration/tests/file/test_loader.py +++ b/opentelemetry-configuration/tests/file/test_loader.py @@ -14,6 +14,10 @@ ConfigurationError, load_config_file, ) +from opentelemetry.configuration.file._loader import ( + _SUPPORTED_SCHEMA_MAJOR, + _SUPPORTED_SCHEMA_MINOR, +) from opentelemetry.configuration.models import ( BatchSpanProcessor as BatchSpanProcessorConfig, ) @@ -331,6 +335,8 @@ def test_typed_config_feeds_factory_function(self): class TestFileFormatValidation(unittest.TestCase): """Validate the file_format version per the configuration spec.""" + _SUPPORTED = f"{_SUPPORTED_SCHEMA_MAJOR}.{_SUPPORTED_SCHEMA_MINOR}" + @staticmethod def _load(file_format: str) -> OpenTelemetryConfiguration: with tempfile.NamedTemporaryFile( @@ -344,26 +350,34 @@ def _load(file_format: str) -> OpenTelemetryConfiguration: os.unlink(path) def test_supported_version_is_accepted(self): - config = self._load("1.0") - self.assertEqual(config.file_format, "1.0") + with self.assertNoLogs( + "opentelemetry.configuration.file._loader", level="WARNING" + ): + config = self._load(self._SUPPORTED) + self.assertEqual(config.file_format, self._SUPPORTED) def test_pre_release_meta_tag_is_accepted(self): - # The meta tag is stripped; "1.0-rc.2" is treated as 1.0. - config = self._load("1.0-rc.2") - self.assertEqual(config.file_format, "1.0-rc.2") + # The meta tag is stripped, so the version is read as the supported one. + version = f"{self._SUPPORTED}-rc.2" + config = self._load(version) + self.assertEqual(config.file_format, version) def test_newer_minor_is_accepted_with_warning(self): + version = f"{_SUPPORTED_SCHEMA_MAJOR}.{_SUPPORTED_SCHEMA_MINOR + 1}" with self.assertLogs( "opentelemetry.configuration.file._loader", level="WARNING" ) as logs: - config = self._load("1.1") - self.assertEqual(config.file_format, "1.1") + config = self._load(version) + self.assertEqual(config.file_format, version) self.assertTrue( any("newer minor version" in message for message in logs.output) ) def test_unsupported_major_is_rejected(self): - for version in ("2.0", "0.4"): + versions = [f"{_SUPPORTED_SCHEMA_MAJOR + 1}.0"] + if _SUPPORTED_SCHEMA_MAJOR > 0: + versions.append(f"{_SUPPORTED_SCHEMA_MAJOR - 1}.0") + for version in versions: with self.subTest(version=version): with self.assertRaises(ConfigurationError) as ctx: self._load(version)