[master] a93c455 Put the VSC->type (ie: MAIN, VBE etc.) into the ->ident field.

Poul-Henning Kamp phk at FreeBSD.org
Thu Jun 8 15:01:06 CEST 2017


commit a93c4555ef664ce2835cb43d4cccddd188a27ecf
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Jun 8 12:54:45 2017 +0000

    Put the VSC->type (ie: MAIN, VBE etc.) into the ->ident field.
    
    Also add back the "formats" property for VSC counters.

diff --git a/bin/varnishd/main.vsc b/bin/varnishd/main.vsc
index c903c28..97ca0a2 100644
--- a/bin/varnishd/main.vsc
+++ b/bin/varnishd/main.vsc
@@ -16,6 +16,7 @@
 
 .. varnish_vsc:: uptime
 	:oneliner:	Child process uptime
+	:format:	duration
 
 	How long the child process has been running.
 
diff --git a/bin/varnishd/mempool.vsc b/bin/varnishd/mempool.vsc
index 2890863..0f333cc 100644
--- a/bin/varnishd/mempool.vsc
+++ b/bin/varnishd/mempool.vsc
@@ -24,12 +24,14 @@
 .. varnish_vsc:: sz_wanted
 	:type:	gauge
 	:level:	debug
+	:format: bytes
 	:oneliner:	Size requested
 
 
 .. varnish_vsc:: sz_actual
 	:type:	gauge
 	:level:	debug
+	:format: bytes
 	:oneliner:	Size allocated
 
 
diff --git a/bin/varnishd/sma.vsc b/bin/varnishd/sma.vsc
index 9b4aadd..5756bec 100644
--- a/bin/varnishd/sma.vsc
+++ b/bin/varnishd/sma.vsc
@@ -26,6 +26,7 @@
 .. varnish_vsc:: c_bytes
 	:type:	counter
 	:level:	info
+	:format: bytes
 	:oneliner:	Bytes allocated
 
 	Number of total bytes allocated by this storage.
@@ -33,6 +34,7 @@
 .. varnish_vsc:: c_freed
 	:type:	counter
 	:level:	info
+	:format: bytes
 	:oneliner:	Bytes freed
 
 	Number of total bytes returned to this storage.
@@ -47,6 +49,7 @@
 .. varnish_vsc:: g_bytes
 	:type:	gauge
 	:level:	info
+	:format: bytes
 	:oneliner:	Bytes outstanding
 
 	Number of bytes allocated from the storage.
@@ -54,6 +57,7 @@
 .. varnish_vsc:: g_space
 	:type:	gauge
 	:level:	info
+	:format: bytes
 	:oneliner:	Bytes available
 
 	Number of bytes left in the storage.
diff --git a/bin/varnishd/smf.vsc b/bin/varnishd/smf.vsc
index 806b2a6..3ba2f3f 100644
--- a/bin/varnishd/smf.vsc
+++ b/bin/varnishd/smf.vsc
@@ -26,6 +26,7 @@
 .. varnish_vsc:: c_bytes
 	:type:	counter
 	:level:	info
+	:format: bytes
 	:oneliner:	Bytes allocated
 
 	Number of total bytes allocated by this storage.
@@ -33,6 +34,7 @@
 .. varnish_vsc:: c_freed
 	:type:	counter
 	:level:	info
+	:format: bytes
 	:oneliner:	Bytes freed
 
 	Number of total bytes returned to this storage.
@@ -47,6 +49,7 @@
 .. varnish_vsc:: g_bytes
 	:type:	gauge
 	:level:	info
+	:format: bytes
 	:oneliner:	Bytes outstanding
 
 	Number of bytes allocated from the storage.
@@ -54,6 +57,7 @@
 .. varnish_vsc:: g_space
 	:type:	gauge
 	:level:	info
+	:format: bytes
 	:oneliner:	Bytes available
 
 	Number of bytes left in the storage.
diff --git a/bin/varnishd/vbe.vsc b/bin/varnishd/vbe.vsc
index a84acbb..6ce7ee1 100644
--- a/bin/varnishd/vbe.vsc
+++ b/bin/varnishd/vbe.vsc
@@ -17,6 +17,7 @@
 .. varnish_vsc:: bereq_hdrbytes
 	:type:	counter
 	:level:	info
+	:format: bytes
 	:oneliner:	Request header bytes
 
 	Total backend request header bytes sent
@@ -24,6 +25,7 @@
 .. varnish_vsc:: bereq_bodybytes
 	:type:	counter
 	:level:	info
+	:format: bytes
 	:oneliner:	Request body bytes
 
 	Total backend request body bytes sent
@@ -31,6 +33,7 @@
 .. varnish_vsc:: beresp_hdrbytes
 	:type:	counter
 	:level:	info
