Skip to content

Commit

Permalink
fix merge of version string for multiple configs (#556)
Browse files Browse the repository at this point in the history
* add test for config version merge
* add version aggregation implementaion
* fix get version test
* update changelog
  • Loading branch information
ekneg54 authored Mar 28, 2024
1 parent 2186732 commit fd0eb4c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

* fix version string of release versions
* fix version string of container builds for feature branches
* fix merge of config versions for multiple configs


## v10.0.4
Expand Down
2 changes: 2 additions & 0 deletions logprep/util/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,8 @@ def _set_attributes_from_configs(self) -> None:
attribute.name,
self._get_last_non_falsy_value(self._configs, attribute.name),
)
versions = (config.version for config in self._configs if config.version)
self.version = ", ".join(versions)

def _build_merged_pipeline(self):
pipelines = (config.pipeline for config in self._configs if config.pipeline)
Expand Down
49 changes: 48 additions & 1 deletion tests/unit/util/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ def test_create_from_sources_adds_configs(self):
@pytest.mark.parametrize(
"attribute, first_value, second_value",
[
("version", "1", "2"),
("config_refresh_interval", 0, 900),
("process_count", 1, 2),
("timeout", 1.0, 2.0),
Expand Down Expand Up @@ -1115,6 +1114,54 @@ def test_verify_environment_raises_if_metrics_enabled_but_prometheus_multiproc_d
):
config._verify_environment()

def test_versions_are_aggregated_for_multiple_configs(self, tmp_path):
dummy_config = {
"input": {"dummy": {"type": "dummy_input", "documents": []}},
"output": {"dummy": {"type": "dummy_output"}},
}
config1 = Configuration(version="first", **dummy_config)
config1_path = tmp_path / "config1.yml"
config1_path.write_text(config1.as_yaml())

config2 = Configuration(version="second", **dummy_config)
config2_path = tmp_path / "config2.yml"
config2_path.write_text(config2.as_yaml())

config = Configuration.from_sources([str(config1_path), str(config2_path)])
assert config.version == "first, second"

def test_versions_are_aggregated_for_multiple_configs_with_first_unset(self, tmp_path):
dummy_config = {
"input": {"dummy": {"type": "dummy_input", "documents": []}},
"output": {"dummy": {"type": "dummy_output"}},
}
config1 = Configuration(**dummy_config)
config1_path = tmp_path / "config1.yml"
config1_path.write_text(config1.as_yaml())

config2 = Configuration(version="second", **dummy_config)
config2_path = tmp_path / "config2.yml"
config2_path.write_text(config2.as_yaml())

config = Configuration.from_sources([str(config1_path), str(config2_path)])
assert config.version == "unset, second"

def test_versions_are_aggregated_for_multiple_configs_with_second_unset(self, tmp_path):
dummy_config = {
"input": {"dummy": {"type": "dummy_input", "documents": []}},
"output": {"dummy": {"type": "dummy_output"}},
}
config1 = Configuration(version="first", **dummy_config)
config1_path = tmp_path / "config1.yml"
config1_path.write_text(config1.as_yaml())

config2 = Configuration(**dummy_config)
config2_path = tmp_path / "config2.yml"
config2_path.write_text(config2.as_yaml())

config = Configuration.from_sources([str(config1_path), str(config2_path)])
assert config.version == "first, unset"


class TestInvalidConfigurationErrors:
@pytest.mark.parametrize(
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/util/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
snake_to_camel,
)
from logprep.util.json_handling import is_json
from tests.testdata.metadata import path_to_alternative_config, path_to_config
from tests.testdata.metadata import path_to_config


class TestCamelToSnake:
Expand Down Expand Up @@ -256,7 +256,7 @@ def test_get_version_string_with_multiple_config_sources(self):
expected_pattern = (
r"python version:\s+3\.\d+\.\d+\n"
r"logprep version:\s+[^\s]+\n"
r"configuration version:\s+1,\s+file://[^\s]+/config\.yml,\s+file://[^\s]+/config\.yml"
r"configuration version:\s+1,\s1,\s+file://[^\s]+/config\.yml,\s+file://[^\s]+/config\.yml"
)

result = get_versions_string(config)
Expand Down

0 comments on commit fd0eb4c

Please sign in to comment.