]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: check: Support generating a `unique_id` for checks
authorTim Duesterhus <tim@bastelstu.be>
Mon, 13 Apr 2026 17:37:30 +0000 (19:37 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 13 Apr 2026 18:01:42 +0000 (20:01 +0200)
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.

include/haproxy/check-t.h
include/haproxy/check.h
src/check.c

index f9f378e8a8c7927f9decd449a3ae4e740dd7239b..353fc58454dcde5e89e7e0556eda7c017d6dcf4d 100644 (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 */
index 09e195a460490fa49e5e46ed39c73f5676351ee5..e25e987f05387e1a97b6080848e0285b21f8a90a 100644 (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);
index 45baca97928c5c8e606b73d9d69e12d9e4ef28cb..481cab22fb2dd5a410b89749ec0cc2308c84ca92 100644 (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);