Commit ddeb8fda authored by Geoff Simmons's avatar Geoff Simmons

Begin adding stats, starting with the ops counter for br and unbr.

parent e5657d62
......@@ -32,6 +32,8 @@ Makefile.in
/src/vcc_if.c
/src/vcc_if.h
/src/vmod_*rst
/src/VSC_brotli.h
/src/VSC_brotli.c
/src/tests/*.log
/src/tests/*.trs
......
......@@ -43,7 +43,7 @@ PKG_CHECK_MODULES([BROTLICOMMON], [libbrotlicommon])
VARNISH_PREREQ([trunk])
VARNISH_VMODS([brotli])
#VARNISH_COUNTERS([brotli])
VARNISH_COUNTERS([brotli])
VMOD_TESTS="$(cd $srcdir/src && echo tests/*.vtc)"
AC_SUBST(VMOD_TESTS)
......
......@@ -11,10 +11,14 @@ libvmod_brotli_la_SOURCES = \
nodist_libvmod_brotli_la_SOURCES = \
vcc_if.c \
vcc_if.h
vcc_if.h \
VSC_brotli.c \
VSC_brotli.h
dist_man_MANS = vfp_brotli.3
@BUILD_VSC_BROTLI@
vfp_brotli.lo: $(nodist_libvmod_brotli_la_SOURCES)
libvmod_brotli_la_LIBADD = @BROTLIENC_LIBS@ @BROTLIDEC_LIBS@ @BROTLICOMMON_LIBS@
......@@ -42,6 +46,7 @@ TESTS = @VMOD_TESTS@
EXTRA_DIST = \
vfp_brotli.vcc \
brotli.vsc \
$(VMOD_TESTS)
CLEANFILES = \
......@@ -49,4 +54,6 @@ CLEANFILES = \
$(builddir)/vcc_if.h \
$(builddir)/vmod_brotli.rst \
$(builddir)/vmod_brotli.man.rst \
$(builddir)/vfp_brotli.3
$(builddir)/vfp_brotli.3 \
$(builddir)/VSC_brotli.c \
$(builddir)/VSC_brotli.h
..
This is *NOT* a RST file but the syntax has been chosen so
that it may become an RST file at some later date.
.. varnish_vsc_begin:: brotli
:oneliner: VFP brotli de-/compression stats
:order: 90
.. varnish_vsc:: ops
:type: counter
:oneliner: Operations
Total number of de-/compression operations
.. varnish_vsc_end:: brotli
# looks like -*- vcl -*-
varnishtest "statistics"
server s1 {
loop 100 {
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 {
txreq
rxresp
expect resp.status == 200
expect resp.http.Content-Encoding == <undef>
expect resp.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.}
}
}
varnish v1 -vcl+backend {
import ${vmod_brotli};
sub vcl_backend_response {
set beresp.filters = "br unbr";
set beresp.uncacheable = true;
}
} -start
client c1 -run
varnish v1 -vsc BROTLI.*
varnish v1 -expect BROTLI.br.ops == 100
varnish v1 -expect BROTLI.unbr.ops == 100
......@@ -42,6 +42,7 @@
#include "cache/cache_filter.h"
#include "vcc_if.h"
#include "VSC_brotli.h"
#define VFAIL(ctx, fmt, ...) \
VRT_fail((ctx), "vfp brotli failure: " fmt, __VA_ARGS__)
......@@ -104,6 +105,14 @@ struct custom_vfp_entry {
VSLIST_HEAD(custom_vfp_head, custom_vfp_entry);
struct vfp_priv {
unsigned magic;
#define VFP_PRIV_MAGIC 0xc79b73f7
struct vbr_settings *settings;
struct VSC_brotli *stats;
struct vsc_seg *vsc_seg;
};
static struct vbr *
newVBR(enum vbr_which which)
{
......@@ -286,12 +295,15 @@ static enum vfp_status v_matchproto_(vfp_init_f)
vfp_br_init(struct vfp_ctx *ctx, struct vfp_entry *ent)
{
struct vbr *vbr;
const struct vfp_priv *priv;
const struct vbr_settings *settings;
CHECK_OBJ_NOTNULL(ctx, VFP_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ent, VFP_ENTRY_MAGIC);
AN(ent->vfp);
CAST_OBJ_NOTNULL(settings, ent->vfp->priv1, VBR_SETTINGS_MAGIC);
CAST_OBJ_NOTNULL(priv, ent->vfp->priv1, VFP_PRIV_MAGIC);
CHECK_OBJ_NOTNULL(priv->settings, VBR_SETTINGS_MAGIC);
settings = priv->settings;
/*
* Ignore partial responses to range requests (as Varnish does for
......@@ -300,6 +312,9 @@ vfp_br_init(struct vfp_ctx *ctx, struct vfp_entry *ent)
if (http_GetStatus(ctx->resp) == 206)
return (VFP_NULL);
if (priv->stats != NULL)
priv->stats->ops++;
if (settings->which == ENC) {
if (http_GetHdr(ctx->resp, H_Content_Encoding, NULL))
return (VFP_NULL);
......@@ -450,18 +465,36 @@ vfp_unbr_pull(struct vfp_ctx *ctx, struct vfp_entry *ent, void *ptr,
return (VFP_END);
}
static const struct vbr_settings default_encoder = {
static struct vbr_settings default_encoder_settings = {
.magic = VBR_SETTINGS_MAGIC,
.bufsz = DEFAULT_BUFSZ,
.quality = BROTLI_DEFAULT_QUALITY,
.large_win = 0,
.lgwin = BROTLI_DEFAULT_WINDOW,
.which = ENC,
};
static const struct vbr_settings default_decoder = {
static struct vbr_settings default_decoder_settings = {
.magic = VBR_SETTINGS_MAGIC,
.bufsz = DEFAULT_BUFSZ,
.large_win = 0,
.which = DEC,
};
static struct vfp_priv default_encoder = {
.magic = VFP_PRIV_MAGIC,
.settings = &default_encoder_settings,
.stats = NULL,
.vsc_seg = NULL,
};
static struct vfp_priv default_decoder = {
.magic = VFP_PRIV_MAGIC,
.settings = &default_decoder_settings,
.stats = NULL,
.vsc_seg = NULL,
};
static const struct vfp vfp_br = {
.name = "br",
.init = vfp_br_init,
......@@ -502,7 +535,7 @@ vmod_event(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e e)
{
struct custom_vfp_head *vfph;
struct custom_vfp_entry *vfpe;
struct vbr_settings *settings;
struct vfp_priv *vfp_priv;
ASSERT_CLI();
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
......@@ -514,6 +547,18 @@ vmod_event(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e e)
case VCL_EVENT_LOAD:
VRT_AddVFP(ctx, &vfp_br);
VRT_AddVFP(ctx, &vfp_unbr);
CAST_OBJ_NOTNULL(vfp_priv, TRUST_ME(vfp_br.priv1),
VFP_PRIV_MAGIC);
if (vfp_priv->stats == NULL)
vfp_priv->stats = VSC_brotli_New(NULL,
&vfp_priv->vsc_seg,
"br");
CAST_OBJ_NOTNULL(vfp_priv, TRUST_ME(vfp_unbr.priv1),
VFP_PRIV_MAGIC);
if (vfp_priv->stats == NULL)
vfp_priv->stats = VSC_brotli_New(NULL,
&vfp_priv->vsc_seg,
"unbr");
return (0);
case VCL_EVENT_DISCARD:
VRT_RemoveVFP(ctx, &vfp_br);
......@@ -523,10 +568,12 @@ vmod_event(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e e)
CHECK_OBJ_NOTNULL(vfpe, CUSTOM_VFP_MAGIC);
if (vfpe->vfp != NULL) {
if (vfpe->vfp->priv1 != NULL) {
CAST_OBJ(settings,
CAST_OBJ(vfp_priv,
TRUST_ME(vfpe->vfp->priv1),
VBR_SETTINGS_MAGIC);
FREE_OBJ(settings);
VFP_PRIV_MAGIC);
CHECK_OBJ_NOTNULL(vfp_priv->settings,
VBR_SETTINGS_MAGIC);
FREE_OBJ(vfp_priv->settings);
}
VRT_RemoveVFP(ctx, vfpe->vfp);
free(vfpe->vfp);
......@@ -553,6 +600,7 @@ coder_init(VRT_CTX, const char *vcl_name, struct vmod_priv *priv,
struct vbr_settings **settingsp)
{
struct vfp *vfp;
struct vfp_priv *vfp_priv;
struct vbr_settings *settings;
struct custom_vfp_head *vfph;
struct custom_vfp_entry *vfpe;
......@@ -603,6 +651,15 @@ coder_init(VRT_CTX, const char *vcl_name, struct vmod_priv *priv,
}
*settingsp = settings;
errno = 0;
ALLOC_OBJ(vfp_priv, VFP_PRIV_MAGIC);
if (vfp_priv == NULL) {
VFAIL(ctx, "new %s: cannot allocate space for VFP priv obj: %s",
vcl_name, strerror(errno));
return (-1);
}
*settingsp = settings;
errno = 0;
ALLOC_OBJ(vfpe, CUSTOM_VFP_MAGIC);
if (vfpe == NULL) {
......@@ -612,11 +669,12 @@ coder_init(VRT_CTX, const char *vcl_name, struct vmod_priv *priv,
}
settings->bufsz = bufsz;
vfp_priv->settings = settings;
vfp->name = strdup(filter_name);
vfp->init = vfp_br_init;
vfp->fini = vfp_br_fini;
vfp->priv1 = settings;
vfp->priv1 = vfp_priv;
vfph = init_priv_vcl(priv);
vfpe->vfp = vfp;
......
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