mirror of
https://github.com/tailscale/tailscale.git
synced 2025-01-05 23:07:44 +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
|
||||
}
|
||||
}
|
||||
name := prefix + key
|
||||
name := strings.ReplaceAll(prefix+key, "-", "_")
|
||||
|
||||
switch v := kv.Value.(type) {
|
||||
case PrometheusVar:
|
||||
|
@ -359,6 +359,12 @@ func TestVarzHandler(t *testing.T) {
|
||||
new(expvar.Int),
|
||||
"# 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",
|
||||
"counter_foo",
|
||||
|
Loading…
x
Reference in New Issue
Block a user