Skip to content

Commit

Permalink
tsweb: normalize common StableID's in bucketed stats, export as LabelMap
Browse files Browse the repository at this point in the history
Signed-off-by: Tom DNetto <tom@tailscale.com>
Updates: corp#17075
  • Loading branch information
twitchyliquid64 committed Feb 7, 2024
1 parent e0762fe commit 8d6d9d2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tsweb/tsweb.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"go4.org/mem"
"tailscale.com/envknob"
"tailscale.com/metrics"
"tailscale.com/net/tsaddr"
"tailscale.com/tsweb/varz"
"tailscale.com/types/logger"
Expand Down Expand Up @@ -185,18 +186,18 @@ type BucketedStatsOptions struct {

// If non-nil, Started maintains a counter of all requests which
// have begun processing.
Started *expvar.Map
Started *metrics.LabelMap

// If non-nil, Finished maintains a counter of all requests which
// have finished processing (that is, the HTTP handler has returned).
Finished *expvar.Map
Finished *metrics.LabelMap
}

// normalizePathRegex matches components in a HTTP request path
// that should be replaced.
//
// See: https://regex101.com/r/WIfpaR/1 for the explainer and test cases.
var normalizePathRegex = regexp.MustCompile("([a-fA-F0-9]{9,}|([^\\/])+\\.([^\\/]){2,})")
var normalizePathRegex = regexp.MustCompile("([a-fA-F0-9]{9,}|([^\\/])+\\.([^\\/]){2,}|((n|k|u|L|t|S)[a-zA-Z0-9]{5,}(CNTRL|Djz1H|LV5CY|mxgaY|jNy1b)))")

// NormalizedPath returns the given path with the following modifications:
//
Expand All @@ -205,6 +206,7 @@ var normalizePathRegex = regexp.MustCompile("([a-fA-F0-9]{9,}|([^\\/])+\\.([^\\/
// replaced by an ellipsis
// - any path component containing a period with at least two characters
// after the period (i.e. an email or domain)
// - any path component consisting of a common Tailscale Stable ID.
func NormalizedPath(p string) string {
// Fastpath: No hex sequences in there we might have to trim.
// Avoids allocating.
Expand Down
2 changes: 2 additions & 0 deletions tsweb/tsweb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,8 @@ func TestBucket(t *testing.T) {
{"/api/v2/tailnet/jeremiah@squish.com/devices", "/api/v2/tailnet/…/devices"},
{"/machine/ssh/wait/5227109621243650/to/7111899293970143/a/a9e4e04cc01b", "/machine/ssh/wait/…/to/…/a/…"},
{"/a/831a4bf39856?refreshed=true", "/a/…"},
{"/c2n/nxaaa1CNTRL", "/c2n/…"},
{"/api/v2/tailnet/blueberries.com/keys/kxaDK21CNTRL", "/api/v2/tailnet/…/keys/…"},
}

for _, tc := range tcs {
Expand Down

0 comments on commit 8d6d9d2

Please sign in to comment.