mirror of
https://github.com/tailscale/tailscale.git
synced 2025-10-27 14:21:44 +01:00
tsweb/varz: add support for ShardedInt metrics
Fixes tailscale/corp#33236 Signed-off-by: Anton Tolchanov <anton@tailscale.com>
This commit is contained in:
parent
154d36f73d
commit
072e6a39f4
@ -58,7 +58,7 @@ tailscale.com/cmd/stund dependencies: (generated by github.com/tailscale/depawar
|
|||||||
tailscale.com/net/stun from tailscale.com/net/stunserver
|
tailscale.com/net/stun from tailscale.com/net/stunserver
|
||||||
tailscale.com/net/stunserver from tailscale.com/cmd/stund
|
tailscale.com/net/stunserver from tailscale.com/cmd/stund
|
||||||
tailscale.com/net/tsaddr from tailscale.com/tsweb
|
tailscale.com/net/tsaddr from tailscale.com/tsweb
|
||||||
tailscale.com/syncs from tailscale.com/metrics
|
tailscale.com/syncs from tailscale.com/metrics+
|
||||||
tailscale.com/tailcfg from tailscale.com/version
|
tailscale.com/tailcfg from tailscale.com/version
|
||||||
tailscale.com/tsweb from tailscale.com/cmd/stund+
|
tailscale.com/tsweb from tailscale.com/cmd/stund+
|
||||||
tailscale.com/tsweb/promvarz from tailscale.com/cmd/stund
|
tailscale.com/tsweb/promvarz from tailscale.com/cmd/stund
|
||||||
|
|||||||
@ -25,6 +25,7 @@ import (
|
|||||||
|
|
||||||
"golang.org/x/exp/constraints"
|
"golang.org/x/exp/constraints"
|
||||||
"tailscale.com/metrics"
|
"tailscale.com/metrics"
|
||||||
|
"tailscale.com/syncs"
|
||||||
"tailscale.com/types/logger"
|
"tailscale.com/types/logger"
|
||||||
"tailscale.com/version"
|
"tailscale.com/version"
|
||||||
)
|
)
|
||||||
@ -136,6 +137,9 @@ func writePromExpVar(w io.Writer, prefix string, kv expvar.KeyValue) {
|
|||||||
case *expvar.Int:
|
case *expvar.Int:
|
||||||
fmt.Fprintf(w, "# TYPE %s %s\n%s %v\n", name, cmp.Or(typ, "counter"), name, v.Value())
|
fmt.Fprintf(w, "# TYPE %s %s\n%s %v\n", name, cmp.Or(typ, "counter"), name, v.Value())
|
||||||
return
|
return
|
||||||
|
case *syncs.ShardedInt:
|
||||||
|
fmt.Fprintf(w, "# TYPE %s %s\n%s %v\n", name, cmp.Or(typ, "counter"), name, v.Value())
|
||||||
|
return
|
||||||
case *expvar.Float:
|
case *expvar.Float:
|
||||||
fmt.Fprintf(w, "# TYPE %s %s\n%s %v\n", name, cmp.Or(typ, "gauge"), name, v.Value())
|
fmt.Fprintf(w, "# TYPE %s %s\n%s %v\n", name, cmp.Or(typ, "gauge"), name, v.Value())
|
||||||
return
|
return
|
||||||
|
|||||||
@ -13,6 +13,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"tailscale.com/metrics"
|
"tailscale.com/metrics"
|
||||||
|
"tailscale.com/syncs"
|
||||||
"tailscale.com/tstest"
|
"tailscale.com/tstest"
|
||||||
"tailscale.com/util/racebuild"
|
"tailscale.com/util/racebuild"
|
||||||
"tailscale.com/version"
|
"tailscale.com/version"
|
||||||
@ -283,6 +284,20 @@ foo_foo_a 1
|
|||||||
foo_foo_b 1
|
foo_foo_b 1
|
||||||
`) + "\n",
|
`) + "\n",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"metrics_sharded_int",
|
||||||
|
"counter_api_status_code",
|
||||||
|
func() *syncs.ShardedInt {
|
||||||
|
m := syncs.NewShardedInt()
|
||||||
|
m.Add(40)
|
||||||
|
m.Add(2)
|
||||||
|
return m
|
||||||
|
}(),
|
||||||
|
strings.TrimSpace(`
|
||||||
|
# TYPE api_status_code counter
|
||||||
|
api_status_code 42
|
||||||
|
`) + "\n",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user