]> git.ipfire.org Git - thirdparty/haproxy.git/commit
BUG/MINOR: stats: fix STAT_STARTED behavior with full htx
authorAurelien DARRAGON <adarragon@haproxy.com>
Thu, 2 Feb 2023 18:01:02 +0000 (19:01 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 6 Feb 2023 06:53:03 +0000 (07:53 +0100)
commit90304dcdd8048e88cbfcc55acdd6202cb416ba93
treedf32dc93b289d89d8d56aa38573ed26355009ab7
parent28a23617cebbb0c516eeec944e18ba20db72184f
BUG/MINOR: stats: fix STAT_STARTED behavior with full htx

When stats_putchk() fails to peform the dump because available data space in
htx is less than the number of bytes pending in the dump buffer, we wait
for more room in the htx (ie: sc_need_room()) to retry the dump attempt
on the next applet invocation.

To provide consistent output, we have to make sure that the stat ctx is not
updated (or at least correctly reverted) in case stats_putchk() fails so
that the new dumping attempt behaves just like the previous (failed) one.

STAT_STARTED is not following this logic, the flag is set in
stats_dump_fields_json() as soon as some data is written to the output buffer.

It's done too early: we need to delay this step after the stats_putchk() has
successfully returned if we want to correctly handle the retries attempts.

Because of this, JSON output could suffer from extraneous ',' characters which
could make json parsers unhappy.

For example, this is the kind of errors you could get when using
`python -m json.tool` on such badly formatted outputs:

   "Expecting value: line 1 column 2 (char 1)"

Unfortunately, fixing this means that the flag needs to be enabled at
multiple places, which is what we're doing in this patch.
(in stats_dump_proxy_to_buffer() where stats_dump_one_line() is involved
by underlying stats_dump_{fe,li,sv,be} functions)

Thereby, this raises the need for a cleanup to reduce code duplication around
stats_dump_proxy_to_buffer() function and simplify things a bit.

It could be backported to 2.6 and 2.7
src/stats.c