Commit e9a3c06a authored by Geoff Simmons's avatar Geoff Simmons

trackrdrd now parses tracking data and sends debug messages to syslog

parent 9714c3c4
......@@ -3,12 +3,13 @@ INCLUDES = -I$(VARNISHSRC)/include -I$(VARNISHSRC)
bin_PROGRAMS = trackrdrd
trackrdrd_SOURCES = \
trackrdrd.c
$(VARNISHSRC)/lib/libvarnish/assert.c \
$(VARNISHSRC)/lib/libvarnish/flopen.c \
$(VARNISHSRC)/lib/libvarnish/version.c \
$(VARNISHSRC)/lib/libvarnish/vsb.c \
$(VARNISHSRC)/lib/libvarnish/vpf.c
trackrdrd.c \
parse.c
# $(VARNISHSRC)/lib/libvarnish/assert.c \
# $(VARNISHSRC)/lib/libvarnish/flopen.c \
# $(VARNISHSRC)/lib/libvarnish/version.c \
# $(VARNISHSRC)/lib/libvarnish/vsb.c \
# $(VARNISHSRC)/lib/libvarnish/vpf.c
trackrdrd_LDADD = \
$(VARNISHSRC)/lib/libvarnishcompat/libvarnishcompat.la \
......
/*-
* Copyright (c) 2012 UPLEX Nils Goroll Systemoptimierung
* Copyright (c) 2012 Otto Gmbh & Co KG
* All rights reserved
* Use only with permission
*
* Author: Geoffrey Simmons <geoffrey.simmons@uplex.de>
* Portions adopted from varnishlog.c from the Varnish project
* Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
* Copyright (c) 2006 Verdens Gang AS
* Copyright (c) 2006-2011 Varnish Software AS
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#include <errno.h>
#include <ctype.h>
#include <string.h>
#include "trackrdrd.h"
int
Parse_XID(const char *str, int len, unsigned *xid)
{
unsigned new;
*xid = 0;
for (int i = 0; i < len; i++) {
if (!isdigit(str[i]))
return EINVAL;
new = *xid * 10 + (str[i] - '0');
if (new < *xid)
return ERANGE;
else
*xid = new;
}
return 0;
}
int
Parse_ReqStart(const char *ptr, int len, unsigned *xid)
{
int i;
for (i = len; ptr[i] != ' '; i--)
if (i == 0)
return EINVAL;
return Parse_XID(&ptr[i+1], len-i-1, xid);
}
int
Parse_ReqEnd(const char *ptr, unsigned len, unsigned *xid)
{
char *blank = memchr(ptr, ' ', len);
if (blank == NULL)
return EINVAL;
return Parse_XID(ptr, blank-ptr, xid);
}
/* ptr points to the first char after "track "
len is length from that char to end of data
*/
int
Parse_VCL_Log(const char *ptr, int len, unsigned *xid,
char **data, int *datalen)
{
char *blank = memchr(ptr, ' ', len);
if (blank == NULL)
return EINVAL;
int err = Parse_XID(ptr, blank-ptr, xid);
if (err != 0)
return err;
*data = blank + 1;
*datalen = ptr + len - blank - 1;
return(0);
}
......@@ -44,6 +44,9 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <syslog.h>
#include "trackrdrd.h"
#include "compat/daemon.h"
......@@ -54,6 +57,7 @@
#include "vsl.h"
#include "varnishapi.h"
static int b_flag, c_flag;
/* Ordering-----------------------------------------------------------*/
......@@ -179,33 +183,6 @@ h_order(void *priv, enum VSL_tag_e tag, unsigned fd, unsigned len,
return (0);
}
static void
do_order(struct VSM_data *vd)
{
int i;
if (!b_flag) {
VSL_Select(vd, SLT_SessionOpen);
VSL_Select(vd, SLT_SessionClose);
VSL_Select(vd, SLT_ReqEnd);
}
if (!c_flag) {
VSL_Select(vd, SLT_BackendOpen);
VSL_Select(vd, SLT_BackendClose);
VSL_Select(vd, SLT_BackendReuse);
}
while (1) {
i = VSL_Dispatch(vd, h_order, vd);
if (i == 0) {
clean_order(vd);
AZ(fflush(stdout));
}
else if (i < 0)
break;
}
clean_order(vd);
}
/*--------------------------------------------------------------------*/
static volatile sig_atomic_t reopen;
......@@ -270,15 +247,6 @@ do_write(const struct VSM_data *vd, const char *w_arg, int a_flag)
}
/*--------------------------------------------------------------------*/
void OSL_Log(const char *ptr, unsigned len);
int OSL_Track(void *priv, enum VSL_tag_e tag, unsigned fd, unsigned len,
unsigned spec, const char *ptr, uint64_t bitmap);
void
OSL_Log(const char *ptr, unsigned len)
{
printf("%*s\n", len, ptr);
}
int
OSL_Track(void *priv, enum VSL_tag_e tag, unsigned fd, unsigned len,
......@@ -289,6 +257,10 @@ OSL_Track(void *priv, enum VSL_tag_e tag, unsigned fd, unsigned len,
hashentry *entry;
#endif
int err;
int datalen;
char *data;
syslog(LOG_DEBUG, "%s: %.*s", VSL_tags[tag], len, ptr);
#if 0
/* if spec != 'c', we may have errors reading from SHM */
......@@ -298,15 +270,17 @@ OSL_Track(void *priv, enum VSL_tag_e tag, unsigned fd, unsigned len,
switch (tag) {
case SLT_ReqStart:
OSL_Log(ptr, len);
#if 0
/* May not be able to have the assert()s, if we can't guarantee
that data arrive correctly and in the right order.
In which case we'll have to have lots of error checking,
and ERROR & WARN messages. */
err = Parse_ReqStart(ptr, len, &xid);
AZ(err);
syslog(LOG_DEBUG, "%s: XID=%d", VSL_tags[tag], xid);
#if 0
/* assert(!(hash(XID) exists)); */
/* init hash(XID); */
/* HSH_Insert() should return err if hash(XID) exists */
......@@ -322,19 +296,18 @@ OSL_Track(void *priv, enum VSL_tag_e tag, unsigned fd, unsigned len,
break;
case SLT_VCL_Log:
OSL_Log(ptr, len);
#if 0
int datalen;
char *data;
/* Skip VCL_Log entries without the "track " prefix. */
if (strncmp(ptr, "track ", len) != 0)
if (strncmp(ptr, TRACKLOG_PREFIX, TRACKLOG_PREFIX_LEN) != 0)
break;
/* assert(regex captures XID and data); */
err = Parse_VCL_Log(&ptr[6], len-6, &xid, data, &datalen);
err = Parse_VCL_Log(&ptr[TRACKLOG_PREFIX_LEN], len-TRACKLOG_PREFIX_LEN,
&xid, &data, &datalen);
AZ(err);
syslog(LOG_DEBUG, "%s: XID=%d, datalen=%d, data=%.*s", VSL_tags[tag],
xid, datalen, datalen, data);
#if 0
/* assert((hash(XID) exists) && hash(XID).tid == fd
&& !hash(XID).done); */
entry = HSH_Find(hashtable, xid);
......@@ -356,12 +329,12 @@ OSL_Track(void *priv, enum VSL_tag_e tag, unsigned fd, unsigned len,
break;
case SLT_ReqEnd:
OSL_Log(ptr, len);
#if 0
/* assert(regex.match() && (hash(XID) exists) && hash(XID).tid == fd
&& !hash(XID).done); */
err = Parse_ReqEnd(ptr, len, &xid);
assert(err == 0);
AZ(err);
syslog(LOG_DEBUG, "%s: XID=%d", VSL_tags[tag], xid);
#if 0
entry = HSH_Find(hashtable, xid);
CHECK_OBJ_NOTNULL(entry, HASHENTRY_MAGIC);
assert(entry->xid == xid);
......@@ -407,6 +380,10 @@ main(int argc, char * const *argv)
vd = VSM_New();
VSL_Setup(vd);
openlog(PACKAGE_NAME, LOG_PID | LOG_CONS | LOG_NDELAY | LOG_NOWAIT,
LOG_USER);
atexit(closelog);
while ((c = getopt(argc, argv, VSL_ARGS "aDP:uVw:oO")) != -1) {
switch (c) {
case 'a':
......@@ -480,10 +457,11 @@ main(int argc, char * const *argv)
if (u_flag)
setbuf(stdout, NULL);
if (!O_flag)
do_order(vd);
/*while (VSL_Dispatch(vd, VSL_H_Print, stdout) >= 0) {*/
if (VSL_Arg(vd, 'i', TRACK_TAGS) <= 0) {
fprintf(stderr, "VSL_Arg(i)\n");
exit(1);
}
while (VSL_Dispatch(vd, OSL_Track, stdout) >= 0) {
if (fflush(stdout) != 0) {
perror("stdout");
......
/*-
* Copyright (c) 2012 UPLEX Nils Goroll Systemoptimierung
* Copyright (c) 2012 Otto Gmbh & Co KG
* All rights reserved
* Use only with permission
*
* Author: Geoffrey Simmons <geoffrey.simmons@uplex.de>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#include <stdint.h>
#include "vsl.h"
#define TRACK_TAGS "ReqStart,VCL_log,ReqEnd"
#define TRACKLOG_PREFIX "track "
#define TRACKLOG_PREFIX_LEN (sizeof(TRACKLOG_PREFIX)-1)
int Parse_XID(const char *str, int len, unsigned *xid);
int Parse_ReqStart(const char *ptr, int len, unsigned *xid);
int Parse_ReqEnd(const char *ptr, unsigned len, unsigned *xid);
int Parse_VCL_Log(const char *ptr, int len, unsigned *xid,
char **data, int *datalen);
void OSL_Log(const char *ptr, unsigned len);
int OSL_Track(void *priv, enum VSL_tag_e tag, unsigned fd, unsigned len,
unsigned spec, const char *ptr, uint64_t bitmap);
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