Commit 766d3b42 authored by Geoff Simmons's avatar Geoff Simmons

Add encrypter.create_stats().

parent 935128b7
...@@ -13,7 +13,9 @@ server s1 -repeat 3 { ...@@ -13,7 +13,9 @@ server s1 -repeat 3 {
txresp -body {I am the walrus} txresp -body {I am the walrus}
} -start } -start
varnish v1 -arg "-p vsl_mask=+VfpAcct" -vcl+backend { # Debug param vclrel causes VCLs to be released without delay, tests
# object finalization and the DISCARD event.
varnish v1 -arg "-p vsl_mask=+VfpAcct -p debug=+vclrel" -vcl+backend {
import ${vmod_ece}; import ${vmod_ece};
import blob; import blob;
...@@ -21,6 +23,7 @@ varnish v1 -arg "-p vsl_mask=+VfpAcct" -vcl+backend { ...@@ -21,6 +23,7 @@ varnish v1 -arg "-p vsl_mask=+VfpAcct" -vcl+backend {
# With all params set to defaults, the encrypter is # With all params set to defaults, the encrypter is
# just like the default ece_encrypt VFP. # just like the default ece_encrypt VFP.
new default_dup = ece.encrypter("default_dup"); new default_dup = ece.encrypter("default_dup");
default_dup.create_stats();
ece.set_key("", blob.decode(BASE64URLNOPAD, ece.set_key("", blob.decode(BASE64URLNOPAD,
encoded="yqdlZ-tYemfogSmv7Ws5PQ")); encoded="yqdlZ-tYemfogSmv7Ws5PQ"));
} }
...@@ -42,6 +45,10 @@ client c1 { ...@@ -42,6 +45,10 @@ client c1 {
expect resp.bodylen == 53 expect resp.bodylen == 53
} -run } -run
varnish v1 -expect ECE.vfp.vcl1.default_dup.ops == 1
varnish v1 -expect ECE.vfp.vcl1.default_dup.in == 15
varnish v1 -expect ECE.vfp.vcl1.default_dup.out == 53
# The only way is to verify the result is to manually inspect the log file. # The only way is to verify the result is to manually inspect the log file.
# See the comment in encrypt.vtc. The same log excerpt shown there should # See the comment in encrypt.vtc. The same log excerpt shown there should
# appear for this test as well. # appear for this test as well.
...@@ -58,6 +65,7 @@ varnish v1 -vcl+backend { ...@@ -58,6 +65,7 @@ varnish v1 -vcl+backend {
sub vcl_init { sub vcl_init {
# Custom encrypter that uses another header to set the key. # Custom encrypter that uses another header to set the key.
new hdr = ece.encrypter("hdr", key_hdr="X-Set-Key-ID"); new hdr = ece.encrypter("hdr", key_hdr="X-Set-Key-ID");
hdr.create_stats();
} }
sub vcl_backend_response { sub vcl_backend_response {
...@@ -84,6 +92,10 @@ client c1 { ...@@ -84,6 +92,10 @@ client c1 {
logexpect l1 -wait logexpect l1 -wait
varnish v1 -expect ECE.vfp.vcl2.hdr.ops == 1
varnish v1 -expect ECE.vfp.vcl2.hdr.in == 15
varnish v1 -expect ECE.vfp.vcl2.hdr.out == 53
# Fetch fails if the wrong key header is used. # Fetch fails if the wrong key header is used.
logexpect l1 -v v1 -d 0 -g vxid -q "FetchError" { logexpect l1 -v v1 -d 0 -g vxid -q "FetchError" {
expect 0 * Begin bereq expect 0 * Begin bereq
...@@ -100,6 +112,10 @@ client c1 { ...@@ -100,6 +112,10 @@ client c1 {
logexpect l1 -wait logexpect l1 -wait
# Tests object finalization and DISCARD event. varnish v1 -expect ECE.vfp.vcl2.hdr.ops == 2
varnish v1 -expect ECE.vfp.vcl2.hdr.in == 15
varnish v1 -expect ECE.vfp.vcl2.hdr.out == 53
# Tests the DISCARD event.
varnish v1 -cli "vcl.discard vcl1" varnish v1 -cli "vcl.discard vcl1"
varnish v1 -cli "vcl.list" varnish v1 -cli "vcl.list"
...@@ -44,7 +44,9 @@ Enim per accumsan, augue id maecenas bibendum ullamcorper in fermentum, platea f ...@@ -44,7 +44,9 @@ Enim per accumsan, augue id maecenas bibendum ullamcorper in fermentum, platea f
chunkedlen 0 chunkedlen 0
} -start } -start
varnish v1 -arg "-p vsl_mask=+VfpAcct" -vcl+backend { # Debug param vclrel causes VCLs to be released without delay, tests
# object finalization and the DISCARD event.
varnish v1 -arg "-p vsl_mask=+VfpAcct -p debug=+vclrel" -vcl+backend {
import ${vmod_ece}; import ${vmod_ece};
import blob; import blob;
...@@ -165,6 +167,7 @@ varnish v1 -vcl+backend { ...@@ -165,6 +167,7 @@ varnish v1 -vcl+backend {
sub vcl_init { sub vcl_init {
# Encrypter uses 128 byte record size. # Encrypter uses 128 byte record size.
new rs128 = ece.encrypter("rs128", rs=128B); new rs128 = ece.encrypter("rs128", rs=128B);
rs128.create_stats();
# Decrypter uses 8k chunk size. # Decrypter uses 8k chunk size.
new chunk8k = ece.decrypter("chunk8k", chunksz=8k); new chunk8k = ece.decrypter("chunk8k", chunksz=8k);
} }
...@@ -223,11 +226,16 @@ client c1 -run ...@@ -223,11 +226,16 @@ client c1 -run
logexpect l1 -wait logexpect l1 -wait
varnish v1 -expect ECE.vfp.vcl2.rs128.ops == 6
varnish v1 -expect ECE.vfp.vcl2.rs128.in == 199975
varnish v1 -expect ECE.vfp.vcl2.rs128.out > 199975
varnish v1 -vcl+backend { varnish v1 -vcl+backend {
import ${vmod_ece}; import ${vmod_ece};
sub vcl_init { sub vcl_init {
new rs815 = ece.encrypter("rs815", rs=815B); new rs815 = ece.encrypter("rs815", rs=815B);
rs815.create_stats();
new chunk4711 = ece.decrypter("chunk4711", chunksz=4711B); new chunk4711 = ece.decrypter("chunk4711", chunksz=4711B);
} }
...@@ -284,3 +292,11 @@ logexpect l1 -v v1 -d 0 -g vxid -q "VfpAcct" { ...@@ -284,3 +292,11 @@ logexpect l1 -v v1 -d 0 -g vxid -q "VfpAcct" {
client c1 -run client c1 -run
logexpect l1 -wait logexpect l1 -wait
varnish v1 -expect ECE.vfp.vcl3.rs815.ops == 6
varnish v1 -expect ECE.vfp.vcl3.rs815.in == 199975
varnish v1 -expect ECE.vfp.vcl3.rs815.out > 199975
varnish v1 -cli "vcl.discard vcl1"
varnish v1 -cli "vcl.discard vcl2"
varnish v1 -cli "vcl.list"
...@@ -256,6 +256,28 @@ crypter_init(VRT_CTX, const char *vcl_name, struct vmod_priv *priv, ...@@ -256,6 +256,28 @@ crypter_init(VRT_CTX, const char *vcl_name, struct vmod_priv *priv,
return (0); return (0);
} }
static void
create_stats(VRT_CTX, const struct vfp *vfp, const char *vcl_name)
{
struct vfp_cfg *cfg;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
AN(vcl_name);
if ((ctx->method & VCL_MET_INIT) == 0) {
VFAIL(ctx, "%s.create_stats() may only be called in vcl_init",
vcl_name);
return;
}
AN(vfp);
CAST_OBJ_NOTNULL(cfg, TRUST_ME(vfp->priv1), VFP_CFG_MAGIC);
cfg->stats = VSC_ece_New(NULL, &cfg->vsc_seg, "vfp.%s.%s",
VCL_Name(ctx->vcl), vcl_name);
AN(cfg->stats);
memset(cfg->stats, 0, sizeof(*cfg->stats));
}
/* Object encrypter */ /* Object encrypter */
VCL_VOID VCL_VOID
...@@ -370,6 +392,13 @@ vmod_encrypter__fini(struct VPFX(ece_encrypter) **encp) ...@@ -370,6 +392,13 @@ vmod_encrypter__fini(struct VPFX(ece_encrypter) **encp)
FREE_OBJ(enc); FREE_OBJ(enc);
} }
VCL_VOID
vmod_encrypter_create_stats(VRT_CTX, struct VPFX(ece_encrypter) * enc)
{
CHECK_OBJ_NOTNULL(enc, ECE_ENCRYPTER_MAGIC);
create_stats(ctx, enc->vfp, enc->vcl_name);
}
/* Object decrypter */ /* Object decrypter */
VCL_VOID VCL_VOID
......
...@@ -63,6 +63,15 @@ Create an encryption filter named ``name`` with custom parameters. ...@@ -63,6 +63,15 @@ Create an encryption filter named ``name`` with custom parameters.
XXX ... XXX ...
$Method VOID .create_stats()
Create statistics, observable with a tool like ``varnishstat(1)``, for
the custom encryption filter. These are the same as the counters
created for the standard ``"ece_encrypt"`` filter. See `STATISTICS`_
below for details.
XXX ...
$Object decrypter(PRIV_VCL, STRING name, BYTES chunksz=16384, $Object decrypter(PRIV_VCL, STRING name, BYTES chunksz=16384,
BYTES max_rs=1048576) BYTES max_rs=1048576)
......
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