diff --git a/tsweb/tsweb.go b/tsweb/tsweb.go index e62c5bf6b..230928a28 100644 --- a/tsweb/tsweb.go +++ b/tsweb/tsweb.go @@ -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) { diff --git a/tsweb/tsweb_test.go b/tsweb/tsweb_test.go index 986fb24ad..034c7869c 100644 --- a/tsweb/tsweb_test.go +++ b/tsweb/tsweb_test.go @@ -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 @@ func() *expvar.Map { 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) {