tsweb: export version metrics to Prometheus

This will allow tracking build versions and runtime versions in
Prometheus.

Signed-off-by: Anton Tolchanov <anton@tailscale.com>
This commit is contained in:
Anton Tolchanov 2022-11-22 11:22:26 +00:00 committed by Anton Tolchanov
parent 8d84178884
commit f053f16460
2 changed files with 10 additions and 0 deletions

View File

@ -564,6 +564,10 @@ func writePromExpVar(w io.Writer, prefix string, kv expvar.KeyValue) {
writeMemstats(w, &ms)
return
}
if vs, ok := v.(string); ok && strings.HasSuffix(name, "version") {
fmt.Fprintf(w, "%s{version=%q} 1\n", name, vs)
return
}
switch v := v.(type) {
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, uintptr, float32, float64:
fmt.Fprintf(w, "%s %v\n", name, v)

View File

@ -542,6 +542,12 @@ foo_totalY 4
promWriter{},
"custom_var_value 42\n",
},
{
"string_version_var",
"foo_version",
expvar.Func(func() any { return "1.2.3-foo15" }),
"foo_version{version=\"1.2.3-foo15\"} 1\n",
},
{
"field_ordering",
"foo",