Commit 351e100e authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add BOOL std.healthy(BACKEND) which can check if any backend is

healthy, rather than have hardcoded variables for
req.backend and bereq.backend's health.
parent 3e3619da
......@@ -328,22 +328,6 @@ REQ_VAR_R(backend, director, struct director *)
REQ_VAR_L(ttl, d_ttl, double, if (!(arg>0.0)) arg = 0;)
REQ_VAR_R(ttl, d_ttl, double)
unsigned
VRT_r_req_backend_healthy(const struct vrt_ctx *ctx)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
/*
* XXX: Not optimal, but we do not have a backend in vcl_deliver
* XXX: and we have to return something.
*/
if (ctx->req->director == NULL)
return (0);
CHECK_OBJ_NOTNULL(ctx->req->director, DIRECTOR_MAGIC);
return (VDI_Healthy(ctx->req->director));
}
/*--------------------------------------------------------------------*/
void
......@@ -366,16 +350,6 @@ VRT_r_bereq_backend(const struct vrt_ctx *ctx)
return (ctx->bo->director);
}
unsigned
VRT_r_bereq_backend_healthy(const struct vrt_ctx *ctx)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
CHECK_OBJ_NOTNULL(ctx->bo->director, DIRECTOR_MAGIC);
return (VDI_Healthy(ctx->bo->director));
}
/*--------------------------------------------------------------------*/
void
......
......@@ -6,8 +6,11 @@ server s1 {
} -start
varnish v1 -vcl+backend {
import ${vmod_std};
sub vcl_deliver {
set resp.http.x-foo = req.backend.healthy;
set resp.http.x-foo = std.healthy(req.backend);
}
} -start
......
......@@ -8,6 +8,8 @@ server s1 {
varnish v1 -vcl {
import ${vmod_std};
probe foo {
.url = "/";
.timeout = 1s;
......@@ -25,7 +27,7 @@ varnish v1 -vcl {
}
sub vcl_recv {
if (req.backend.healthy) {
if (std.healthy(req.backend)) {
return(error(200,"Backend healthy"));
} else {
return(error(500,"Backend sick"));
......
......@@ -229,13 +229,6 @@ The client's IP address.
The backend to use to service the request.
"""
),
('req.backend.healthy',
'BOOL',
( 'client',),
( ), """
XXX: remove: foo.healthy()
"""
),
('req.hash_ignore_busy',
'BOOL',
( 'recv',),
......@@ -266,13 +259,6 @@ The client's IP address.
( 'pipe', 'backend', ), """
"""
),
('bereq.backend.healthy',
'BOOL',
( 'pipe', 'backend', ),
( ), """
XXX: remove: foo.healthy()
"""
),
('bereq.method',
'STRING',
( 'pipe', 'backend', ),
......
......@@ -37,3 +37,4 @@ Function DURATION duration(STRING, DURATION)
Function INT integer(STRING, INT)
Function VOID collect(HEADER)
Function IP ip(STRING, IP)
Function BOOL healthy(BACKEND)
......@@ -42,6 +42,7 @@
#include "vtcp.h"
#include "cache/cache.h"
#include "cache/cache_backend.h"
#include "vcc_if.h"
......@@ -183,3 +184,13 @@ vmod_collect(const struct vrt_ctx *ctx, VCL_HEADER hdr)
http_CollectHdr(ctx->http_resp, hdr->what);
}
}
VCL_BOOL __match_proto__(td_std_healthy)
vmod_healthy(const struct vrt_ctx *ctx, VCL_BACKEND be)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (be == NULL)
return (0);
CHECK_OBJ_NOTNULL(be, DIRECTOR_MAGIC);
return (VDI_Healthy(be));
}
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