+	:format: bytes
 	:oneliner:	Response header bytes
 
 	Total backend response header bytes received
@@ -38,6 +41,7 @@
 .. varnish_vsc:: beresp_bodybytes
 	:type:	counter
 	:level:	info
+	:format: bytes
 	:oneliner:	Response body bytes
 
 	Total backend response body bytes received
@@ -45,6 +49,7 @@
 .. varnish_vsc:: pipe_hdrbytes
 	:type:	counter
 	:level:	info
+	:format: bytes
 	:oneliner:	Pipe request header bytes
 
 	Total request bytes sent for piped sessions
@@ -52,6 +57,7 @@
 .. varnish_vsc:: pipe_out
 	:type:	counter
 	:level:	info
+	:format: bytes
 	:oneliner:	Piped bytes to backend
 
 	Total number of bytes forwarded to backend in pipe sessions
@@ -59,6 +65,7 @@
 .. varnish_vsc:: pipe_in
 	:type:	counter
 	:level:	info
+	:format: bytes
 	:oneliner:	Piped bytes from backend
 
 	Total number of bytes forwarded from backend in pipe sessions
diff --git a/bin/varnishstat/varnishstat.c b/bin/varnishstat/varnishstat.c
index 2323b2b..7f6bd33 100644
--- a/bin/varnishstat/varnishstat.c
+++ b/bin/varnishstat/varnishstat.c
@@ -66,11 +66,7 @@ do_xml_cb(void *priv, const struct VSC_point * const pt)
 	sec = pt->section;
 
 	printf("\t<stat>\n");
-	if (strcmp(sec->type, ""))
-		printf("\t\t<type>%s</type>\n", sec->type);
-	if (strcmp(sec->ident, ""))
-		printf("\t\t<ident>%s</ident>\n", sec->ident);
-	printf("\t\t<name>%s</name>\n", pt->desc->name);
+	printf("\t\t<name>%s.%s</name>\n", sec->ident, pt->desc->name);
 	printf("\t\t<value>%ju</value>\n", (uintmax_t)val);
 	printf("\t\t<flag>%c</flag>\n", pt->desc->semantics);
 	printf("\t\t<format>%c</format>\n", pt->desc->format);
@@ -118,18 +114,12 @@ do_json_cb(void *priv, const struct VSC_point * const pt)
 
 	printf("  \"");
 	/* build the JSON key name.  */
-	if (sec->type[0])
-		printf("%s.", sec->type);
 	if (sec->ident[0])
 		printf("%s.", sec->ident);
 	printf("%s\": {\n", pt->desc->name);
 	printf("    \"description\": \"%s\",\n", pt->desc->sdesc);
 
-	if (strcmp(sec->type, ""))
-		printf("    \"type\": \"%s\", ", sec->type);
-	if (strcmp(sec->ident, ""))
-		printf("\"ident\": \"%s\", ", sec->ident);
-	printf("\"flag\": \"%c\", ", pt->desc->semantics);
+	printf("    \"flag\": \"%c\", ", pt->desc->semantics);
 	printf("\"format\": \"%c\",\n", pt->desc->format);
 	printf("    \"value\": %ju", (uintmax_t)val);
 	printf("\n  }");
@@ -177,7 +167,7 @@ do_once_cb_first(void *priv, const struct VSC_point * const pt)
 	op = priv;
 	AZ(strcmp(pt->desc->ctype, "uint64_t"));
 	sec = pt->section;
-	if (strcmp(sec->type, "MAIN") || strcmp(pt->desc->name, "uptime"))
+	if (strcmp(sec->ident, "MAIN") || strcmp(pt->desc->name, "uptime"))
 		return (0);
 	val = *(const volatile uint64_t*)pt->ptr;
 	op->up = (double)val;
@@ -199,8 +189,6 @@ do_once_cb(void *priv, const struct VSC_point * const pt)
 	val = *(const volatile uint64_t*)pt->ptr;
 	sec = pt->section;
 	i = 0;
-	if (strcmp(sec->type, ""))
-		i += printf("%s.", sec->type);
 	if (strcmp(sec->ident, ""))
 		i += printf("%s.", sec->ident);
 	i += printf("%s", pt->desc->name);
@@ -244,8 +232,6 @@ do_list_cb(void *priv, const struct VSC_point * const pt)
 
 	sec = pt->section;
 	i = 0;
-	if (strcmp(sec->type, ""))
-		i += printf("%s.", sec->type);
 	if (strcmp(sec->ident, ""))
 		i += printf("%s.", sec->ident);
 	i += printf("%s", pt->desc->name);
