feat(hindsight): configurable embedded daemon health grace timeout (#50341)
On resource-contended hosts the embedded Hindsight daemon can exceed a single 2s /health check; upstream then waits a grace window before treating it as stale and killing+restarting it (hindsight-embed reads HINDSIGHT_EMBED_PORT_HEALTH_GRACE_TIMEOUT, default 30s, into a module-level constant at import time). Users on busy boxes had no Hermes-side way to raise it short of hand-setting an env var. Add a 'port_health_grace_timeout' config.json option to the Hindsight plugin. When set, initialize() exports it to the process env BEFORE daemon_embed_manager is imported (the import-time read is the contract). setdefault() so an explicit operator env override always wins. Exposed in 'hermes memory setup' for local_embedded mode. Follow-up to #50308 / issue #13125 comment thread.
This commit is contained in:
parent
def3f6388f
commit
5e3e89cc05
2 changed files with 106 additions and 0 deletions
64
tests/plugins/test_hindsight_health_grace_timeout.py
Normal file
64
tests/plugins/test_hindsight_health_grace_timeout.py
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
"""Embedded-daemon health grace timeout export (issue #13125 comment thread).
|
||||
|
||||
On resource-contended hosts the embedded Hindsight daemon can exceed a single
|
||||
2s /health check and get needlessly killed + restarted. Upstream exposes the
|
||||
grace window via HINDSIGHT_EMBED_PORT_HEALTH_GRACE_TIMEOUT (read at import
|
||||
time). The plugin surfaces it as a config.json knob and exports it to the
|
||||
process env BEFORE daemon_embed_manager is imported.
|
||||
"""
|
||||
|
||||
import importlib
|
||||
|
||||
import pytest
|
||||
|
||||
hindsight = importlib.import_module("plugins.memory.hindsight")
|
||||
_export = hindsight._export_port_health_grace_timeout
|
||||
_ENV = hindsight._PORT_HEALTH_GRACE_ENV
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _clear_env(monkeypatch):
|
||||
monkeypatch.delenv(_ENV, raising=False)
|
||||
|
||||
|
||||
def test_configured_value_exported(monkeypatch):
|
||||
_export({"port_health_grace_timeout": 60})
|
||||
import os
|
||||
|
||||
assert float(os.environ[_ENV]) == 60.0
|
||||
|
||||
|
||||
def test_string_value_parsed(monkeypatch):
|
||||
_export({"port_health_grace_timeout": "45"})
|
||||
import os
|
||||
|
||||
assert float(os.environ[_ENV]) == 45.0
|
||||
|
||||
|
||||
def test_blank_and_missing_are_noops(monkeypatch):
|
||||
import os
|
||||
|
||||
_export({})
|
||||
assert _ENV not in os.environ
|
||||
_export({"port_health_grace_timeout": ""})
|
||||
assert _ENV not in os.environ
|
||||
_export({"port_health_grace_timeout": None})
|
||||
assert _ENV not in os.environ
|
||||
|
||||
|
||||
def test_invalid_and_negative_ignored(monkeypatch):
|
||||
import os
|
||||
|
||||
_export({"port_health_grace_timeout": "not-a-number"})
|
||||
assert _ENV not in os.environ
|
||||
_export({"port_health_grace_timeout": -5})
|
||||
assert _ENV not in os.environ
|
||||
|
||||
|
||||
def test_explicit_env_wins_over_config(monkeypatch):
|
||||
import os
|
||||
|
||||
monkeypatch.setenv(_ENV, "99")
|
||||
_export({"port_health_grace_timeout": 60})
|
||||
# setdefault must not clobber an operator-set env override.
|
||||
assert os.environ[_ENV] == "99"
|
||||
Loading…
Add table
Add a link
Reference in a new issue