Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ Makefile.in

/src/vcc_if.c
/src/vcc_if.h
/src/vmod_statsd.man.rst
/src/vmod_statsd.rst
/vmod_statsd.3
14 changes: 11 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
ACLOCAL_AMFLAGS = -I m4
ACLOCAL_AMFLAGS = -I m4 -I ${LIBVARNISHAPI_DATAROOTDIR}/aclocal

SUBDIRS = src

EXTRA_DIST = README.rst
DISTCHECK_CONFIGURE_FLAGS = \
VMOD_DIR='$${libdir}/varnish/vmods'

EXTRA_DIST = README.rst LICENSE vmod-statsd.spec debian

doc_DATA = README.rst LICENSE

dist_man_MANS = vmod_statsd.3
MAINTAINERCLEANFILES = $(dist_man_MANS)

vmod_statsd.3: README.rst

%.1 %.2 %.3 %.4 %.5 %.6 %.7 %.8 %.9:
if HAVE_RST2MAN
${RST2MAN} README.rst $@
${RST2MAN} $< $@
else
@echo "========================================"
@echo "You need rst2man installed to make dist"
@echo "========================================"
@false
endif

10 changes: 4 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ SYNOPSIS
DESCRIPTION
===========

Varnish Module (vmod) for sending statistics to Statsd.
Varnish 4.x Module (vmod) for sending statistics to Statsd.

See https://github.com/jib/libvmod-statsd/tree/master for Varnish 3.x version.

See https://github.com/etsy/statsd for documentation on Statsd.

Expand Down Expand Up @@ -190,11 +192,7 @@ Usage::
./autogen.sh

# Execute configure script
./configure VARNISHSRC=DIR [VMODDIR=DIR]

`VARNISHSRC` is the directory of the Varnish source tree for which to
compile your vmod. Both the `VARNISHSRC` and `VARNISHSRC/include`
will be added to the include search paths for your module.
./configure