diff --git a/bin/varnishstat/varnishstat_curses.c b/bin/varnishstat/varnishstat_curses.c
index 6d3d142..97995dd 100644
--- a/bin/varnishstat/varnishstat_curses.c
+++ b/bin/varnishstat/varnishstat_curses.c
@@ -276,8 +276,7 @@ build_pt_list_cb(void *priv, const struct VSC_point *vpt)
 	CAST_OBJ_NOTNULL(pt_priv, priv, PT_PRIV_MAGIC);
 
 	AZ(strcmp(vpt->desc->ctype, "uint64_t"));
-	bprintf(buf, "%s.%s.%s", vpt->section->type,
-	    vpt->section->ident, vpt->desc->name);
+	bprintf(buf, "%s.%s", vpt->section->ident, vpt->desc->name);
 
 	if (!strcmp(buf, "MGT..uptime"))
 		mgt_uptime = vpt->ptr;
@@ -313,12 +312,7 @@ build_pt_list_cb(void *priv, const struct VSC_point *vpt)
 	pt->key = strdup(buf);
 	AN(pt->key);
 
-	if (*vpt->section->type != '\0')
-		bprintf(buf, "%s.%s", vpt->section->type, vpt->desc->name);
-	else if (*vpt->section->ident != '\0')
-		bprintf(buf, "%s.%s", vpt->section->ident, vpt->desc->name);
-	else
-		bprintf(buf, "%s", vpt->desc->name);
+	bprintf(buf, "%s.%s", vpt->section->ident, vpt->desc->name);
 	REPLACE(pt->name, buf);
 	AN(pt->name);
 
diff --git a/bin/varnishtest/tests/u00005.vtc b/bin/varnishtest/tests/u00005.vtc
index 4b068d4..2653854 100644
--- a/bin/varnishtest/tests/u00005.vtc
+++ b/bin/varnishtest/tests/u00005.vtc
@@ -45,7 +45,7 @@ shell -err -expect "Cannot open /nonexistent/_.vsm" \
 	"varnishstat -n /nonexistent -t 1"
 shell -expect "MAIN.uptime" \
 	"varnishstat -n ${v1_name} -1"
-shell -expect "<type>MAIN</type>" \
+shell -expect "<name>MAIN.uptime</name>" \
 	"varnishstat -n ${v1_name} -x"
 shell -match {"MAIN.uptime":} \
 	"varnishstat -n ${v1_name} -j"
diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c
index c385ffc..82d8444 100644
--- a/bin/varnishtest/vtc_varnish.c
+++ b/bin/varnishtest/vtc_varnish.c
@@ -822,11 +822,7 @@ do_stat_dump_cb(void *priv, const struct VSC_point * const pt)
 		return (0);
 	u = *(const volatile uint64_t*)pt->ptr;
 
