diff --git a/tsweb/tsweb.go b/tsweb/tsweb.go index 31c0cef87..8b52e656d 100644 --- a/tsweb/tsweb.go +++ b/tsweb/tsweb.go @@ -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) diff --git a/tsweb/tsweb_test.go b/tsweb/tsweb_test.go index 4b6b5e7c8..c1bcd34f7 100644 --- a/tsweb/tsweb_test.go +++ b/tsweb/tsweb_test.go @@ -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",