Optionally you can also set the vmod install directory by adding
`VMODDIR=DIR` (defaults to the pkg-config discovered directory from your
Expand Down
13 changes: 11 additions & 2 deletions autogen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,18 @@ else
esac
fi

# check for varnishapi.m4 in custom paths
dataroot=$(pkg-config --variable=datarootdir varnishapi 2>/dev/null)
if [ -z "$dataroot" ] ; then
cat >&2 <<'EOF'
Package varnishapi was not found in the pkg-config search path.
Perhaps you should add the directory containing `varnishapi.pc'
to the PKG_CONFIG_PATH environment variable
EOF
exit 1
fi
set -ex

aclocal -I m4
aclocal -I m4 -I ${dataroot}/aclocal
$LIBTOOLIZE --copy --force
autoheader
automake --add-missing --copy --foreign
Expand Down
63 changes: 32 additions & 31 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
AC_PREREQ(2.59)
AC_COPYRIGHT([Copyright (c) 2011 Varnish Software AS])
AC_COPYRIGHT([Copyright (c) 2011-2015 Varnish Software AS])
AC_INIT([libvmod-statsd], [trunk])
AC_CONFIG_MACRO_DIR([m4])
m4_ifndef([VARNISH_VMOD_INCLUDES], AC_MSG_ERROR([Need varnish.m4 -- see README.rst]))
AC_CONFIG_SRCDIR(src/vmod_statsd.vcc)
AM_CONFIG_HEADER(config.h)

Expand Down Expand Up @@ -29,43 +30,43 @@ if test "x$RST2MAN" = "xno"; then
fi
AM_CONDITIONAL(HAVE_RST2MAN, [test "x$RST2MAN" != "xno"])

# Check for pkg-config
PKG_PROG_PKG_CONFIG

# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([sys/stdlib.h])

# Check for python
AC_CHECK_PROGS(PYTHON, [python3 python3.1 python3.2 python2.7 python2.6 python2.5 python2 python], [AC_MSG_ERROR([Python is needed to build this vmod, please install python.])])
# backwards compat with older pkg-config
# - pull in AC_DEFUN from pkg.m4
m4_ifndef([PKG_CHECK_VAR], [
# PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE,
# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
# -------------------------------------------
# Retrieves the value of the pkg-config variable for the given module.
AC_DEFUN([PKG_CHECK_VAR],
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl

# Varnish source tree
AC_ARG_VAR([VARNISHSRC], [path to Varnish source tree (mandatory)])
if test "x$VARNISHSRC" = x; then
AC_MSG_ERROR([No Varnish source tree specified])
fi
VARNISHSRC=`cd $VARNISHSRC && pwd`
AC_CHECK_FILE([$VARNISHSRC/include/varnishapi.h],
[],
[AC_MSG_FAILURE(["$VARNISHSRC" is not a Varnish source directory])]
)
AM_CONDITIONAL(HAVE_VARNISHSRC, [test -n $VARNISHSRC])
_PKG_CONFIG([$1], [variable="][$3]["], [$2])
AS_VAR_COPY([$1], [pkg_cv_][$1])

AS_VAR_IF([$1], [""], [$5], [$4])dnl
])# PKG_CHECK_VAR
])

# Check that varnishtest is built in the varnish source directory
AC_CHECK_FILE([$VARNISHSRC/bin/varnishtest/varnishtest],
[],
[AC_MSG_FAILURE([Can't find "$VARNISHSRC/bin/varnishtest/varnishtest". Please build your varnish source directory])]
)
PKG_CHECK_MODULES([libvarnishapi], [varnishapi])
PKG_CHECK_VAR([LIBVARNISHAPI_DATAROOTDIR], [varnishapi], [datarootdir])
PKG_CHECK_VAR([LIBVARNISHAPI_BINDIR], [varnishapi], [bindir])
PKG_CHECK_VAR([LIBVARNISHAPI_SBINDIR], [varnishapi], [sbindir])
AC_SUBST([LIBVARNISHAPI_DATAROOTDIR])

# vmod installation dir
AC_ARG_VAR([VMODDIR], [vmod installation directory @<:@LIBDIR/varnish/vmods@:>@])
if test "x$VMODDIR" = x; then
VMODDIR=`pkg-config --variable=vmoddir varnishapi`
if test "x$VMODDIR" = x; then
AC_MSG_FAILURE([Can't determine vmod installation directory])
fi
fi
AM_CONDITIONAL(HAVE_VMODDIR, [test -n $VMODDIR])
# Varnish include files tree
VARNISH_VMOD_INCLUDES
VARNISH_VMOD_DIR
VARNISH_VMODTOOL

AC_PATH_PROG([VARNISHTEST], [varnishtest], [],
[$LIBVARNISHAPI_BINDIR:$LIBVARNISHAPI_SBINDIR:$PATH])
AC_PATH_PROG([VARNISHD], [varnishd], [],
[$LIBVARNISHAPI_SBINDIR:$LIBVARNISHAPI_BINDIR:$PATH])

AC_CONFIG_FILES([
Makefile
Expand Down
36 changes: 11 additions & 25 deletions src/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
# if VARNISHSRC is defined on the command-line, use that. Otherwise, build
# this the same as the modules that come with varnish (i.e. we're building
# within the varnish src dir itself, and $(top_srcdir) is the varnish source).
#
if HAVE_VARNISHSRC
SRC = $(VARNISHSRC)
DIR_PREFIX = /
else
SRC = $(top_srcdir)
DIR_PREFIX = lib/libvmod-statsd/
endif

INCLUDES = -I$(SRC)/include -I$(SRC)

if HAVE_VMODDIR
vmoddir = $(VMODDIR)
else
vmoddir = $(pkglibdir)/vmods
endif
AM_CPPFLAGS = @VMOD_INCLUDES@

vmoddir = @VMOD_DIR@
vmod_LTLIBRARIES = libvmod_statsd.la

libvmod_statsd_la_LDFLAGS = -module -export-dynamic -avoid-version
Expand All @@ -27,19 +10,22 @@ libvmod_statsd_la_SOURCES = \
vcc_if.h \
vmod_statsd.c

vcc_if.c vcc_if.h: $(SRC)/lib/libvmod_std/vmod.py $(top_srcdir)/$(DIR_PREFIX)src/vmod_statsd.vcc
@PYTHON@ $(SRC)/lib/libvmod_std/vmod.py $(top_srcdir)/$(DIR_PREFIX)src/vmod_statsd.vcc
vcc_if.c vcc_if.h: @VMODTOOL@ $(top_srcdir)/$(DIR_PREFIX)src/vmod_statsd.vcc
@VMODTOOL@ $(top_srcdir)/$(DIR_PREFIX)src/vmod_statsd.vcc

VMOD_TESTS = tests/*.vtc
VMOD_TESTS = $(top_srcdir)/src/tests/*.vtc
.PHONY: $(VMOD_TESTS)

tests/*.vtc:
$(SRC)/bin/varnishtest/varnishtest -Dvarnishd=$(SRC)/bin/varnishd/varnishd -Dvmod_topbuild=$(abs_top_builddir) $@
$(top_srcdir)/src/tests/*.vtc:
@VARNISHTEST@ -Dvarnishd=@VARNISHD@ -Dvmod_topbuild=$(abs_top_builddir) $@

check: $(VMOD_TESTS)

EXTRA_DIST = \
vmod_statsd.vcc \
$(VMOD_TESTS)

CLEANFILES = $(builddir)/vcc_if.c $(builddir)/vcc_if.h
CLEANFILES = $(builddir)/vcc_if.c $(builddir)/vcc_if.h \
$(builddir)/vmod_statsd.man.rst \
$(builddir)/vmod_statsd.rst \
$(builddir)/../vmod_statsd.3
46 changes: 46 additions & 0 deletions src/tests/test02.vtc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
varnishtest "Test sending stats"

server s1 {
rxreq
txresp
} -start

# XXX I don't know how to test reception of UDP packets from varnish,
# so for now, these tests just make sure that the process doesn't crash,
# hang, or do anything else bad

varnish v1 -vcl+backend {
import statsd from "${vmod_topbuild}/src/.libs/libvmod_statsd.so";

sub vcl_init {
statsd.server("localhost", "1"); # nothing listens on UDP port 1 right?
statsd.prefix("prefix");
statsd.suffix("suffix");
}

sub vcl_deliver {
statsd.incr( "incr" );
statsd.gauge( "gauge", 1234567890 );
statsd.timing( "timing", 1234567890 );
statsd.counter( "counter", 1234567890 );

# So we know we got to at least here.
set resp.http.hello = "Hello, World";
}

} -start

logexpect l1 -v v1 {
expect * * VCL_Log "vmod-statsd: Sent 20 of 20 bytes "
expect * * VCL_Log "Could not write stat 'prefixgaugesuffix:1234567890|g'"
} -start

client c1 {
txreq -url "/"
rxresp
expect resp.http.hello == "Hello, World"
}

client c1 -run

logexpect l1 -wait
Loading