Skip to content

Commit e2598cf

Browse files
committed
Add option to control configuration change watching in Engine
1 parent a5bf564 commit e2598cf

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

mongoose/core/engine.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Engine(metaclass=Singleton):
5151
and managing their lifecycle (start, stop, reload).
5252
"""
5353

54-
def __init__(self, config_path: str, interface: str = None):
54+
def __init__(self, config_path: str, interface: str = None, watch_configuration_changes: bool = True):
5555
self.config_path = config_path
5656
self.config: Optional[Configuration] = None
5757
self.processing_queue = ProcessingQueue()
@@ -65,6 +65,7 @@ def __init__(self, config_path: str, interface: str = None):
6565
self._setup_components()
6666
self.started = False
6767
self.thread_id = threading.get_ident()
68+
self.watch_configuration_changes = watch_configuration_changes
6869
self.webhook_configuration_watcher = DropInConfigurationWatcher(
6970
self.config.extra_configuration_dir / "webhook.d",
7071
DropInConfigurationHandler(WebhookForwarderConfiguration, self._handle_webhook_configuration_changes),
@@ -189,7 +190,8 @@ def start(self):
189190
# Reset the stop event in case it was set during a previous run
190191
self.processing_queue.stop_processing_event.clear()
191192

192-
self.webhook_configuration_watcher.run()
193+
if self.watch_configuration_changes:
194+
self.webhook_configuration_watcher.run()
193195

194196
self.sink.start()
195197
self.database_storage.start()
@@ -215,7 +217,9 @@ def stop(self):
215217
self.started = False
216218

217219
self.processing_queue.stop_processing()
218-
self.webhook_configuration_watcher.stop()
220+
221+
if self.watch_configuration_changes:
222+
self.webhook_configuration_watcher.stop()
219223

220224
self.sink.stop()
221225
self.processing_queue.queues.clear()

tests/test_engine.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_engine_initialization(tmp_path):
2424
with open(config_file, "w") as f:
2525
yaml.dump(config_content, f)
2626

27-
engine = Engine(str(config_file))
27+
engine = Engine(str(config_file), watch_configuration_changes=False)
2828
assert isinstance(engine.config, Configuration)
2929
assert engine.config.collector.suricata.enable is True
3030
assert engine.config.collector.nf_stream.enable is False
@@ -52,7 +52,7 @@ def test_engine_start(mock_enrich_init, mock_file_start, mock_enrich_start, mock
5252
with open(config_file, "w") as f:
5353
yaml.dump(config_content, f)
5454

55-
engine = Engine(str(config_file))
55+
engine = Engine(str(config_file), watch_configuration_changes=False)
5656
engine.start()
5757

5858
assert mock_suricata_start.called
@@ -79,7 +79,7 @@ def test_engine_stop(mock_stop_processing, tmp_path):
7979
with open(config_file, "w") as f:
8080
yaml.dump(config_content, f)
8181

82-
engine = Engine(str(config_file))
82+
engine = Engine(str(config_file), watch_configuration_changes=False)
8383
engine.stop()
8484
assert mock_stop_processing.called
8585

@@ -94,7 +94,7 @@ def test_engine_reload(mock_setup, mock_load, mock_start, mock_stop, tmp_path):
9494
with open(config_file, "w") as f:
9595
yaml.dump(config_content, f)
9696

97-
engine = Engine(str(config_file))
97+
engine = Engine(str(config_file), watch_configuration_changes=False)
9898
engine.reload()
9999

100100
assert mock_stop.called

0 commit comments

Comments
 (0)