Commit e3c28439 authored by Geoff Simmons's avatar Geoff Simmons

Add the decoder.create_stats() method.

parent d913397b
......@@ -105,6 +105,13 @@ new xdecoder = brotli.decoder(STRING name, BYTES buffer, BOOL large_win)
XXX ...
.. _vmod_brotli.decoder.create_stats:
VOID xdecoder.create_stats()
----------------------------
XXX ...
.. _vmod_brotli.encoder_version:
STRING encoder_version()
......
......@@ -44,10 +44,12 @@ varnish v1 -vcl+backend {
sub vcl_init {
new mybr = brotli.encoder("mybr");
mybr.create_stats();
new myunbr = brotli.decoder("myunbr");
myunbr.create_stats();
}
sub vcl_backend_response {
set beresp.filters = "mybr unbr";
set beresp.filters = "mybr myunbr";
set beresp.uncacheable = true;
}
}
......@@ -65,25 +67,27 @@ 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.unbr.ops == 10
varnish v1 -expect BROTLI.vcl2.mybr.ops == 10
varnish v1 -expect BROTLI.vcl2.myunbr.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.
# With vcl2 in the cold state, stats for vcl2.* 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 -expect BROTLI.unbr.ops == 10
varnish v1 -cliok "vcl.state vcl2 warm"
# With vcl2 back in the warm state, stats for vcl2.mybr appear again.
# With vcl2 back in the warm state, stats for vcl2.* appear again.
varnish v1 -expect BROTLI.br.ops == 10
varnish v1 -expect BROTLI.unbr.ops == 20
varnish v1 -expect BROTLI.unbr.ops == 10
varnish v1 -expect BROTLI.vcl2.mybr.ops == 10
varnish v1 -expect BROTLI.vcl2.myunbr.ops == 10
varnish v1 -cliok "vcl.state vcl2 cold"
varnish v1 -cliok "vcl.discard vcl2"
......@@ -91,4 +95,4 @@ varnish v1 -cliok "vcl.list"
varnish v1 -vsc BROTLI.*
varnish v1 -expect BROTLI.br.ops == 10
varnish v1 -expect BROTLI.unbr.ops == 20
varnish v1 -expect BROTLI.unbr.ops == 10
......@@ -95,6 +95,7 @@ struct vmod_brotli_encoder {
struct vmod_brotli_decoder {
unsigned magic;
#define VMOD_BROTLI_DECODER_MAGIC 0x263b6d01
char *vcl_name;
struct vfp *vfp;
};
......@@ -709,6 +710,28 @@ coder_init(VRT_CTX, const char *vcl_name, struct vmod_priv *priv,
return (0);
}
static void
create_stats(VRT_CTX, const struct vfp *vfp, const char *vcl_name)
{
struct vfp_priv *vfp_priv;
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(vfp_priv, TRUST_ME(vfp->priv1), VFP_PRIV_MAGIC);
vfp_priv->stats = VSC_brotli_New(NULL, &vfp_priv->vsc_seg, "%s.%s",
VCL_Name(ctx->vcl), vcl_name);
AN(vfp_priv->stats);
memset(vfp_priv->stats, 0, sizeof(*vfp_priv->stats));
}
VCL_VOID
vmod_encoder__init(VRT_CTX, struct vmod_brotli_encoder **encp,
const char *vcl_name, struct vmod_priv *priv,
......@@ -785,23 +808,8 @@ vmod_encoder__fini(struct vmod_brotli_encoder **encp)
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));
create_stats(ctx, enc->vfp, enc->vcl_name);
}
/* Object decoder */
......@@ -837,6 +845,7 @@ vmod_decoder__init(VRT_CTX, struct vmod_brotli_decoder **decp,
settings->which = DEC;
settings->large_win = large_win;
dec->vfp = vfp;
dec->vcl_name = strdup(vcl_name);
*decp = dec;
}
......@@ -853,9 +862,18 @@ vmod_decoder__fini(struct vmod_brotli_decoder **decp)
CHECK_OBJ(*decp, VMOD_BROTLI_DECODER_MAGIC);
dec = *decp;
*decp = NULL;
if (dec->vcl_name != NULL)
free(dec->vcl_name);
FREE_OBJ(dec);
}
VCL_VOID
vmod_decoder_create_stats(VRT_CTX, struct vmod_brotli_decoder *dec)
{
CHECK_OBJ_NOTNULL(dec, VMOD_BROTLI_DECODER_MAGIC);
create_stats(ctx, dec->vfp, dec->vcl_name);
}
/* Version functions */
static VCL_STRING
......
......@@ -75,6 +75,10 @@ $Object decoder(PRIV_VCL, STRING name, BYTES buffer=32768, BOOL large_win=0)
XXX ...
$Method VOID .create_stats()
XXX ...
$Function STRING encoder_version()
Return the version string for the brotli encoder.
......
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