mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-16 19:51:41 +00:00
client/web: add metric for exit node advertising (#9781)
* client/web: add metric for exit node advertising Updates tailscale/corp#15215 Signed-off-by: Naman Sood <mail@nsood.in> * client/web: use http request's context for IncrementCounter Updates #cleanup Signed-off-by: Naman Sood <mail@nsood.in> --------- Signed-off-by: Naman Sood <mail@nsood.in>
This commit is contained in:
parent
ce0830837d
commit
7783a960e8
@ -66,6 +66,11 @@ const (
|
|||||||
sessionCookieExpiry = time.Hour * 24 * 30 // 30 days
|
sessionCookieExpiry = time.Hour * 24 * 30 // 30 days
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
exitNodeRouteV4 = netip.MustParsePrefix("0.0.0.0/0")
|
||||||
|
exitNodeRouteV6 = netip.MustParsePrefix("::/0")
|
||||||
|
)
|
||||||
|
|
||||||
// browserSession holds data about a user's browser session
|
// browserSession holds data about a user's browser session
|
||||||
// on the full management web client.
|
// on the full management web client.
|
||||||
type browserSession struct {
|
type browserSession struct {
|
||||||
@ -189,7 +194,7 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !s.devMode {
|
if !s.devMode {
|
||||||
s.lc.IncrementCounter(context.Background(), "web_client_page_load", 1)
|
s.lc.IncrementCounter(r.Context(), "web_client_page_load", 1)
|
||||||
}
|
}
|
||||||
s.assetsHandler.ServeHTTP(w, r)
|
s.assetsHandler.ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
@ -427,8 +432,6 @@ func (s *Server) serveGetNodeData(w http.ResponseWriter, r *http.Request) {
|
|||||||
IPNVersion: versionShort,
|
IPNVersion: versionShort,
|
||||||
DebugMode: s.tsDebugMode,
|
DebugMode: s.tsDebugMode,
|
||||||
}
|
}
|
||||||
exitNodeRouteV4 := netip.MustParsePrefix("0.0.0.0/0")
|
|
||||||
exitNodeRouteV6 := netip.MustParsePrefix("::/0")
|
|
||||||
for _, r := range prefs.AdvertiseRoutes {
|
for _, r := range prefs.AdvertiseRoutes {
|
||||||
if r == exitNodeRouteV4 || r == exitNodeRouteV6 {
|
if r == exitNodeRouteV4 || r == exitNodeRouteV6 {
|
||||||
data.AdvertiseExitNode = true
|
data.AdvertiseExitNode = true
|
||||||
@ -473,6 +476,22 @@ func (s *Server) servePostNodeUpdate(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prefs, err := s.lc.GetPrefs(r.Context())
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
isCurrentlyExitNode := slices.Contains(prefs.AdvertiseRoutes, exitNodeRouteV4) || slices.Contains(prefs.AdvertiseRoutes, exitNodeRouteV6)
|
||||||
|
|
||||||
|
if postData.AdvertiseExitNode != isCurrentlyExitNode {
|
||||||
|
if postData.AdvertiseExitNode {
|
||||||
|
s.lc.IncrementCounter(r.Context(), "web_client_advertise_exitnode_enable", 1)
|
||||||
|
} else {
|
||||||
|
s.lc.IncrementCounter(r.Context(), "web_client_advertise_exitnode_disable", 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
routes, err := netutil.CalcAdvertiseRoutes(postData.AdvertiseRoutes, postData.AdvertiseExitNode)
|
routes, err := netutil.CalcAdvertiseRoutes(postData.AdvertiseRoutes, postData.AdvertiseExitNode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user