tsweb: make VarzHandler support untyped expvar.Maps for compatibility
Updates #2635 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>pull/2649/head
parent
7c7eb8094b
commit
c6740da624
|
@ -438,9 +438,9 @@ func writePromExpVar(w io.Writer, prefix string, kv expvar.KeyValue) {
|
||||||
default:
|
default:
|
||||||
fmt.Fprintf(w, "# skipping expvar %q (Go type %T%s) with undeclared Prometheus type\n", name, kv.Value, funcRet)
|
fmt.Fprintf(w, "# skipping expvar %q (Go type %T%s) with undeclared Prometheus type\n", name, kv.Value, funcRet)
|
||||||
return
|
return
|
||||||
case *metrics.LabelMap:
|
case *metrics.LabelMap, *expvar.Map:
|
||||||
// Permit typeless LabelMap for compatibility
|
// Permit typeless LabelMap and expvar.Map for
|
||||||
// with old expvar-registered
|
// compatibility with old expvar-registered
|
||||||
// metrics.LabelMap.
|
// 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)
|
fmt.Fprintf(w, "%s{%s=%q} %v\n", name, label, kv.Key, kv.Value)
|
||||||
})
|
})
|
||||||
} else {
|
} 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",
|
"# 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",
|
"func_float64",
|
||||||
"counter_x",
|
"counter_x",
|
||||||
|
@ -420,16 +432,6 @@ func TestVarzHandler(t *testing.T) {
|
||||||
}(),
|
}(),
|
||||||
"# TYPE m counter\nm{keyname=\"bar\"} 2\nm{keyname=\"foo\"} 1\n",
|
"# 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",
|
"struct_reflect",
|
||||||
"foo",
|
"foo",
|
||||||
|
|
Loading…
Reference in New Issue