From 8fa302661425d56f9fed4450232736aa8fb56bad Mon Sep 17 00:00:00 2001 From: James Tucker Date: Tue, 9 Apr 2024 13:06:48 -0700 Subject: [PATCH] tsweb: switch to fastuuid for request ID generation Request ID generation appears prominently in some services cumulative allocation rate, and while this does not eradicate this issue (the API still makes UUID objects), it does improve the overhead of this API and reduce the amount of garbage that it produces. Updates tailscale/corp#18266 Updates tailscale/corp#19054 Signed-off-by: James Tucker --- cmd/derper/depaware.txt | 4 +++- cmd/stund/depaware.txt | 4 +++- tsweb/request_id.go | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cmd/derper/depaware.txt b/cmd/derper/depaware.txt index 0b6df2561..aafbac821 100644 --- a/cmd/derper/depaware.txt +++ b/cmd/derper/depaware.txt @@ -17,7 +17,7 @@ tailscale.com/cmd/derper dependencies: (generated by github.com/tailscale/depawa L github.com/google/nftables/expr from github.com/google/nftables+ L github.com/google/nftables/internal/parseexprfunc from github.com/google/nftables+ L github.com/google/nftables/xt from github.com/google/nftables/expr+ - github.com/google/uuid from tailscale.com/tsweb + github.com/google/uuid from tailscale.com/util/fastuuid github.com/hdevalence/ed25519consensus from tailscale.com/tka L github.com/josharian/native from github.com/mdlayher/netlink+ L 💣 github.com/jsimonetti/rtnetlink from tailscale.com/net/interfaces+ @@ -143,6 +143,7 @@ tailscale.com/cmd/derper dependencies: (generated by github.com/tailscale/depawa tailscale.com/util/ctxkey from tailscale.com/tsweb+ L 💣 tailscale.com/util/dirwalk from tailscale.com/metrics tailscale.com/util/dnsname from tailscale.com/hostinfo+ + tailscale.com/util/fastuuid from tailscale.com/tsweb tailscale.com/util/httpm from tailscale.com/client/tailscale tailscale.com/util/lineread from tailscale.com/hostinfo+ L tailscale.com/util/linuxfw from tailscale.com/net/netns @@ -250,6 +251,7 @@ tailscale.com/cmd/derper dependencies: (generated by github.com/tailscale/depawa math/big from crypto/dsa+ math/bits from compress/flate+ math/rand from github.com/mdlayher/netlink+ + math/rand/v2 from tailscale.com/util/fastuuid mime from github.com/prometheus/common/expfmt+ mime/multipart from net/http mime/quotedprintable from mime/multipart diff --git a/cmd/stund/depaware.txt b/cmd/stund/depaware.txt index 09c39f3fc..b54ba8480 100644 --- a/cmd/stund/depaware.txt +++ b/cmd/stund/depaware.txt @@ -2,7 +2,7 @@ tailscale.com/cmd/stund dependencies: (generated by github.com/tailscale/depawar github.com/beorn7/perks/quantile from github.com/prometheus/client_golang/prometheus 💣 github.com/cespare/xxhash/v2 from github.com/prometheus/client_golang/prometheus - github.com/google/uuid from tailscale.com/tsweb + github.com/google/uuid from tailscale.com/util/fastuuid 💣 github.com/prometheus/client_golang/prometheus from tailscale.com/tsweb/promvarz github.com/prometheus/client_golang/prometheus/internal from github.com/prometheus/client_golang/prometheus github.com/prometheus/client_model/go from github.com/prometheus/client_golang/prometheus+ @@ -65,6 +65,7 @@ tailscale.com/cmd/stund dependencies: (generated by github.com/tailscale/depawar tailscale.com/util/ctxkey from tailscale.com/tsweb+ L 💣 tailscale.com/util/dirwalk from tailscale.com/metrics tailscale.com/util/dnsname from tailscale.com/tailcfg + tailscale.com/util/fastuuid from tailscale.com/tsweb tailscale.com/util/lineread from tailscale.com/version/distro tailscale.com/util/nocasemaps from tailscale.com/types/ipproto tailscale.com/util/slicesx from tailscale.com/tailcfg @@ -151,6 +152,7 @@ tailscale.com/cmd/stund dependencies: (generated by github.com/tailscale/depawar math/big from crypto/dsa+ math/bits from compress/flate+ math/rand from math/big+ + math/rand/v2 from tailscale.com/util/fastuuid mime from github.com/prometheus/common/expfmt+ mime/multipart from net/http mime/quotedprintable from mime/multipart diff --git a/tsweb/request_id.go b/tsweb/request_id.go index 2db9cb767..8516b8f72 100644 --- a/tsweb/request_id.go +++ b/tsweb/request_id.go @@ -7,8 +7,8 @@ import ( "context" "net/http" - "github.com/google/uuid" "tailscale.com/util/ctxkey" + "tailscale.com/util/fastuuid" ) // RequestID is an opaque identifier for a HTTP request, used to correlate @@ -44,7 +44,7 @@ func GenerateRequestID() RequestID { // REQ-1 indicates the version of the RequestID pattern. It is // currently arbitrary but allows for forward compatible // transitions if needed. - return RequestID("REQ-1" + uuid.NewString()) + return RequestID("REQ-1" + fastuuid.NewUUID().String()) } // SetRequestID is an HTTP middleware that injects a RequestID in the