MINOR: check: Support generating a unique_id for checks

This implementation is directly modeled after `stream_generate_unique_id()` and
the corresponding `unique_id` field on `struct stream`.

It will be used in a future commit to enable the use of the `%[unique-id]`
fetch in check rules.
This commit is contained in:
Tim Duesterhus 2026-04-13 19:37:30 +02:00 committed by Willy Tarreau
parent 7ff2627112
commit 2c748125f5
3 changed files with 19 additions and 0 deletions

View File

@ -199,6 +199,7 @@ struct check {
const struct mux_proto_list *mux_proto; /* the mux to use for all outgoing connections (specified by the "proto" keyword) */
struct list check_queue; /* entry in the check queue. Not empty = in queue. */
int via_socks4; /* check the connection via socks4 proxy */
struct ist unique_id; /* custom unique ID, same as in struct stream */
};
#endif /* _HAPROXY_CHECKS_T_H */

View File

@ -26,6 +26,7 @@
#include <haproxy/proxy-t.h>
#include <haproxy/server-t.h>
#include <haproxy/trace-t.h>
#include <haproxy/log.h>
extern struct trace_source trace_check;
@ -80,6 +81,16 @@ struct task *srv_chk_io_cb(struct task *t, void *ctx, unsigned int state);
int check_buf_available(void *target);
struct buffer *check_get_buf(struct check *check, struct buffer *bptr, unsigned int small_buffer);
void check_release_buf(struct check *check, struct buffer *bptr);
static inline struct ist check_generate_unique_id(struct check *check, struct lf_expr *format)
{
if (!isttest(check->unique_id)) {
generate_unique_id(&check->unique_id, check->sess, NULL, format);
}
return check->unique_id;
}
const char *init_check(struct check *check, int type);
void free_check(struct check *check);
void check_purge(struct check *check);

View File

@ -458,6 +458,11 @@ void set_server_check_status(struct check *check, short status, const char *desc
check->result = CHK_RES_UNKNOWN; /* no result yet */
check->desc[0] = '\0';
check->start = now_ns;
/* Reset unique_id. */
pool_free(pool_head_uniqueid, istptr(check->unique_id));
check->unique_id = IST_NULL;
return;
}
@ -1558,6 +1563,8 @@ void free_check(struct check *check)
ha_free(&check->tcpcheck);
}
pool_free(pool_head_uniqueid, istptr(check->unique_id));
check->unique_id = IST_NULL;
ha_free(&check->pool_conn_name);
ha_free(&check->sni);
ha_free(&check->alpn_str);