Skip to content

Commit

Permalink
Merge pull request #524 from fkie-cad/fix-versioneer
Browse files Browse the repository at this point in the history
Fix versioneer and PROMETHEUS_MULTIPROC_DIR bug
  • Loading branch information
djkhl authored Feb 8, 2024
2 parents e1fcaf5 + 0c26481 commit 13c374f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

### Bugfix

## v10.0.2
### Bugfix
* fix versioneer import
* fix logprep does not complain about missing PROMETHEUS_MULTIPROC_DIR

## v10.0.1
### Bugfix

Expand Down
5 changes: 5 additions & 0 deletions logprep/util/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,11 @@ def _verify_environment(self):
f"'{prometheus_multiproc_path}' does not exist"
)
)
if self.metrics.enabled:
if "PROMETHEUS_MULTIPROC_DIR" not in os.environ:
raise InvalidConfigurationError(
"Metrics enabled but PROMETHEUS_MULTIPROC_DIR is not set"
)

def _verify_rules(self, processor: Processor) -> None:
rule_ids = []
Expand Down
2 changes: 1 addition & 1 deletion logprep/util/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from colorama import Back, Fore
from colorama.ansi import AnsiBack, AnsiFore

from logprep._version import get_versions
from logprep.util.defaults import DEFAULT_CONFIG_LOCATION
from versioneer import get_versions

if TYPE_CHECKING: # pragma: no cover
from logprep.util.configuration import Configuration
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class TestQuickstart:
QUICKSTART_CONFIG_PATH = "quickstart/exampledata/config/pipeline.yml"

@mock.patch("os.environ", new={"PROMETHEUS_MULTIPROC_DIR": "/tmp"})
def test_quickstart_setup_is_valid(self):
"""ensures the quickstart rules are valid"""
with mock.patch(
Expand Down
26 changes: 19 additions & 7 deletions tests/unit/util/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ def test_get_last_value(self, tmp_path, attribute, first_value, second_value):
{attribute}: {second_value}
"""
)

config = Configuration.from_sources([str(first_config), str(second_config)])
attribute_from_test = getattr(config, attribute)
if hasattr(attribute_from_test, "__attrs_attrs__"):
assert asdict(attribute_from_test) == second_value
else:
assert attribute_from_test == second_value
with mock.patch("os.environ", new={"PROMETHEUS_MULTIPROC_DIR": str(tmp_path)}):
config = Configuration.from_sources([str(first_config), str(second_config)])
attribute_from_test = getattr(config, attribute)
if hasattr(attribute_from_test, "__attrs_attrs__"):
assert asdict(attribute_from_test) == second_value
else:
assert attribute_from_test == second_value

@pytest.mark.parametrize(
"attribute, value, expected_error, expected_message",
Expand Down Expand Up @@ -1103,6 +1103,18 @@ def test_processor_config_with_url_path(self, tmp_path):
assert len(config.pipeline) == 1
assert len(config.pipeline[0]["the almighty dissector"]["generic_rules"]) == 1

def test_verify_environment_raises_if_metrics_enabled_but_prometheus_multiproc_dir_not_set(
self, config_path
):
config = Configuration.from_sources([str(config_path)])
config.metrics = MetricsConfig(enabled=True, port=4242)
with mock.patch("os.environ", {}):
with pytest.raises(
InvalidConfigurationError,
match="Metrics enabled but PROMETHEUS_MULTIPROC_DIR is not set",
):
config._verify_environment()


class TestInvalidConfigurationErrors:
@pytest.mark.parametrize(
Expand Down

0 comments on commit 13c374f

Please sign in to comment.