MINOR: sample/arg: Be able to resolve args found in defaults sections

It is not yet used but thanks to this patch, it will be possible to resolve
arguments found in defaults sections. However, there is some restrictions:

  * For FE (frontend) or BE (backend) arguments, if the proxy is explicity
    defined, there is no change. But for implicit proxy (not specified), the
    argument points on the default proxy. when a sample fetch using this
    kind of argument is evaluated, the default proxy replaced by the current
    one.

  * For SRV (server) and TAB (stick-table)arguments, the proxy must always
    be specified. Otherwise an error is reported.

This patch is mandatory to support TCP/HTTP rules in defaults sections.
This commit is contained in:
Christopher Faulet 2021-10-12 18:48:05 +02:00
parent dfd10ab5ee
commit 37a9e21a3a
3 changed files with 92 additions and 15 deletions

View File

@ -2669,11 +2669,15 @@ int backend_parse_balance(const char **args, char **err, struct proxy *curproxy)
static int
smp_fetch_nbsrv(const struct arg *args, struct sample *smp, const char *kw, void *private)
{
struct proxy *px;
struct proxy *px = args->data.prx;
if (px == NULL)
return 0;
if (px->cap & PR_CAP_DEF)
px = smp->px;
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
px = args->data.prx;
smp->data.u.sint = be_usable_srv(px);
@ -2708,12 +2712,18 @@ static int
smp_fetch_connslots(const struct arg *args, struct sample *smp, const char *kw, void *private)
{
struct server *iterator;
struct proxy *px = args->data.prx;
if (px == NULL)
return 0;
if (px->cap & PR_CAP_DEF)
px = smp->px;
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
smp->data.u.sint = 0;
for (iterator = args->data.prx->srv; iterator; iterator = iterator->next) {
for (iterator = px->srv; iterator; iterator = iterator->next) {
if (iterator->cur_state == SRV_ST_STOPPED)
continue;
@ -2822,9 +2832,16 @@ smp_fetch_srv_name(const struct arg *args, struct sample *smp, const char *kw, v
static int
smp_fetch_be_sess_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
{
struct proxy *px = args->data.prx;
if (px == NULL)
return 0;
if (px->cap & PR_CAP_DEF)
px = smp->px;
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
smp->data.u.sint = read_freq_ctr(&args->data.prx->be_sess_per_sec);
smp->data.u.sint = read_freq_ctr(&px->be_sess_per_sec);
return 1;
}
@ -2835,9 +2852,16 @@ smp_fetch_be_sess_rate(const struct arg *args, struct sample *smp, const char *k
static int
smp_fetch_be_conn(const struct arg *args, struct sample *smp, const char *kw, void *private)
{
struct proxy *px = args->data.prx;
if (px == NULL)
return 0;
if (px->cap & PR_CAP_DEF)
px = smp->px;
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
smp->data.u.sint = args->data.prx->beconn;
smp->data.u.sint = px->beconn;
return 1;
}
@ -2850,14 +2874,19 @@ static int
smp_fetch_be_conn_free(const struct arg *args, struct sample *smp, const char *kw, void *private)
{
struct server *iterator;
struct proxy *px;
struct proxy *px = args->data.prx;
unsigned int maxconn;
if (px == NULL)
return 0;
if (px->cap & PR_CAP_DEF)
px = smp->px;
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
smp->data.u.sint = 0;
for (iterator = args->data.prx->srv; iterator; iterator = iterator->next) {
for (iterator = px->srv; iterator; iterator = iterator->next) {
if (iterator->cur_state == SRV_ST_STOPPED)
continue;
@ -2888,9 +2917,16 @@ smp_fetch_be_conn_free(const struct arg *args, struct sample *smp, const char *k
static int
smp_fetch_queue_size(const struct arg *args, struct sample *smp, const char *kw, void *private)
{
struct proxy *px = args->data.prx;
if (px == NULL)
return 0;
if (px->cap & PR_CAP_DEF)
px = smp->px;
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
smp->data.u.sint = args->data.prx->totpend;
smp->data.u.sint = px->totpend;
return 1;
}
@ -2905,12 +2941,16 @@ smp_fetch_queue_size(const struct arg *args, struct sample *smp, const char *kw,
static int
smp_fetch_avg_queue_size(const struct arg *args, struct sample *smp, const char *kw, void *private)
{
struct proxy *px = args->data.prx;
int nbsrv;
struct proxy *px;
if (px == NULL)
return 0;
if (px->cap & PR_CAP_DEF)
px = smp->px;
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
px = args->data.prx;
nbsrv = be_usable_srv(px);

View File

@ -211,9 +211,16 @@ smp_fetch_fe_defbe(const struct arg *args, struct sample *smp, const char *kw, v
static int
smp_fetch_fe_req_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
{
struct proxy *px = args->data.prx;
if (px == NULL)
return 0;
if (px->cap & PR_CAP_DEF)
px = smp->px;
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
smp->data.u.sint = read_freq_ctr(&args->data.prx->fe_req_per_sec);
smp->data.u.sint = read_freq_ctr(&px->fe_req_per_sec);
return 1;
}
@ -224,9 +231,16 @@ smp_fetch_fe_req_rate(const struct arg *args, struct sample *smp, const char *kw
static int
smp_fetch_fe_sess_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
{
struct proxy *px = args->data.prx;
if (px == NULL)
return 0;
if (px->cap & PR_CAP_DEF)
px = smp->px;
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
smp->data.u.sint = read_freq_ctr(&args->data.prx->fe_sess_per_sec);
smp->data.u.sint = read_freq_ctr(&px->fe_sess_per_sec);
return 1;
}
@ -237,9 +251,16 @@ smp_fetch_fe_sess_rate(const struct arg *args, struct sample *smp, const char *k
static int
smp_fetch_fe_conn(const struct arg *args, struct sample *smp, const char *kw, void *private)
{
struct proxy *px = args->data.prx;
if (px == NULL)
return 0;
if (px->cap & PR_CAP_DEF)
px = smp->px;
smp->flags = SMP_F_VOL_TEST;
smp->data.type = SMP_T_SINT;
smp->data.u.sint = args->data.prx->feconn;
smp->data.u.sint = px->feconn;
return 1;
}

View File

@ -1217,8 +1217,16 @@ int smp_resolve_args(struct proxy *p, char **err)
break;
}
}
else
else {
if (px->cap & PR_CAP_DEF) {
memprintf(err, "%sparsing [%s:%d]: backend name must be set in arg %d of %s%s%s%s '%s' %s proxy '%s'.\n",
*err ? *err : "", cur->file, cur->line,
cur->arg_pos + 1, conv_pre, conv_ctx, conv_pos, ctx, cur->kw, where, p->id);
cfgerr++;
break;
}
sname = arg->data.str.area;
}
srv = findserver(px, sname);
if (!srv) {
@ -1293,8 +1301,16 @@ int smp_resolve_args(struct proxy *p, char **err)
case ARGT_TAB:
if (arg->data.str.data)
stktname = arg->data.str.area;
else
else {
if (px->cap & PR_CAP_DEF) {
memprintf(err, "%sparsing [%s:%d]: table name must be set in arg %d of %s%s%s%s '%s' %s proxy '%s'.\n",
*err ? *err : "", cur->file, cur->line,
cur->arg_pos + 1, conv_pre, conv_ctx, conv_pos, ctx, cur->kw, where, p->id);
cfgerr++;
break;
}
stktname = px->id;
}
t = stktable_find_by_name(stktname);
if (!t) {