tsweb: make VarzHandler support expvar.Funcs returning ints/floats

Updates #2635
pull/2649/head
Brad Fitzpatrick 3 years ago
parent 5aba620fb9
commit 7c7eb8094b

@ -427,6 +427,11 @@ func writePromExpVar(w io.Writer, prefix string, kv expvar.KeyValue) {
writeMemstats(w, &ms)
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)
return
}
funcRet = fmt.Sprintf(" returning %T", v)
}
switch kv.Value.(type) {

@ -379,7 +379,7 @@ func TestVarzHandler(t *testing.T) {
"func_float64_untyped",
"x",
expvar.Func(func() interface{} { return float64(1.2) }),
"# skipping expvar \"x\" (Go type expvar.Func returning float64) with undeclared Prometheus type\n",
"x 1.2\n",
},
{
"metrics_label_map",
@ -461,6 +461,12 @@ foo_AUint16 65535
expvarAdapter{(*SomeStats)(nil)},
"",
},
{
"func_returning_int",
"num_goroutines",
expvar.Func(func() interface{} { return 123 }),
"num_goroutines 123\n",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

Loading…
Cancel
Save