From 2f208a84fb3fd5ec3859f2f512b8a329bbbd65fe Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Tue, 6 Oct 2026 21:05:22 -0400 Subject: [PATCH] fix(host_agent): the server writes all five samples an agent post carries (#5181) MAX_SAMPLES_PER_INGEST was 2 while agent 1.10 drains a backlog five samples a post, so the server dropped the oldest three of every such post. Posts now answer in 0.4-1.3 s on dev, including the boot cleanup window, so five fit the agent's 10 s. A test holds the server cap at or above the agent's. Co-Authored-By: Claude Opus 5.5 --- plugins/host_agent/routes.py | 7 ++++--- tests/plugins/host_agent/test_ingest_timing.py | 8 ++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/plugins/host_agent/routes.py b/plugins/host_agent/routes.py index dbdf77c..5ee0734 100644 --- a/plugins/host_agent/routes.py +++ b/plugins/host_agent/routes.py @@ -344,9 +344,10 @@ SLOW_INGEST_SECONDS = 2.0 # instance that did not finish inside the agent's 10 s, the rollback left the # buffer full, and every later post failed the same way. The newest samples # are kept: the older ones would be lost to the agent's ring buffer anyway. -# Two (~400 rows) fits 10 s even at the ~110 rows/s measured before -# plugin_metrics got time-ordered ids; raise it once the new rate is known. -MAX_SAMPLES_PER_INGEST = 2 +# Five matches the agent's MAX_SAMPLES_PER_POST (1.10+), so its backlog posts +# land whole: ~1,000 metric rows at the 1,300-4,000 rows/s measured once +# plugin_metrics got time-ordered ids, with posts answering in 0.4-1.3 s (#5181). +MAX_SAMPLES_PER_INGEST = 5 def newest_samples(samples: list, limit: int) -> tuple[list, int]: diff --git a/tests/plugins/host_agent/test_ingest_timing.py b/tests/plugins/host_agent/test_ingest_timing.py index a3b5f3e..62cfda2 100644 --- a/tests/plugins/host_agent/test_ingest_timing.py +++ b/tests/plugins/host_agent/test_ingest_timing.py @@ -73,3 +73,11 @@ def test_a_full_backlog_is_cut_to_its_newest_samples(): def test_a_small_post_is_left_alone(): posted = [_s(3), _s(1)] assert routes.newest_samples(posted, 5) == (posted, 0) + + +def test_the_server_writes_every_sample_an_agent_post_carries(): + # An agent drains its backlog MAX_SAMPLES_PER_POST at a time; a server cap + # below that drops the oldest of every such post (#5181). + from plugins.host_agent import agent + + assert routes.MAX_SAMPLES_PER_INGEST >= agent.MAX_SAMPLES_PER_POST