]> err.no Git - varnish/commitdiff
Add string representation of backend
authortfheen <tfheen@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 17 Sep 2008 10:04:47 +0000 (10:04 +0000)
committertfheen <tfheen@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 17 Sep 2008 10:04:47 +0000 (10:04 +0000)
This takes the name from the name assigned in the VCL.

Partially fixes #294.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3197 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache_backend.h
varnish-cache/bin/varnishd/cache_dir_random.c
varnish-cache/bin/varnishd/cache_dir_round_robin.c
varnish-cache/bin/varnishd/cache_dir_simple.c
varnish-cache/bin/varnishd/cache_vrt.c
varnish-cache/bin/varnishtest/tests/b00016.vtc [new file with mode: 0644]
varnish-cache/include/vrt.h
varnish-cache/lib/libvcl/vcc_string.c

index 780fdc4c0abe980cb6298dc8c0d3967bc7e68974..0b78dea56095497b9f48e751f214f0cbb4f03e31 100644 (file)
@@ -85,6 +85,7 @@ struct director {
        unsigned                magic;
 #define DIRECTOR_MAGIC         0x3336351d
        const char              *name;
+       char                    *vcl_name;
        vdi_getfd_f             *getfd;
        vdi_fini_f              *fini;
        vdi_healthy             *healthy;
index bb386f79ef40a4adae479f66a3c902d02613f88b..35c08c92bf59284d7e47e2ab2e2ecbbae4c31c25 100644 (file)
@@ -152,6 +152,7 @@ vdi_random_fini(struct director *d)
        for (i = 0; i < vs->nhosts; i++, vh++)
                VBE_DropRef(vh->backend);
        free(vs->hosts);
+       free(vs->dir.vcl_name);
        vs->dir.magic = 0;
        FREE_OBJ(vs);
 }
