feat(main): add bounded randomized check-interval jitter across nodes

This commit is contained in:
patrick committed 2026-03-05 20:39:22 -05:00
1 parent b34ac69ac1
commit d2fdd5be44
7 files changed
+72 -3

No files matched your search

+18 -3
View File
@@ -1,4 +1,5 @@
import logging
import random
import signal
import threading
@@ -14,6 +15,15 @@ from healing import execute_heal_and_verify, should_heal
from reporter import LocalStateReporter
def compute_sleep_interval(base_interval, jitter_pct):
base = max(1.0, float(base_interval))
jitter = min(max(float(jitter_pct), 0.0), 0.90)
if jitter == 0:
return base
factor = 1.0 + random.uniform(-jitter, jitter)
return max(1.0, base * factor)
def main():
"""
The Orchestrator: Links Audit findings to the State Reporter.
@@ -45,7 +55,8 @@ def main():
logging.info(
f"Threat Engine Agent initialized on {settings.node_name}. "
f"config_path={settings.config_path} "
f"log_path={settings.log_path} state_file={settings.state_file}"
f"log_path={settings.log_path} state_file={settings.state_file} "
f"check_jitter_pct={settings.check_jitter_pct:.2f}"
)
while not stop_event.is_set():
@@ -108,8 +119,12 @@ def main():
else:
logging.info(f"Audit Success: {count} IPs in sync.")
print(f"[*] Sleeping for {settings.check_interval} seconds...")
stop_event.wait(settings.check_interval)
sleep_seconds = compute_sleep_interval(
settings.check_interval,
settings.check_jitter_pct,
)
print(f"[*] Sleeping for {sleep_seconds:.1f} seconds...")
stop_event.wait(sleep_seconds)
except KeyboardInterrupt:
logging.info("Agent shutting down manually.")