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