Commit d913397b authored by Geoff Simmons's avatar Geoff Simmons

Add the encoder.create_stats() method.

parent ddeb8fda
......@@ -7,7 +7,7 @@
.. role:: ref(emphasis)
===========
vmod_brotli
VMOD brotli
===========
--------------------------------------------------
......@@ -40,10 +40,6 @@ SYNOPSIS
}
}
# Create statistics for the built-in filters.
VOID brotli.create_br_stats()
VOID brotli.create_unbr_stats()
# Create a brotli compression filter with custom parameters.
new <obj> = brotli.encoder(STRING name, BYTES buffer, INT quality,
INT lgwin)
......@@ -87,6 +83,13 @@ new xencoder = brotli.encoder(STRING name, BYTES bufffer, INT quality, BOOL larg
XXX ...
.. _vmod_brotli.encoder.create_stats:
VOID xencoder.create_stats()
----------------------------
XXX ...
.. _vmod_brotli.decoder:
new xdecoder = brotli.decoder(STRING name, BYTES buffer, BOOL large_win)
......
......@@ -3,14 +3,14 @@
varnishtest "statistics"
server s1 {
loop 100 {
loop 10 {
rxreq
txresp -body {Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.}
}
} -start
client c1 {
loop 100 {
loop 10 {
txreq
rxresp
expect resp.status == 200
......@@ -19,7 +19,10 @@ client c1 {
}
}
varnish v1 -vcl+backend {
# Debug param vclrel causes VCLs to be released without delay. This
# makes it possible to check the effects of temperature changes (stats
# are hidden and revealed as VCLs go cold and warm).
varnish v1 -arg "-p debug=+vclrel" -vcl+backend {
import ${vmod_brotli};
sub vcl_backend_response {
......@@ -32,5 +35,60 @@ client c1 -run
varnish v1 -vsc BROTLI.*
varnish v1 -expect BROTLI.br.ops == 100
varnish v1 -expect BROTLI.unbr.ops == 100
varnish v1 -expect BROTLI.br.ops == 10
varnish v1 -expect BROTLI.unbr.ops == 10
varnish v1 -vcl+backend {
import ${vmod_brotli};
sub vcl_init {
new mybr = brotli.encoder("mybr");
mybr.create_stats();
}
sub vcl_backend_response {
set beresp.filters = "mybr unbr";
set beresp.uncacheable = true;
}
}
varnish v1 -cliok "vcl.discard vcl1"
varnish v1 -cliok "vcl.list"
varnish v1 -vsc BROTLI.*
varnish v1 -expect BROTLI.br.ops == 10
varnish v1 -expect BROTLI.unbr.ops == 10
server s1 -wait
server s1 -start
client c1 -run
varnish v1 -vsc BROTLI.*
varnish v1 -expect BROTLI.br.ops == 10
varnish v1 -expect BROTLI.unbr.ops == 20
varnish v1 -expect BROTLI.vcl2.mybr.ops == 10
varnish v1 -vcl+backend {}
varnish v1 -cliok "vcl.state vcl2 cold"
# With vcl2 in the cold state, stats for vcl2.mybr do not appear.
# This has to be checked manually in the log.
varnish v1 -vsc BROTLI.vcl2.*
varnish v1 -expect BROTLI.br.ops == 10
varnish v1 -expect BROTLI.unbr.ops == 20
varnish v1 -cliok "vcl.state vcl2 warm"
# With vcl2 back in the warm state, stats for vcl2.mybr appear again.
varnish v1 -expect BROTLI.br.ops == 10
varnish v1 -expect BROTLI.unbr.ops == 20
varnish v1 -expect BROTLI.vcl2.mybr.ops == 10
varnish v1 -cliok "vcl.state vcl2 cold"
varnish v1 -cliok "vcl.discard vcl2"
varnish v1 -cliok "vcl.list"
varnish v1 -vsc BROTLI.*
varnish v1 -expect BROTLI.br.ops == 10
varnish v1 -expect BROTLI.unbr.ops == 20
......@@ -40,6 +40,7 @@
#include "cache/cache.h"
#include "cache/cache_filter.h"
#include "vcl.h"
#include "vcc_if.h"
#include "VSC_brotli.h"
......@@ -87,6 +88,7 @@ struct vbr_settings {
struct vmod_brotli_encoder {
unsigned magic;
#define VMOD_BROTLI_ENCODER_MAGIC 0x1490a42a
char *vcl_name;
struct vfp *vfp;
};
......@@ -571,9 +573,15 @@ vmod_event(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e e)
CAST_OBJ(vfp_priv,
TRUST_ME(vfpe->vfp->priv1),
VFP_PRIV_MAGIC);
CHECK_OBJ_NOTNULL(vfp_priv->settings,
if (vfp_priv->settings != NULL) {
CHECK_OBJ(vfp_priv->settings,
VBR_SETTINGS_MAGIC);
FREE_OBJ(vfp_priv->settings);
FREE_OBJ(vfp_priv->settings);
}
if (vfp_priv->vsc_seg != NULL)
VSC_brotli_Destroy(
&vfp_priv->vsc_seg);
/* XXX free(vfp_priv->stats) ? */
}
VRT_RemoveVFP(ctx, vfpe->vfp);
free(vfpe->vfp);
......@@ -584,7 +592,26 @@ vmod_event(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e e)
free(vfph);
return (0);
case VCL_EVENT_WARM:
VSLIST_FOREACH(vfpe, vfph, list) {
CHECK_OBJ_NOTNULL(vfpe, CUSTOM_VFP_MAGIC);
if (vfpe->vfp != NULL && vfpe->vfp->priv1 != NULL) {
CAST_OBJ(vfp_priv, TRUST_ME(vfpe->vfp->priv1),
VFP_PRIV_MAGIC);
if (vfp_priv->vsc_seg != NULL)
VRT_VSC_Reveal(vfp_priv->vsc_seg);
}
}
return (0);
case VCL_EVENT_COLD:
VSLIST_FOREACH(vfpe, vfph, list) {
CHECK_OBJ_NOTNULL(vfpe, CUSTOM_VFP_MAGIC);
if (vfpe->vfp != NULL && vfpe->vfp->priv1 != NULL) {
CAST_OBJ(vfp_priv, TRUST_ME(vfpe->vfp->priv1),
VFP_PRIV_MAGIC);
if (vfp_priv->vsc_seg != NULL)
VRT_VSC_Hide(vfp_priv->vsc_seg);
}
}
return (0);
default:
WRONG("illegal event enum");
......@@ -731,6 +758,7 @@ vmod_encoder__init(VRT_CTX, struct vmod_brotli_encoder **encp,
settings->large_win = large_win;
settings->lgwin = lgwin;
enc->vfp = vfp;
enc->vcl_name = strdup(vcl_name);
*encp = enc;
}
......@@ -749,9 +777,33 @@ vmod_encoder__fini(struct vmod_brotli_encoder **encp)
CHECK_OBJ(*encp, VMOD_BROTLI_ENCODER_MAGIC);
enc = *encp;
*encp = NULL;
if (enc->vcl_name != NULL)
free(enc->vcl_name);
FREE_OBJ(enc);
}
VCL_VOID
vmod_encoder_create_stats(VRT_CTX, struct vmod_brotli_encoder *enc)
{
struct vfp_priv *vfp_priv;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(enc, VMOD_BROTLI_ENCODER_MAGIC);
if ((ctx->method & VCL_MET_INIT) == 0) {
VFAIL(ctx, "%s.create_stats() may only be called in vcl_init",
enc->vcl_name);
return;
}
AN(enc->vfp);
CAST_OBJ_NOTNULL(vfp_priv, TRUST_ME(enc->vfp->priv1), VFP_PRIV_MAGIC);
vfp_priv->stats = VSC_brotli_New(NULL, &vfp_priv->vsc_seg, "%s.%s",
VCL_Name(ctx->vcl), enc->vcl_name);
AN(vfp_priv->stats);
memset(vfp_priv->stats, 0, sizeof(*vfp_priv->stats));
}
/* Object decoder */
VCL_VOID
......
......@@ -36,10 +36,6 @@ SYNOPSIS
}
}
# Create statistics for the built-in filters.
VOID brotli.create_br_stats()
VOID brotli.create_unbr_stats()
# Create a brotli compression filter with custom parameters.
new <obj> = brotli.encoder(STRING name, BYTES buffer, INT quality,
INT lgwin)
......@@ -71,6 +67,10 @@ $Object encoder(PRIV_VCL, STRING name, BYTES bufffer=32768, INT quality=11,
XXX ...
$Method VOID .create_stats()
XXX ...
$Object decoder(PRIV_VCL, STRING name, BYTES buffer=32768, BOOL large_win=0)
XXX ...
......
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