mirror of
https://github.com/tailscale/tailscale.git
synced 2025-01-07 16:17:41 +00:00
tsweb: avoid dashes in Prometheus metric names
Ideally we should strip other invalid characters too, but that would call for a regexp replacement which increases the number of allocations and makes `TestVarzHandlerSorting` fail. Signed-off-by: Anton Tolchanov <anton@tailscale.com>
This commit is contained in:
parent
dd50dcd067
commit
3c27632ffe
@ -474,7 +474,7 @@ func writePromExpVar(w io.Writer, prefix string, kv expvar.KeyValue) {
|
|||||||
label, key = a, b
|
label, key = a, b
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
name := prefix + key
|
name := strings.ReplaceAll(prefix+key, "-", "_")
|
||||||
|
|
||||||
switch v := kv.Value.(type) {
|
switch v := kv.Value.(type) {
|
||||||
case PrometheusVar:
|
case PrometheusVar:
|
||||||
|
@ -359,6 +359,12 @@ func TestVarzHandler(t *testing.T) {
|
|||||||
new(expvar.Int),
|
new(expvar.Int),
|
||||||
"# TYPE foo counter\nfoo 0\n",
|
"# TYPE foo counter\nfoo 0\n",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"dash_in_metric_name",
|
||||||
|
"counter_foo-bar",
|
||||||
|
new(expvar.Int),
|
||||||
|
"# TYPE foo_bar counter\nfoo_bar 0\n",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"int_with_type_counter",
|
"int_with_type_counter",
|
||||||
"counter_foo",
|
"counter_foo",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user