Commit bc5f754f authored by Nils Goroll's avatar Nils Goroll

Also add a ctx to vdi_list_f (director list callback)

... to bring "more nuance" (quote phk) to the director health
state output, the list callback needs to be able to query
VRT_Health() of the director's backends, so, in turn, we also
need a CTX here.

Ref https://github.com/varnishcache/varnish-cache/pull/2888#issuecomment-460258147

Of the following out-of-tree vmods, none uses the .list callback,
so I expect minimal vmod author uprise:

	- saintmode (varnish-modules)
	- all_healthy
	- dynamic
	- cluster
	- weightadjust (someome(tm) needs to update to vdi_methods)
parent 0d6803d2
......@@ -445,12 +445,14 @@ vbe_panic(const struct director *d, struct vsb *vsb)
/*--------------------------------------------------------------------
*/
static void
vbe_list(const struct director *d, struct vsb *vsb, int vflag, int pflag,
int jflag)
static void v_matchproto_(vdi_list_f)
vbe_list(VRT_CTX, const struct director *d, struct vsb *vsb, int vflag,
int pflag, int jflag)
{
struct backend *bp;
(void)ctx;
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
CAST_OBJ_NOTNULL(bp, d->priv, BACKEND_MAGIC);
......
......@@ -278,15 +278,9 @@ struct list_args {
};
static const char *
cli_health(struct director *d)
cli_health(VRT_CTX, struct director *d)
{
struct vrt_ctx *ctx;
VCL_BOOL healthy;
ctx = VCL_Get_CliCtx(0,0);
healthy = VRT_Healthy(ctx, d, NULL);
VCL_Rel_CliCtx(&ctx);
AZ(ctx);
VCL_BOOL healthy = VRT_Healthy(ctx, d, NULL);
return (healthy ? "healthy" : "sick");
}
......@@ -296,6 +290,7 @@ do_list(struct cli *cli, struct director *d, void *priv)
{
char time_str[VTIM_FORMAT_SIZE];
struct list_args *la;
struct vrt_ctx *ctx;
CAST_OBJ_NOTNULL(la, priv, LIST_ARGS_MAGIC);
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
......@@ -303,18 +298,24 @@ do_list(struct cli *cli, struct director *d, void *priv)
if (d->vdir->admin_health == VDI_AH_DELETED)
return (0);
ctx = VCL_Get_CliCtx(0,0);
// XXX admin health "probe" for the no-probe case is confusing
VCLI_Out(cli, "\n%-30s %-7s ", d->vdir->cli_name, VDI_Ahealth(d));
if (d->vdir->methods->list != NULL)
d->vdir->methods->list(d, cli->sb, 0, 0, 0);
d->vdir->methods->list(ctx, d, cli->sb, 0, 0, 0);
else
VCLI_Out(cli, "%-10s", cli_health(d));
VCLI_Out(cli, "%-10s", cli_health(ctx, d));
VTIM_format(d->vdir->health_changed, time_str);
VCLI_Out(cli, " %s", time_str);
if ((la->p || la->v) && d->vdir->methods->list != NULL)
d->vdir->methods->list(d, cli->sb, la->p, la->v, 0);
d->vdir->methods->list(ctx, d, cli->sb, la->p, la->v, 0);
VCL_Rel_CliCtx(&ctx);
AZ(ctx);
return (0);
}
......@@ -322,6 +323,7 @@ static int v_matchproto_(vcl_be_func)
do_list_json(struct cli *cli, struct director *d, void *priv)
{
struct list_args *la;
struct vrt_ctx *ctx;
CAST_OBJ_NOTNULL(la, priv, LIST_ARGS_MAGIC);
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
......@@ -329,6 +331,8 @@ do_list_json(struct cli *cli, struct director *d, void *priv)
if (d->vdir->admin_health == VDI_AH_DELETED)
return (0);
ctx = VCL_Get_CliCtx(0,0);
VCLI_Out(cli, "%s", la->jsep);
la->jsep = ",\n";
// XXX admin health "probe" for the no-probe case is confusing
......@@ -339,18 +343,22 @@ do_list_json(struct cli *cli, struct director *d, void *priv)
VCLI_Out(cli, "\"admin_health\": \"%s\",\n", VDI_Ahealth(d));
VCLI_Out(cli, "\"probe_message\": ");
if (d->vdir->methods->list != NULL)
d->vdir->methods->list(d, cli->sb, 0, 0, 1);
d->vdir->methods->list(ctx, d, cli->sb, 0, 0, 1);
else
VCLI_Out(cli, "\"%s\"", cli_health(d));
VCLI_Out(cli, "\"%s\"", cli_health(ctx, d));
VCLI_Out(cli, ",\n");
if ((la->p || la->v) && d->vdir->methods->list != NULL) {
VCLI_Out(cli, "\"probe_details\": ");
d->vdir->methods->list(d, cli->sb, la->p, la->v, 1);
d->vdir->methods->list(ctx, d, cli->sb, la->p, la->v, 1);
}
VCLI_Out(cli, "\"last_change\": %.3f\n", d->vdir->health_changed);
VSB_indent(cli->sb, -2);
VCLI_Out(cli, "}");
VCL_Rel_CliCtx(&ctx);
AZ(ctx);
return (0);
}
......
......@@ -60,6 +60,7 @@
* changed VRT_blob()
* req->req_bodybytes removed
* use: AZ(ObjGetU64(req->wrk, req->body_oc, OA_LEN, &u));
* struct vdi_methods .list callback signature changed
* 8.0 (2018-09-15)
* VRT_Strands() added
* VRT_StrandsWS() added
......@@ -476,7 +477,7 @@ typedef enum sess_close vdi_http1pipe_f(VRT_CTX, VCL_BACKEND);
typedef void vdi_event_f(VCL_BACKEND, enum vcl_event_e);
typedef void vdi_destroy_f(VCL_BACKEND);
typedef void vdi_panic_f(VCL_BACKEND, struct vsb *);
typedef void vdi_list_f(VCL_BACKEND, struct vsb *, int, int, int);
typedef void vdi_list_f(VRT_CTX, VCL_BACKEND, struct vsb *, int, int, int);
struct vdi_methods {
unsigned magic;
......
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