MEDIUM: applet: Emit a warning when a legacy applet is spawned

To motivate developers to support the new applets API, a warning is now
emitted when a legacy applet is spawned. To not flood users, this warning is
only emitted once per legacy applet. To do so, the applet flag
APPLET_FL_WARNED was added. It is set when the warning is emitted.

Note that test and set on this flag are not performed via atomic operations.
So it is possible to have more than one warning for a given applet if it is
spawned in same time on several threads. At worrst, there is one warning per
thread.
This commit is contained in:
Christopher Faulet 2025-07-25 15:44:47 +02:00
parent 337768656b
commit b8d5307bd9
2 changed files with 9 additions and 0 deletions

View File

@ -82,6 +82,7 @@ static forceinline char *appctx_show_flags(char *buf, size_t len, const char *de
}
#define APPLET_FL_NEW_API 0x00000001 /* Set if the applet is based on the new API (using applet's buffers) */
#define APPLET_FL_WARNED 0x00000002 /* Set when warning was already emitted about a legacy applet */
/* Applet descriptor */
struct applet {

View File

@ -19,6 +19,7 @@
#include <haproxy/channel.h>
#include <haproxy/htx.h>
#include <haproxy/list.h>
#include <haproxy/log.h>
#include <haproxy/sc_strm.h>
#include <haproxy/stconn.h>
#include <haproxy/stream.h>
@ -232,6 +233,13 @@ struct appctx *appctx_new_on(struct applet *applet, struct sedesc *sedesc, int t
TRACE_ENTER(APPLET_EV_NEW);
if (unlikely(!(applet->flags & (APPLET_FL_NEW_API|APPLET_FL_WARNED)))) {
send_log(NULL, LOG_WARNING,
"Applet '%s' is based on a deprecated API. Please report this error to developers\n",
applet->name);
applet->flags |= APPLET_FL_WARNED;
}
appctx = pool_zalloc(pool_head_appctx);
if (unlikely(!appctx)) {
TRACE_ERROR("APPCTX allocation failure", APPLET_EV_NEW|APPLET_EV_ERR);