Commit b815ceb3 authored by Nils Goroll's avatar Nils Goroll

bring more nuance to backend.list output for directors

by example of the round-robin director

Also changes the backend probe state

	good->healthy
	bad->sick

for consistency
parent 3ad673f2
......@@ -524,10 +524,10 @@ VBP_Status(struct vsb *vsb, const struct backend *be, int details, int json)
if (json)
VSB_printf(vsb, "[%u, %u, \"%s\"]",
vt->good, vt->window,
vt->backend->director->sick ? "bad" : "good");
vt->backend->director->sick ? "sick" : "healthy");
else
VSB_printf(vsb, "%u/%u %s", vt->good, vt->window,
vt->backend->director->sick ? "bad" : "good");
vt->backend->director->sick ? "sick" : "healthy");
return;
}
......
......@@ -229,6 +229,26 @@ VRT_Healthy(VRT_CTX, VCL_BACKEND d, VCL_TIME *changed)
return (d->vdir->methods->healthy(ctx, d, changed));
}
/*--------------------------------------------------------------------
* Update health_changed. This is for load balancing directors
* to update their health_changed time based on their backends.
*/
VCL_VOID
VRT_SetChanged(VRT_CTX, VCL_BACKEND d, VCL_TIME changed)
{
(void)ctx;
if (d == NULL)
return;
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
if (changed <= d->vdir->health_changed)
return;
d->vdir->health_changed = changed;
}
/* Send Event ----------------------------------------------------------
*/
......
......@@ -63,6 +63,7 @@
* use: AZ(ObjGetU64(req->wrk, req->body_oc, OA_LEN, &u));
* struct vdi_methods .list callback signature changed
* VRT_LookupDirector() added
* VRT_SetChanged() added
* 8.0 (2018-09-15)
* VRT_Strands() added
* VRT_StrandsWS() added
......@@ -524,6 +525,7 @@ struct director {
};
VCL_BOOL VRT_Healthy(VRT_CTX, VCL_BACKEND, VCL_TIME *);
VCL_VOID VRT_SetChanged(VRT_CTX, VCL_BACKEND, VCL_TIME);
VCL_BACKEND VRT_AddDirector(VRT_CTX, const struct vdi_methods *,
void *, const char *, ...) v_printflike_(4, 5);
void VRT_SetHealth(VCL_BACKEND d, int health);
......
......@@ -44,7 +44,7 @@ struct vmod_directors_round_robin {
unsigned nxt;
};
static VCL_BOOL v_matchproto_(vdi_healthy)
static VCL_BOOL v_matchproto_(vdi_healthy_f)
vmod_rr_healthy(VRT_CTX, VCL_BACKEND dir, VCL_TIME *changed)
{
struct vmod_directors_round_robin *rr;
......@@ -55,6 +55,17 @@ vmod_rr_healthy(VRT_CTX, VCL_BACKEND dir, VCL_TIME *changed)
return (vdir_any_healthy(ctx, rr->vd, changed));
}
static void v_matchproto_(vdi_list_f)
vmod_rr_list(VRT_CTX, VCL_BACKEND dir, struct vsb *vsb, int pflag, int jflag)
{
struct vmod_directors_round_robin *rr;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(dir, DIRECTOR_MAGIC);
CAST_OBJ_NOTNULL(rr, dir->priv, VMOD_DIRECTORS_ROUND_ROBIN_MAGIC);
return (vdir_list(ctx, rr->vd, vsb, pflag, jflag));
}
static VCL_BACKEND v_matchproto_(vdi_resolve_f)
vmod_rr_resolve(VRT_CTX, VCL_BACKEND dir)
{
......@@ -96,7 +107,8 @@ static const struct vdi_methods vmod_rr_methods[1] = {{
.type = "round-robin",
.healthy = vmod_rr_healthy,
.resolve = vmod_rr_resolve,
.destroy = vmod_rr_destroy
.destroy = vmod_rr_destroy,
.list = vmod_rr_list
}};
VCL_VOID v_matchproto_()
......
......@@ -29,10 +29,12 @@
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include "cache/cache.h"
#include "vbm.h"
#include "vsb.h"
#include "vdir.h"
......@@ -192,6 +194,74 @@ vdir_any_healthy(VRT_CTX, struct vdir *vd, VCL_TIME *changed)
return (retval);
}
void
vdir_list(VRT_CTX, struct vdir *vd, struct vsb *vsb, int pflag, int jflag)
{
VCL_TIME c, changed = 0;
VCL_BACKEND be;
VCL_BOOL h;
unsigned u, nh = 0;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(vd, VDIR_MAGIC);
if (pflag) {
if (jflag) {
VSB_printf(vsb, "{\n");
VSB_indent(vsb, 2);
} else {
VSB_printf(vsb, "\n");
}
}
vdir_rdlock(vd);
for (u = 0; u < vd->n_backend; u++) {
be = vd->backend[u];
CHECK_OBJ_NOTNULL(be, DIRECTOR_MAGIC);
c = 0;
h = VRT_Healthy(ctx, be, &c);
if (h)
nh++;
if (c > changed)
changed = c;
if ((pflag) == 0)
continue;
if (jflag) {
if (u)
VSB_printf(vsb, ",\n");
VSB_printf(vsb, "\"%s\": \"%s\"",
be->vcl_name, h ? "healthy" : "sick");
} else {
VSB_printf(vsb, "\t%s: %s\n",
be->vcl_name, h ? "healthy" : "sick");
}
}
vdir_unlock(vd);
VRT_SetChanged(ctx, vd->dir, changed);
if (jflag && (pflag)) {
VSB_printf(vsb, "\n");
VSB_indent(vsb, -2);
VSB_printf(vsb, "},\n");
}
if (pflag)
return;
/*
* for health state, the api-correct thing would be to call our own
* healthy function, but that would just re-iterate the backends for no
* real benefit
*/
if (jflag)
VSB_printf(vsb, "[%u, %u, \"%s\"]", nh, u,
nh ? "healthy" : "sick");
else
VSB_printf(vsb, "%u/%u %s", nh, u, nh ? "healthy" : "sick");
}
static unsigned
vdir_pick_by_weight(const struct vdir *vd, double w,
const struct vbitmap *blacklist)
......
......@@ -50,4 +50,5 @@ void vdir_unlock(struct vdir *vd);
void vdir_add_backend(VRT_CTX, struct vdir *, VCL_BACKEND, double weight);
void vdir_remove_backend(VRT_CTX, struct vdir *, VCL_BACKEND, unsigned *cur);
VCL_BOOL vdir_any_healthy(VRT_CTX, struct vdir *, VCL_TIME *);
void vdir_list(VRT_CTX, struct vdir *, struct vsb *, int, int);
VCL_BACKEND vdir_pick_be(VRT_CTX, struct vdir *, double w);
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