Commit 7791a8ad authored by Nils Goroll's avatar Nils Goroll

the healthy callback should not resolve in cli context

parent ec231cbb
......@@ -26,11 +26,12 @@ AM_VTC_LOG_FLAGS = \
-p vmod_path="$(abs_builddir)/.libs:$(vmoddir)"
TESTS = \
vtc/cfg.vtc \
vtc/deep.vtc \
vtc/cfg.vtc \
vtc/deep.vtc \
vtc/deep_stk.vtc \
vtc/shallow.vtc \
vtc/lazy.vtc
vtc/shallow.vtc \
vtc/lazy.vtc \
vtc/lazy_shard.vtc
# Documentation
......
......@@ -539,9 +539,28 @@ vmod_cluster_backend(VRT_CTX,
return (cluster_resolve(ctx, pr, resolve));
}
/*
* layered directors may not be prepared to resolve outside a VCL task, so when
* called from the cli (no method, no vcl), just return health of the real
* backend
*/
static VCL_BOOL
vmod_cluster_healthy(VRT_CTX, VCL_BACKEND be, VCL_TIME *c)
{
be = vmod_cluster_resolve(ctx, be);
const struct vmod_cluster_cluster *vc;
const struct vmod_cluster_cluster_param *p;
if (ctx->vcl && ctx->method) {
be = vmod_cluster_resolve(ctx, be);
} else {
CAST_OBJ_NOTNULL(vc, be->priv,
VMOD_CLUSTER_CLUSTER_MAGIC);
p = vc->param;
CHECK_OBJ_NOTNULL(p,
VMOD_CLUSTER_CLUSTER_PARAM_MAGIC);
be = p->real;
}
return VRT_Healthy(ctx, be, c);
}
varnishtest "vmod_cluster toy example with round-robin - lazy resolution"
server s1 {
rxreq
txresp
} -start
server s2 {
}
server s3 {
rxreq
txresp
} -start
varnish v1 -vcl+backend {
import cluster;
import directors;
sub vcl_init {
new shard = directors.shard();
shard.add_backend(s1);
shard.add_backend(s2);
shard.reconfigure();
new cl = cluster.cluster(shard.backend(), deny=s2, real=s3);
}
sub vcl_recv {
return (pass);
}
sub vcl_backend_fetch {
set bereq.http.shard = shard.backend();
set bereq.http.unc1 = cl.get_uncacheable_direct();
set bereq.backend = cl.backend(uncacheable_direct=false);
set bereq.http.unc2 = cl.get_uncacheable_direct();
}
sub vcl_backend_response {
set beresp.http.shard = bereq.http.shard;
set beresp.http.unc1 = bereq.http.unc1;
set beresp.http.backend = beresp.backend;
set beresp.http.unc2 = bereq.http.unc2;
}
} -start
varnish v1 -cliexpect "shard.*healthy" "backend.list"
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.http.unc1 == "true"
expect resp.http.shard == "s2"
expect resp.http.backend == "s3"
expect resp.http.unc2 == "false"
txreq -url "/foo"
rxresp
expect resp.status == 200
expect resp.http.unc1 == "true"
expect resp.http.backend == "s1"
expect resp.http.unc2 == "false"
} -run
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