mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-16 18:08:40 +00:00
tsweb: make VarzHandler support untyped expvar.Maps for compatibility
Updates #2635 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
7c7eb8094b
commit
c6740da624
@ -438,9 +438,9 @@ func writePromExpVar(w io.Writer, prefix string, kv expvar.KeyValue) {
|
||||
default:
|
||||
fmt.Fprintf(w, "# skipping expvar %q (Go type %T%s) with undeclared Prometheus type\n", name, kv.Value, funcRet)
|
||||
return
|
||||
case *metrics.LabelMap:
|
||||
// Permit typeless LabelMap for compatibility
|
||||
// with old expvar-registered
|
||||
case *metrics.LabelMap, *expvar.Map:
|
||||
// Permit typeless LabelMap and expvar.Map for
|
||||
// compatibility with old expvar-registered
|
||||
// metrics.LabelMap.
|
||||
}
|
||||
}
|
||||
@ -471,7 +471,9 @@ func writePromExpVar(w io.Writer, prefix string, kv expvar.KeyValue) {
|
||||
fmt.Fprintf(w, "%s{%s=%q} %v\n", name, label, kv.Key, kv.Value)
|
||||
})
|
||||
} else {
|
||||
fmt.Fprintf(w, "# skipping expvar.Map %q with incomplete metadata: label %q, Prometheus type %q\n", name, label, typ)
|
||||
v.Do(func(kv expvar.KeyValue) {
|
||||
fmt.Fprintf(w, "%s_%s %v\n", name, kv.Key, kv.Value)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -363,6 +363,18 @@ func TestVarzHandler(t *testing.T) {
|
||||
},
|
||||
"# TYPE s_bar counter\ns_bar 2\n# TYPE s_foo counter\ns_foo 1\n",
|
||||
},
|
||||
{
|
||||
"expvar_map_untyped",
|
||||
"api_status_code",
|
||||
func() *expvar.Map {
|
||||
m := new(expvar.Map)
|
||||
m.Init()
|
||||
m.Add("2xx", 100)
|
||||
m.Add("5xx", 2)
|
||||
return m
|
||||
}(),
|
||||
"api_status_code_2xx 100\napi_status_code_5xx 2\n",
|
||||
},
|
||||
{
|
||||
"func_float64",
|
||||
"counter_x",
|
||||
@ -420,16 +432,6 @@ func TestVarzHandler(t *testing.T) {
|
||||
}(),
|
||||
"# TYPE m counter\nm{keyname=\"bar\"} 2\nm{keyname=\"foo\"} 1\n",
|
||||
},
|
||||
{
|
||||
"expvar_label_map_malformed",
|
||||
"counter_labelmap_lackslabel",
|
||||
func() *expvar.Map {
|
||||
m := new(expvar.Map)
|
||||
m.Init()
|
||||
return m
|
||||
}(),
|
||||
"# skipping expvar.Map \"lackslabel\" with incomplete metadata: label \"\", Prometheus type \"counter\"\n",
|
||||
},
|
||||
{
|
||||
"struct_reflect",
|
||||
"foo",
|
||||
|
Loading…
x
Reference in New Issue
Block a user