[6.0] 50926acbe varnishhish: Add a prefix to custom Profile definitions

Nils Goroll nils.goroll at uplex.de
Thu Aug 16 08:52:22 UTC 2018


commit 50926acbe55b4f851e5f593dab5d17ca5dbd6e9b
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Wed Mar 21 14:38:02 2018 +0100

    varnishhish: Add a prefix to custom Profile definitions
    
    Without it, graphing Timestamp tags was impossible for all practical purposes

diff --git a/bin/varnishhist/varnishhist.c b/bin/varnishhist/varnishhist.c
index dd7e49749..27d3174bc 100644
--- a/bin/varnishhist/varnishhist.c
+++ b/bin/varnishhist/varnishhist.c
@@ -501,8 +501,8 @@ int
 main(int argc, char **argv)
 {
 	int i;
-	const char *colon, *ptag;
-	const char *profile = "responsetime";
+	char *colon;
+	const char *ptag, *profile = "responsetime";
 	pthread_t thr;
 	int fnum = -1;
 	struct profile cli_p = {0};
@@ -528,7 +528,7 @@ main(int argc, char **argv)
 				profile = optarg;
 				break;
 			}
-			/* else it's a definition, we hope */
+			/* else check if valid definition */
 			if (colon == optarg + 1 &&
 			    (*optarg == 'b' || *optarg == 'c')) {
 				cli_p.VSL_arg = *optarg;
@@ -542,15 +542,27 @@ main(int argc, char **argv)
 			}
 
 			assert(colon);
-			if (sscanf(colon + 1, "%d:%d:%d", &cli_p.field,
-			    &cli_p.hist_low, &cli_p.hist_high) != 3)
-				profile_error(optarg);
 
 			match_tag = VSL_Name2Tag(ptag, colon - ptag);
 			if (match_tag < 0)
 				VUT_Error(vut, 1,
 				    "-P: '%s' is not a valid tag name",
 				    optarg);
+
+			cli_p.prefix = colon + 1;
+			colon = strchr(colon + 1, ':');
+
+			if (colon == NULL)
+				profile_error(optarg);
+
+			*colon = '\0';
+			if (*cli_p.prefix == '\0')
+				cli_p.prefix = NULL;
+
+			if (sscanf(colon + 1, "%d:%d:%d", &cli_p.field,
+			    &cli_p.hist_low, &cli_p.hist_high) != 3)
+				profile_error(optarg);
+
 			if (VSL_tagflags[match_tag])
 				VUT_Error(vut, 1,
 				    "-P: '%s' is an unsafe or binary record",
diff --git a/bin/varnishhist/varnishhist_options.h b/bin/varnishhist/varnishhist_options.h
index 7ad374bf7..999a678f4 100644
--- a/bin/varnishhist/varnishhist_options.h
+++ b/bin/varnishhist/varnishhist_options.h
@@ -47,13 +47,14 @@
 	)
 
 #define HIS_OPT_P							\
-	VOPT("P:", "[-P <[cb:]tag:field_num:min:max>]",			\
+	VOPT("P:", "[-P <[cb:]tag:[prefix]:field_num:min:max>]",	\
 	    "Custom profile definition",				\
 	    "Graph the given custom definition defined as: an optional" \
 	    " (c)lient or (b)ackend filter (defaults to client), the"	\
-	    " tag we'll look for, and the field number of the value we" \
-	    " are interested in. min and max are the boundaries of the" \
-	    " graph (these are power of ten)."				\
+	    " tag we'll look for, a prefix to look for (can be empty,"	\
+	    " but must be terminated by a colon) and the field number"	\
+	    " of the value we are interested in. min and max are the"	\
+	    " boundaries of the graph (these are power of ten)."	\
 	)
 
 #define HIS_OPT_B							\
diff --git a/doc/changes.rst b/doc/changes.rst
index af44652d7..bb85dc2a4 100644
--- a/doc/changes.rst
+++ b/doc/changes.rst
@@ -1,3 +1,14 @@
+====================
+Varnish Cache master
+====================
+
+bundled tools
+-------------
+
+* ``varnishhist``: The format of the ``-P`` argument has been changed
+  for custom profile definitions to also contain a prefix to match the
+  tag against.
+
 ================================
 Varnish Cache 6.0.0 (2018-03-15)
 ================================


More information about the varnish-commit mailing list