@@ -174,6 +175,7 @@ VRT_init_dir_random(struct cli *cli, struct director **bp, const struct vrt_dir_
        vs->dir.magic = DIRECTOR_MAGIC;
        vs->dir.priv = vs;
        vs->dir.name = "random";
+       REPLACE(vs->dir.vcl_name, t->name);
        vs->dir.getfd = vdi_random_getfd;
        vs->dir.fini = vdi_random_fini;
        vs->dir.healthy = vdi_random_healthy;
index de7fc240810620d0e812a30f1c87d77c7d92b052..479657c438abe6ffbb902b4a9c3cf16c7d57b4d0 100644 (file)
@@ -116,6 +116,7 @@ vdi_round_robin_fini(struct director *d)
        for (i = 0; i < vs->nhosts; i++, vh++)
                VBE_DropRef(vh->backend);
        free(vs->hosts);
+       free(vs->dir.vcl_name);
        vs->dir.magic = 0;
        vs->next_host = 0;
        FREE_OBJ(vs);
@@ -139,6 +140,7 @@ VRT_init_dir_round_robin(struct cli *cli, struct director **bp, const struct vrt
        vs->dir.magic = DIRECTOR_MAGIC;
        vs->dir.priv = vs;
        vs->dir.name = "round_robin";
+       REPLACE(vs->dir.vcl_name, t->name);
        vs->dir.getfd = vdi_round_robin_getfd;
        vs->dir.fini = vdi_round_robin_fini;
        vs->dir.healthy = vdi_round_robin_healthy;
index e0e8b81f3ae944fa2096a174603e7cfaa66f945c..dc47fa0b1b99ec59a442e9eb12424ec03b9afdf2 100644 (file)
@@ -87,6 +87,7 @@ vdi_simple_fini(struct director *d)
        CAST_OBJ_NOTNULL(vs, d->priv, VDI_SIMPLE_MAGIC);
        
        VBE_DropRef(vs->backend);
+       free(vs->dir.vcl_name);
        vs->dir.magic = 0;
        FREE_OBJ(vs);
 }
@@ -103,6 +104,7 @@ VRT_init_dir_simple(struct cli *cli, struct director **bp, const struct vrt_dir_
        vs->dir.magic = DIRECTOR_MAGIC;
        vs->dir.priv = vs;
        vs->dir.name = "simple";
+       REPLACE(vs->dir.vcl_name, t->host->vcl_name);
        vs->dir.getfd = vdi_simple_getfd;
        vs->dir.fini = vdi_simple_fini;
        vs->dir.healthy = vdi_simple_healthy;
index c1e9222474aed39e9c481ea992fdbe3e40b6e78c..dc08fb465c4f2701cfd78e9435d331c840b750ba 100644 (file)
@@ -648,6 +648,14 @@ VRT_double_string(const struct sess *sp, double num)
        return (p);
 }
 
+const char *
+VRT_backend_string(struct sess *sp)
+{
+       CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+       CHECK_OBJ_NOTNULL(sp->director, DIRECTOR_MAGIC);
+       return (sp->director->vcl_name);
+}
+
 /*--------------------------------------------------------------------*/
 
 void
diff --git a/varnish-cache/bin/varnishtest/tests/b00016.vtc b/varnish-cache/bin/varnishtest/tests/b00016.vtc
new file mode 100644 (file)
index 0000000..cf70f6a
--- /dev/null
@@ -0,0 +1,73 @@
+# $Id$
+
+test "Check naming of backends"
+
+varnish v1 -vcl { 
+       backend foo {
+               .host = "127.0.0.2";
+               .port = "9080";
+       }
+
+       sub vcl_recv {
+           error 200 "ok";
+       }
+
+       sub vcl_error {
+           set obj.http.X-Backend-Name = req.backend;
+       }
+} -start
+
+client c1 {
+       txreq -url "/"
+       rxresp
+       expect resp.http.X-Backend-Name == "foo"
+} -run
+
+varnish v1 -vcl { 
+       director bar random {
+               {
+               .backend = {
+                       .host = "127.0.0.2";
+                       .port = "9080";
+               }
+               .weight = 1;
+               }
+       }
+
+       sub vcl_recv {
+           error 200 "ok";
+       }
+
+       sub vcl_error {
+           set obj.http.X-Backend-Name = req.backend;
+       }
+}
+
+client c1 {
+       txreq -url "/"
+       rxresp
+       expect resp.http.X-Backend-Name == "bar"
+} -run
+
+varnish v1 -vcl { 
+       director baz round-robin {
+                { .backend = {
+                       .host = "127.0.0.2";
+                       .port = "9080";
+               } }
+       }
+
+       sub vcl_recv {
+           error 200 "ok";
+       }
+
+       sub vcl_error {
+           set obj.http.X-Backend-Name = req.backend;
+       }
+}
+
+client c1 {
+       txreq -url "/"
+       rxresp
+       expect resp.http.X-Backend-Name == "baz"
+} -run
index e9c8e3db0bbcb32bb62a5fe17656d573cfb20796..121d9bf83a274cc503ce0faf4abba20a3a47fd70 100644 (file)
@@ -171,6 +171,7 @@ void VRT_fini_dir(struct cli *, struct director *);
 char *VRT_IP_string(const struct sess *sp, const struct sockaddr *sa);
 char *VRT_int_string(const struct sess *sp, int);
 char *VRT_double_string(const struct sess *sp, double);
+const char *VRT_backend_string(struct sess *sp);
 
 #define VRT_done(sp, hand)                     \
        do {                                    \
index 005cbb8bfe5063e3a89253f0eb50e49d21b5717b..0d9641f1defaa33932741fca5ec2abfa1c5a2232 100644 (file)
@@ -150,6 +150,9 @@ vcc_StringVal(struct tokenlist *tl)
                case FLOAT:
                        Fb(tl, 0, "VRT_double_string(sp, %s)", vp->rname);
                        break;
+               case BACKEND:
+                       Fb(tl, 0, "VRT_backend_string(sp)");
+                       break;
                default:
                        vsb_printf(tl->sb,
                            "String representation of '%s' not implemented yet.\n",