fix: stop synthetic rtt_* keys from masking real plugin-data checks
host.plugin_data now always holds rtt_ipv4/rtt_ipv6 history after the first heartbeat, which broke two pre-existing behaviors that assumed plugin_data reflects only real client-collected data: - The request_update ACK gate in handle_datagram() never fired again after a host's first heartbeat, so stale OS/agent-version info was never refreshed after a reconnect (only a client restart fixed it). - plugin_data.clear() on every UP transition wiped rtt_* history too, so a flaky host could never accumulate a useful RTT graph. Add _is_rtt_key()/_has_real_plugin_data() helpers so both spots treat rtt_* keys as synthetic: the gate now looks only at real plugin data, and the recovery clear only drops real plugin keys, preserving RTT history across reconnects. Also fixes two pre-existing E127 continuation-indent flake8 issues in tests/test_udp_rtt_history.py. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DEimzMv4Q5EjFg3hoiZ69T
This commit is contained in:
+13
-2
@@ -319,6 +319,16 @@ def restore_connection_timers(hbdclass, ctx):
|
||||
logger.info("Restored timers for %d connection(s)", restored)
|
||||
|
||||
|
||||
def _is_rtt_key(plugin_name: str) -> bool:
|
||||
"""True for synthetic RTT-history keys (rtt_ipv4/rtt_ipv6), not real plugin data."""
|
||||
return plugin_name.startswith("rtt_")
|
||||
|
||||
|
||||
def _has_real_plugin_data(plugin_data: dict) -> bool:
|
||||
"""True if plugin_data holds any real (non-RTT) client-collected plugin data."""
|
||||
return any(not _is_rtt_key(k) for k in plugin_data)
|
||||
|
||||
|
||||
def handle_datagram(msg: dict, addr, transport, ctx: dict):
|
||||
"""Handle a parsed datagram message.
|
||||
|
||||
@@ -385,7 +395,7 @@ def handle_datagram(msg: dict, addr, transport, ctx: dict):
|
||||
host.doesack = msg.get("acks", -1)
|
||||
# send ACK back; ask client to resend plugin info when we have none yet
|
||||
rmsg = {"time": time.time()}
|
||||
if not host.plugin_data:
|
||||
if not _has_real_plugin_data(host.plugin_data):
|
||||
rmsg["request_update"] = 1
|
||||
opkt = dicttos("ACK", rmsg)
|
||||
try:
|
||||
@@ -516,7 +526,8 @@ def handle_datagram(msg: dict, addr, transport, ctx: dict):
|
||||
# cleanly from the first two post-boot samples.
|
||||
for pname in list(host.plugin_timers):
|
||||
host.cancel_plugin_timer(pname)
|
||||
host.plugin_data.clear()
|
||||
for pname in [k for k in host.plugin_data if not _is_rtt_key(k)]:
|
||||
del host.plugin_data[pname]
|
||||
stale_plugin_keys = [
|
||||
k for k in host.alert_states
|
||||
if k not in ("rtt",) and not k.startswith("connectivity.")
|
||||
|
||||
Reference in New Issue
Block a user