Skip to content

Skip zlib metrics in Prometheus exporter when built with libslz#22

Draft
Copilot wants to merge 14 commits intomasterfrom
copilot/improve-prometheus-metrics
Draft

Skip zlib metrics in Prometheus exporter when built with libslz#22
Copilot wants to merge 14 commits intomasterfrom
copilot/improve-prometheus-metrics

Conversation

Copy link

Copilot AI commented Feb 6, 2026

When HAProxy is built with libslz instead of zlib, the Prometheus exporter exports haproxy_process_current_zlib_memory and haproxy_process_max_zlib_memory metrics with NaN values, as these metrics are only populated when USE_ZLIB is defined.

Changes

  • Added preprocessor guard in promex_dump_global_metrics() to skip ST_I_INF_ZLIB_MEM_USAGE and ST_I_INF_MAX_ZLIB_MEM_USAGE when USE_ZLIB is not defined
  • Metrics are now conditionally exported based on actual compression backend in use
#ifndef USE_ZLIB
    case ST_I_INF_ZLIB_MEM_USAGE:
    case ST_I_INF_MAX_ZLIB_MEM_USAGE:
        /* Skip zlib metrics when built with libslz */
        continue;
#endif

This aligns the Prometheus exporter behavior with the stats subsystem, which already conditionally populates these fields under #ifdef USE_ZLIB.

Original prompt

This section details on the original issue you should resolve

<issue_title>improve prometheus metrics</issue_title>
<issue_description>when haproxy is built with libslz (not zlib), the following metrics are irrelevant

# HELP haproxy_process_current_zlib_memory Amount of memory currently used by HTTP compression on the current worker process (in bytes)
# TYPE haproxy_process_current_zlib_memory gauge
haproxy_process_current_zlib_memory NaN
# HELP haproxy_process_max_zlib_memory Limit on the amount of memory used by HTTP compression above which it is automatically disabled (in bytes, see global.maxzlibmem)
# TYPE haproxy_process_max_zlib_memory gauge
haproxy_process_max_zlib_memory NaN

we need not to add that metric if haproxy is built with slz</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

a-denoyelle and others added 13 commits February 6, 2026 14:35
Default proxies validation occurs during post-parsing. The objective is
to report any tcp/http-rules which could not behave as expected.

Previously, this was performed while looping over standard proxies list,
when such proxy is referencing a default instance. This was enough as
only named referenced proxies were kept after parsing. However, this is
not the case anymore in the context of dynamic backends creation at
runtime.

As such, this patch now performs validation on every named defaults
outside of the standard proxies list loop. This should not cause any
behavior difference, as defaults are validated without using the proxy
which relies on it.

Along with this change, PR_FL_READY proxy flag is now removed. Its usage
was only really needed for defaults, to avoid validating a same instance
multiple times. With the validation of defaults in their own loop, it is
now redundant.
A lot of proxies initialization code is delayed on post-parsing stage,
as it depends on the configuration fully parsed. This is performed via a
loop on proxies_list.

Extract this code in a dedicated function proxy_finalize(). This patch
will be useful for dynamic backends creation.

Note that for the moment the code has been extracted as-is. With each
new features, some init code was added there. This has become a giant
loop with no real ordering. A future patch may provide some cleanup in
order to reorganize this.
If a proxy is referencing a defaults instance, some checks must be
performed to ensure that inheritance will be compatible. Refcount of the
defaults instance may also be incremented if some settings cannot be
copied. This operation is performed when parsing a new proxy of defaults
section which references a defaults, either implicitely or explicitely.

This patch extracts this code into a dedicated function named
proxy_ref_defaults(). This in turn may call defaults_px_ref()
(previously called proxy_ref_defaults()) to increment its refcount.

The objective of this patch is to be able to reuse defaults inheritance
validation for dynamic backends created at runtime, outside of the
parsing code.
Define a new utility function str_to_proxy_mode() which is able to
convert a string into the corresponding proxy mode if possible. This new
function is used for the parsing of "mode" configuration proxy keyword.

This patch will be reused for dynamic backend implementation, in order
to parse a similar "mode" argument via a CLI handler.
Move backend compatibility checks performed during 'add server' in a
dedicated function be_supports_dynamic_srv(). This should simplify
addition of future restriction.

This function will be reused when implementing backend creation at
runtime.
Define a basic CLI handler for "add backend".

For now, this handler only performs a parsing of the name argument and
return an error if a duplicate already exists. It runs under thread
isolation, to guarantee thread safety during the proxy creation.

This feature is considered in development. CLI command requires to set
experimental-mode.
Add an optional "mode" argument to "add backend" CLI command. This
argument allows to specify if the backend is in TCP or HTTP mode.

By default, it is mandatory, unless the inherited default proxy already
explicitely specifies the mode. To differentiate if TCP mode is implicit
or explicit, a new proxy flag PR_FL_DEF_EXPLICIT_MODE is defined. It is
set for every defaults instances which explicitely defined their mode.
Defines an extra optional GUID argument for "add backend" command. This
can be useful as it is not possible to define it via a default proxy
instance.
This commits completes "add backend" handler with some checks performed
on the specified default proxy instance. These are additional checks
outside of the already existing inheritance rules, specific to dynamic
backends.

For now, a default proxy is considered not compatible if it is not in
mode TCP/HTTP. Also, a default proxy is rejected if it references HTTP
errors. This limitation may be lifted in the future, when HTTP errors
are partiallay reworked.
Implement the required operations for "add backend" handler. This
requires a new proxy allocation, settings copy from the specified
default instance and proxy config finalization. All handlers registered
via REGISTER_POST_PROXY_CHECK() are also called on the newly created
instance.

If no error were encountered, the newly created proxy is finally
attached in the proxies list.
Implement proxy ID generation for dynamic backends. This is performed
through the already function existing proxy_get_next_id().

As an optimization, lookup will performed starting from a global
variable <dynpx_next_id>. It is initialized to the greatest ID assigned
after parsing, and updated each time a backend instance is created. When
backend deletion will be implemented, it could be lowered to the newly
available slot.
Add a new regtests to validate backend creation at runtime. A server is
then added and requests made to validate the newly created instance
before (with force-be-switch) and after publishing.
Co-authored-by: chipitsine <2217296+chipitsine@users.noreply.github.com>
Copilot AI changed the title [WIP] Remove irrelevant metrics for slz build in Prometheus Skip zlib metrics in Prometheus exporter when built with libslz Feb 6, 2026
Copilot AI requested a review from chipitsine February 6, 2026 19:45
@chipitsine chipitsine force-pushed the master branch 2 times, most recently from a8bc83b to 2a07dc9 Compare February 7, 2026 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

improve prometheus metrics

3 participants