-	strcpy(buf, pt->section->type);
-	if (pt->section->ident[0] != '\0')
-		bprintf(buf, "%s.%s", pt->section->ident, pt->desc->name);
-	else
-		bprintf(buf, "MAIN.%s", pt->desc->name);
+	bprintf(buf, "%s.%s", pt->section->ident, pt->desc->name);
 
 	if (strcmp(dp->arg, "*")) {
 		if (fnmatch(dp->arg, buf, 0))
@@ -858,7 +854,6 @@ varnish_vsc(const struct varnish *v, const char *arg)
  */
 
 struct stat_priv {
-	char target_type[256];
 	char target_ident[256];
 	char target_name[256];
 	uintmax_t val;
@@ -873,8 +868,6 @@ do_stat_cb(void *priv, const struct VSC_point * const pt)
 	if (pt == NULL)
 		return(0);
 
-	if (strcmp(pt->section->type, sp->target_type))
-		return(0);
 	if (strcmp(pt->section->ident, sp->target_ident))
 		return(0);
 	if (strcmp(pt->desc->name, sp->target_name))
@@ -895,7 +888,6 @@ varnish_expect(const struct varnish *v, char * const *av)
 	int good;
 	char *r;
 	char *p;
-	char *q;
 	int i, not = 0;
 	struct stat_priv sp;
 
@@ -908,22 +900,13 @@ varnish_expect(const struct varnish *v, char * const *av)
 		AN(av[1]);
 		AN(av[2]);
 	}
-	p = strchr(r, '.');
+	p = strrchr(r, '.');
 	if (p == NULL) {
-		strcpy(sp.target_type, "MAIN");
-		sp.target_ident[0] = '\0';
+		strcpy(sp.target_ident, "MAIN");
 		bprintf(sp.target_name, "%s", r);
 	} else {
-		bprintf(sp.target_type, "%.*s", (int)(p - r), r);
-		p++;
-		q = strrchr(p, '.');
-		if (q == NULL) {
-			sp.target_ident[0] = '\0';
-			bprintf(sp.target_name, "%s", p);
-		} else {
-			bprintf(sp.target_ident, "%.*s", (int)(q - p), p);
-			bprintf(sp.target_name, "%s", q + 1);
-		}
+		bprintf(sp.target_ident, "%.*s", (int)(p - r), r);
+		bprintf(sp.target_name, "%s", p + 1);
 	}
 
 	sp.val = 0;
diff --git a/include/vapi/vsc.h b/include/vapi/vsc.h
index 3f96f09..c53d388 100644
--- a/include/vapi/vsc.h
+++ b/include/vapi/vsc.h
@@ -85,7 +85,6 @@ struct VSC_level_desc {
 };
 
 struct VSC_section {
-	char *type;
 	char *ident;
 };
 
diff --git a/lib/libvarnishapi/vsc.c b/lib/libvarnishapi/vsc.c
index 37334f2..339b588 100644
--- a/lib/libvarnishapi/vsc.c
+++ b/lib/libvarnishapi/vsc.c
@@ -249,12 +249,19 @@ static struct vsc_vf *
 vsc_add_vf(struct vsc *vsc, const struct VSM_fantom *fantom, int order)
 {
 	struct vsc_vf *vf, *vf2;
+	struct vsb *vsb;
 
 	ALLOC_OBJ(vf, VSC_VF_MAGIC);
 	AN(vf);
 	vf->fantom = *fantom;
-	REPLACE(vf->section.type, vf->fantom.type);
-	REPLACE(vf->section.ident, vf->fantom.ident);
+	vsb = VSB_new_auto();
+	AN(vsb);
+	VSB_printf(vsb, "%s", vf->fantom.type);
+	if (*vf->fantom.ident != '\0')
+		VSB_printf(vsb, ".%s", vf->fantom.ident);
+	AZ(VSB_finish(vsb));
+	REPLACE(vf->section.ident, VSB_data(vsb));
+	VSB_destroy(&vsb);
 	vf->order = order;
 
 	VTAILQ_FOREACH(vf2, &vsc->vf_list, list) {
@@ -355,7 +362,38 @@ vsc_build_pt_list(struct VSM_data *vd)
 			DOF(sdesc, "oneliner");
 			DOF(ldesc, "docs");
 #undef DOF
+			vt = vjsn_child(vv, "type");
+			AN(vt);
+			assert(vt->type == VJSN_STRING);
+
+			if (!strcmp(vt->value, "counter")) {
+				vdsc->semantics = 'c';
+			} else if (!strcmp(vt->value, "gauge")) {
+				vdsc->semantics = 'g';
+			} else if (!strcmp(vt->value, "bitmap")) {
+				vdsc->semantics = 'b';
+			} else {
+				vdsc->semantics = '?';
+			}
+
+			vt = vjsn_child(vv, "format");
+			AN(vt);
+			assert(vt->type == VJSN_STRING);
+
+			if (!strcmp(vt->value, "integer")) {
+				vdsc->format = 'i';
+			} else if (!strcmp(vt->value, "bytes")) {
+				vdsc->format = 'B';
+			} else if (!strcmp(vt->value, "bitmap")) {
+				vdsc->format = 'b';
+			} else if (!strcmp(vt->value, "duration")) {
+				vdsc->format = 'd';
+			} else {
+				vdsc->format = '?';
+			}
+
 			vdsc->level = &level_info;
+
 			vt = vjsn_child(vv, "index");
 			AN(vt);
 			vsc_add_pt(vsc,
@@ -373,8 +411,6 @@ vsc_filter_match_pt(struct vsb *vsb, const struct vsc_sf *sf, const
     struct vsc_pt *pt)
 {
 	VSB_clear(vsb);
-	if (strcmp(pt->point.section->type, ""))
-		VSB_printf(vsb, "%s.", pt->point.section->type);
 	if (strcmp(pt->point.section->ident, ""))
 		VSB_printf(vsb, "%s.", pt->point.section->ident);
 	VSB_printf(vsb, "%s", pt->point.desc->name);
diff --git a/lib/libvcc/vsctool.py b/lib/libvcc/vsctool.py
index 00a1714..93c7d2d 100644
--- a/lib/libvcc/vsctool.py
+++ b/lib/libvcc/vsctool.py
@@ -43,12 +43,14 @@ import collections
 TYPES = [ "counter", "gauge", "bitmap" ]
 CTYPES = [ "uint64_t" ]
 LEVELS = [ "info", "diag", "debug" ]
+FORMATS = [ "integer", "bytes", "duration" ]
 
 PARAMS = {
 	"type":		["counter", TYPES],
 	"ctype":	["uint64_t", CTYPES],
 	"level":	["info", LEVELS],
 	"oneliner":	True,
+	"format":	[ "integer", FORMATS],
 }
 
 def gzip_str(s):



More information about the varnish-commit mailing list