mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2024-12-27 23:22:09 +00:00
MINOR: log: Enable the log sampling and load-balancing feature.
This patch implements the sampling and load-balancing of log servers configured with "sample" new keyword implemented by this commit: 'MINOR: log: Add "sample" new keyword to "log" lines'. As the list of ranges used to sample the log to balance is ordered, we only have to maintain ->curr_idx member of smp_info struct which is the index of the sample and check if it belongs or not to the current range to decide if we must send it to the log server or not.
This commit is contained in:
parent
d95ea2897e
commit
d803e475e5
@ -443,6 +443,7 @@ enum lock_label {
|
||||
START_LOCK,
|
||||
TLSKEYS_REF_LOCK,
|
||||
AUTH_LOCK,
|
||||
LOGSRV_LOCK,
|
||||
OTHER_LOCK,
|
||||
LOCK_LABELS
|
||||
};
|
||||
@ -559,6 +560,7 @@ static inline const char *lock_label(enum lock_label label)
|
||||
case START_LOCK: return "START";
|
||||
case TLSKEYS_REF_LOCK: return "TLSKEYS_REF";
|
||||
case AUTH_LOCK: return "AUTH";
|
||||
case LOGSRV_LOCK: return "LOGSRV";
|
||||
case OTHER_LOCK: return "OTHER";
|
||||
case LOCK_LABELS: break; /* keep compiler happy */
|
||||
};
|
||||
|
@ -54,6 +54,17 @@ extern THREAD_LOCAL char *logline;
|
||||
extern THREAD_LOCAL char *logline_rfc5424;
|
||||
|
||||
|
||||
/*
|
||||
* Test if <idx> index numbered from 0 is in <rg> range with low and high
|
||||
* limits of indexes numbered from 1.
|
||||
*/
|
||||
static inline int in_smp_log_range(struct smp_log_range *rg, unsigned int idx)
|
||||
{
|
||||
if (idx + 1 <= rg->high && idx + 1 >= rg->low)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Initialize/Deinitialize log buffers used for syslog messages */
|
||||
int init_log_buffers();
|
||||
void deinit_log_buffers();
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <sys/un.h>
|
||||
#include <netinet/in.h>
|
||||
#include <common/config.h>
|
||||
#include <common/hathreads.h>
|
||||
#include <common/mini-clist.h>
|
||||
|
||||
#define NB_LOG_FACILITIES 24
|
||||
@ -202,6 +203,7 @@ struct logsrv {
|
||||
int minlvl;
|
||||
int maxlen;
|
||||
struct logsrv *ref;
|
||||
__decl_hathreads(HA_SPINLOCK_T lock);
|
||||
};
|
||||
|
||||
#endif /* _TYPES_LOG_H */
|
||||
|
25
src/log.c
25
src/log.c
@ -946,6 +946,7 @@ int parse_logsrv(char **args, struct list *logsrvs, int do_del, char **err)
|
||||
|
||||
cur_arg += 2;
|
||||
}
|
||||
HA_SPIN_INIT(&logsrv->lock);
|
||||
/* parse the facility */
|
||||
logsrv->facility = get_log_facility(args[cur_arg]);
|
||||
if (logsrv->facility < 0) {
|
||||
@ -1722,12 +1723,32 @@ void __send_log(struct proxy *p, int level, char *message, size_t size, char *sd
|
||||
/* Send log messages to syslog server. */
|
||||
nblogger = 0;
|
||||
list_for_each_entry(logsrv, logsrvs, list) {
|
||||
static THREAD_LOCAL int in_range = 1;
|
||||
|
||||
/* we can filter the level of the messages that are sent to each logger */
|
||||
if (level > logsrv->level)
|
||||
continue;
|
||||
|
||||
__do_send_log(logsrv, ++nblogger, pid.area, pid.data, level,
|
||||
message, size, sd, sd_size, tag->area, tag->data);
|
||||
if (logsrv->lb.smp_rgs) {
|
||||
struct smp_log_range *curr_rg;
|
||||
|
||||
HA_SPIN_LOCK(LOGSRV_LOCK, &logsrv->lock);
|
||||
curr_rg = &logsrv->lb.smp_rgs[logsrv->lb.curr_rg];
|
||||
in_range = in_smp_log_range(curr_rg, logsrv->lb.curr_idx);
|
||||
if (in_range) {
|
||||
/* Let's consume this range. */
|
||||
curr_rg->curr_idx = (curr_rg->curr_idx + 1) % curr_rg->sz;
|
||||
if (!curr_rg->curr_idx) {
|
||||
/* If consumed, let's select the next range. */
|
||||
logsrv->lb.curr_rg = (logsrv->lb.curr_rg + 1) % logsrv->lb.smp_rgs_sz;
|
||||
}
|
||||
}
|
||||
logsrv->lb.curr_idx = (logsrv->lb.curr_idx + 1) % logsrv->lb.smp_sz;
|
||||
HA_SPIN_UNLOCK(LOGSRV_LOCK, &logsrv->lock);
|
||||
}
|
||||
if (in_range)
|
||||
__do_send_log(logsrv, ++nblogger, pid.area, pid.data, level,
|
||||
message, size, sd, sd_size, tag->area, tag->data);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user