BUG/MINOR: promex: Skip resolvers metrics when there is no resolver section

By default, there is always at least on resolver section, the default one,
based on "/etc/resolv.conf" content. However, it is possible to have no
resolver at all if the file is empty or if any error occurred. Errors are
silently ignored at this stage.

In that case, there was a bug in the Prometheus exporter leading to a crash
because the resolver section list is empty. An invalid resolver entity was
used. To fix the issue we must only take care to not dump resolvers metrics
when there is no resolver.

Thanks to Aurelien to have spotted the offending commit.

This patch should fix the issue #2604. It must be backported to 3.0.

(cherry picked from commit 91fe085943cea52d0c3d04e81f8ecb6a51668b09)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
This commit is contained in:
Christopher Faulet 2024-06-12 08:42:56 +02:00
parent abecd956e5
commit ebd0e8f699

View File

@ -3919,8 +3919,12 @@ static int rslv_promex_metric_info(unsigned int id, struct promex_metric *metric
static void *rslv_promex_start_ts(void *unused, unsigned int id)
{
struct resolvers *resolver = LIST_NEXT(&sec_resolvers, struct resolvers *, list);
struct resolvers *resolver;
if (LIST_ISEMPTY(&sec_resolvers))
return NULL;
resolver = LIST_NEXT(&sec_resolvers, struct resolvers *, list);
return LIST_NEXT(&resolver->nameservers, struct dns_nameserver *, list);
}