mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-06 23:27:04 +02:00
MINOR: proxy: add log_steps struct member
add proxy->conf.log_steps eb32 root tree which will be used to store the log origin identifiers that should result in haproxy emitting a log as configured by the user using upcoming "log-steps" proxy keyword. It was chosen to use eb32 tree instead of simple bitfield because despite the slight overhead it is more future-proof given that we already implemented the prerequisites for seamless custom log origins registration that will also be usable from "log-steps" proxy keyword.
This commit is contained in:
parent
b882402a29
commit
9341792baf
@ -426,6 +426,7 @@ struct proxy {
|
|||||||
struct arg_list args; /* sample arg list that need to be resolved */
|
struct arg_list args; /* sample arg list that need to be resolved */
|
||||||
struct ebpt_node by_name; /* proxies are stored sorted by name here */
|
struct ebpt_node by_name; /* proxies are stored sorted by name here */
|
||||||
struct list lf_checks; /* list of logformats found in the proxy section that needs to be checked during postparse */
|
struct list lf_checks; /* list of logformats found in the proxy section that needs to be checked during postparse */
|
||||||
|
struct eb_root log_steps; /* tree of log origins where log should be generated during request handling */
|
||||||
const char *file_prev; /* file of the previous instance found with the same name, or NULL */
|
const char *file_prev; /* file of the previous instance found with the same name, or NULL */
|
||||||
int line_prev; /* line of the previous instance found with the same name, or 0 */
|
int line_prev; /* line of the previous instance found with the same name, or 0 */
|
||||||
unsigned int refcount; /* refcount on this proxy (only used for default proxy for now) */
|
unsigned int refcount; /* refcount on this proxy (only used for default proxy for now) */
|
||||||
|
32
src/proxy.c
32
src/proxy.c
@ -202,6 +202,7 @@ static inline void proxy_free_common(struct proxy *px)
|
|||||||
struct acl *acl, *aclb;
|
struct acl *acl, *aclb;
|
||||||
struct logger *log, *logb;
|
struct logger *log, *logb;
|
||||||
struct lf_expr *lf, *lfb;
|
struct lf_expr *lf, *lfb;
|
||||||
|
struct eb32_node *node;
|
||||||
|
|
||||||
ha_free(&px->id);
|
ha_free(&px->id);
|
||||||
drop_file_name(&px->conf.file);
|
drop_file_name(&px->conf.file);
|
||||||
@ -259,6 +260,16 @@ static inline void proxy_free_common(struct proxy *px)
|
|||||||
|
|
||||||
chunk_destroy(&px->log_tag);
|
chunk_destroy(&px->log_tag);
|
||||||
|
|
||||||
|
node = eb32_first(&px->conf.log_steps);
|
||||||
|
while (node) {
|
||||||
|
struct eb32_node *prev_node = node;
|
||||||
|
|
||||||
|
/* log steps directly use the node key as id, they are not encapsulated */
|
||||||
|
node = eb32_next(node);
|
||||||
|
eb32_delete(prev_node);
|
||||||
|
free(prev_node);
|
||||||
|
}
|
||||||
|
|
||||||
free_email_alert(px);
|
free_email_alert(px);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1415,6 +1426,7 @@ void init_new_proxy(struct proxy *p)
|
|||||||
p->conf.used_listener_id = EB_ROOT;
|
p->conf.used_listener_id = EB_ROOT;
|
||||||
p->conf.used_server_id = EB_ROOT;
|
p->conf.used_server_id = EB_ROOT;
|
||||||
p->used_server_addr = EB_ROOT_UNIQUE;
|
p->used_server_addr = EB_ROOT_UNIQUE;
|
||||||
|
p->conf.log_steps = EB_ROOT_UNIQUE;
|
||||||
|
|
||||||
/* Timeouts are defined as -1 */
|
/* Timeouts are defined as -1 */
|
||||||
proxy_reset_timeouts(p);
|
proxy_reset_timeouts(p);
|
||||||
@ -1644,6 +1656,7 @@ static int proxy_defproxy_cpy(struct proxy *curproxy, const struct proxy *defpro
|
|||||||
{
|
{
|
||||||
struct logger *tmplogger;
|
struct logger *tmplogger;
|
||||||
char *tmpmsg = NULL;
|
char *tmpmsg = NULL;
|
||||||
|
struct eb32_node *node;
|
||||||
|
|
||||||
/* set default values from the specified default proxy */
|
/* set default values from the specified default proxy */
|
||||||
srv_settings_cpy(&curproxy->defsrv, &defproxy->defsrv, 0);
|
srv_settings_cpy(&curproxy->defsrv, &defproxy->defsrv, 0);
|
||||||
@ -1849,6 +1862,25 @@ static int proxy_defproxy_cpy(struct proxy *curproxy, const struct proxy *defpro
|
|||||||
curproxy->email_alert.level = defproxy->email_alert.level;
|
curproxy->email_alert.level = defproxy->email_alert.level;
|
||||||
curproxy->email_alert.flags = defproxy->email_alert.flags;
|
curproxy->email_alert.flags = defproxy->email_alert.flags;
|
||||||
|
|
||||||
|
/* defproxy is const pointer, so we need to typecast log_steps to
|
||||||
|
* drop the const in order to use EB tree API, please note however
|
||||||
|
* that the operations performed below should theorically be read-only
|
||||||
|
*/
|
||||||
|
node = eb32_first((struct eb_root *)&defproxy->conf.log_steps);
|
||||||
|
while (node) {
|
||||||
|
struct eb32_node *new_node;
|
||||||
|
|
||||||
|
new_node = malloc(sizeof(*new_node));
|
||||||
|
if (!new_node) {
|
||||||
|
memprintf(errmsg, "proxy '%s': out of memory for log_steps option", curproxy->id);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
new_node->key = node->key;
|
||||||
|
eb32_insert(&curproxy->conf.log_steps, new_node);
|
||||||
|
node = eb32_next(node);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user