Commit 6b4cbe26 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

Expose VCL probes to VMODs

parent c9b0aa06
......@@ -150,4 +150,5 @@ too is no longer needed. It is then Varnish that will take care of health
probing and disabling the feature on cold VCL (see
:ref:`ref-vmod-event-functions`).
.. TODO document VCL_PROBE if patchwork #310 is merged
Instead of initializing your own probe definition, you can get a ``VCL_PROBE``
directly built from VCL (see :ref:`ref-vmod-vcl-c-types`).
......@@ -193,7 +193,10 @@ PRIV_TOP
PRIV_VCL
See :ref:`ref-vmod-private-pointers` below.
.. TODO document PROBE if patchwork #310 is merged
PROBE
C-type: ``const struct vrt_backend_probe *``
A named standalone backend probe definition.
REAL
C-type: ``double``
......
......@@ -67,20 +67,21 @@ struct ws;
* (alphabetic order)
*/
typedef const struct director * VCL_BACKEND;
typedef const struct vmod_priv * VCL_BLOB;
typedef unsigned VCL_BOOL;
typedef double VCL_BYTES;
typedef double VCL_DURATION;
typedef const char * VCL_ENUM;
typedef const struct gethdr_s * VCL_HEADER;
typedef struct http * VCL_HTTP;
typedef long VCL_INT;
typedef const struct suckaddr * VCL_IP;
typedef double VCL_REAL;
typedef const char * VCL_STRING;
typedef double VCL_TIME;
typedef void VCL_VOID;
typedef const struct director * VCL_BACKEND;
typedef const struct vmod_priv * VCL_BLOB;
typedef unsigned VCL_BOOL;
typedef double VCL_BYTES;
typedef double VCL_DURATION;
typedef const char * VCL_ENUM;
typedef const struct gethdr_s * VCL_HEADER;
typedef struct http * VCL_HTTP;
typedef long VCL_INT;
typedef const struct suckaddr * VCL_IP;
typedef const struct vrt_backend_probe * VCL_PROBE;
typedef double VCL_REAL;
typedef const char * VCL_STRING;
typedef double VCL_TIME;
typedef void VCL_VOID;
/***********************************************************************
* This is the composite argument we pass to compiled VCL and VRT
......
......@@ -249,7 +249,7 @@ void
vcc_ParseProbe(struct vcc *tl)
{
struct token *t_probe;
int i;
struct symbol *sym;
char *p;
vcc_NextToken(tl); /* ID: probe */
......@@ -258,11 +258,18 @@ vcc_ParseProbe(struct vcc *tl)
ERRCHK(tl);
t_probe = tl->t;
vcc_NextToken(tl);
i = vcc_AddDef(tl, t_probe, SYM_PROBE);
if (i > 1) {
sym = VCC_GetSymbolTok(tl, t_probe, SYM_PROBE);
AN(sym);
if (sym->ndef > 0) {
VSB_printf(tl->sb, "Probe %.*s redefined\n", PF(t_probe));
vcc_ErrWhere(tl, t_probe);
return;
}
sym->fmt = PROBE;
sym->eval = vcc_Eval_Probe;
sym->ndef++;
ERRCHK(tl);
vcc_ParseProbeSpec(tl, t_probe, &p);
if (vcc_IdIs(t_probe, "default")) {
......
......@@ -280,6 +280,7 @@ sym_expr_t vcc_Eval_SymFunc;
void vcc_Eval_Func(struct vcc *tl, const char *cfunc, const char *extra,
const char *name, const char *args);
sym_expr_t vcc_Eval_Backend;
sym_expr_t vcc_Eval_Probe;
/* vcc_obj.c */
extern const struct var vcc_vars[];
......
......@@ -516,6 +516,23 @@ vcc_Eval_Backend(struct vcc *tl, struct expr **e, const struct symbol *sym)
/*--------------------------------------------------------------------
*/
void
vcc_Eval_Probe(struct vcc *tl, struct expr **e, const struct symbol *sym)
{
assert(sym->kind == SYM_PROBE);
vcc_ExpectCid(tl);
vcc_AddRef(tl, tl->t, SYM_PROBE);
*e = vcc_mk_expr(PROBE, "&vgc_probe_%.*s", PF(tl->t));
(*e)->constant = EXPR_VAR; /* XXX ? */
vcc_NextToken(tl);
}
/*--------------------------------------------------------------------
*/
void
vcc_Eval_Var(struct vcc *tl, struct expr **e, const struct symbol *sym)
{
......@@ -812,6 +829,8 @@ vcc_expr4(struct vcc *tl, struct expr **e, enum var_type fmt)
sym = NULL;
if (fmt == BACKEND)
sym = VCC_FindSymbol(tl, tl->t, SYM_BACKEND);
if (fmt == PROBE)
sym = VCC_FindSymbol(tl, tl->t, SYM_PROBE);
if (sym == NULL)
sym = VCC_FindSymbol(tl, tl->t, SYM_VAR);
if (sym == NULL)
......@@ -831,6 +850,7 @@ vcc_expr4(struct vcc *tl, struct expr **e, enum var_type fmt)
case SYM_VAR:
case SYM_FUNC:
case SYM_BACKEND:
case SYM_PROBE:
AN(sym->eval);
AZ(*e);
sym->eval(tl, e, sym);
......
......@@ -60,6 +60,7 @@ ctypes = {
'PRIV_VCL': "struct vmod_priv *",
'PRIV_TASK': "struct vmod_priv *",
'PRIV_TOP': "struct vmod_priv *",
'PROBE': "VCL_PROBE",
'REAL': "VCL_REAL",
'STRING': "VCL_STRING",
'STRING_LIST': "const char *, ...",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment