feature/featuretags: make clientmetrics optional

Saves 57 KB

Updates #12614

Change-Id: If7eebec12b3cb30ae6264171d36a258c04b05a70
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2025-10-01 18:34:11 -07:00 committed by Brad Fitzpatrick
parent 127a967207
commit 3ae7a351b4
6 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,13 @@
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
// Code generated by gen.go; DO NOT EDIT.
//go:build ts_omit_clientmetrics
package buildfeatures
// HasClientMetrics is whether the binary was built with support for modular feature "Client metrics support".
// Specifically, it's whether the binary was NOT built with the "ts_omit_clientmetrics" build tag.
// It's a const so it can be used for dead code elimination.
const HasClientMetrics = false

View File

@ -0,0 +1,13 @@
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
// Code generated by gen.go; DO NOT EDIT.
//go:build !ts_omit_clientmetrics
package buildfeatures
// HasClientMetrics is whether the binary was built with support for modular feature "Client metrics support".
// Specifically, it's whether the binary was NOT built with the "ts_omit_clientmetrics" build tag.
// It's a const so it can be used for dead code elimination.
const HasClientMetrics = true

View File

@ -97,6 +97,7 @@ var Features = map[FeatureTag]FeatureMeta{
"cloud": {Sym: "Cloud", Desc: "detect cloud environment to learn instances IPs and DNS servers"}, "cloud": {Sym: "Cloud", Desc: "detect cloud environment to learn instances IPs and DNS servers"},
"cli": {Sym: "CLI", Desc: "embed the CLI into the tailscaled binary"}, "cli": {Sym: "CLI", Desc: "embed the CLI into the tailscaled binary"},
"cliconndiag": {Sym: "CLIConnDiag", Desc: "CLI connection error diagnostics"}, "cliconndiag": {Sym: "CLIConnDiag", Desc: "CLI connection error diagnostics"},
"clientmetrics": {Sym: "ClientMetrics", Desc: "Client metrics support"},
"clientupdate": {Sym: "ClientUpdate", Desc: "Client auto-update support"}, "clientupdate": {Sym: "ClientUpdate", Desc: "Client auto-update support"},
"completion": {Sym: "Completion", Desc: "CLI shell completion"}, "completion": {Sym: "Completion", Desc: "CLI shell completion"},
"dbus": {Sym: "DBus", Desc: "Linux DBus support"}, "dbus": {Sym: "DBus", Desc: "Linux DBus support"},

View File

@ -1218,6 +1218,11 @@ func (h *Handler) serveHandlePushMessage(w http.ResponseWriter, r *http.Request)
} }
func (h *Handler) serveUploadClientMetrics(w http.ResponseWriter, r *http.Request) { func (h *Handler) serveUploadClientMetrics(w http.ResponseWriter, r *http.Request) {
if !buildfeatures.HasClientMetrics {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(struct{}{})
return
}
if r.Method != httpm.POST { if r.Method != httpm.POST {
http.Error(w, "unsupported method", http.StatusMethodNotAllowed) http.Error(w, "unsupported method", http.StatusMethodNotAllowed)
return return

View File

@ -1,6 +1,8 @@
// Copyright (c) Tailscale Inc & AUTHORS // Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause // SPDX-License-Identifier: BSD-3-Clause
//go:build !ts_omit_clientmetrics
// Package clientmetric provides client-side metrics whose values // Package clientmetric provides client-side metrics whose values
// get occasionally logged. // get occasionally logged.
package clientmetric package clientmetric

24
util/clientmetric/omit.go Normal file
View File

@ -0,0 +1,24 @@
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
//go:build ts_omit_clientmetrics
package clientmetric
type Metric struct{}
func (*Metric) Add(int64) {}
func (*Metric) Set(int64) {}
func (*Metric) Value() int64 { return 0 }
func (*Metric) Register(expvarInt any) {}
func (*Metric) UnregisterAll() {}
func HasPublished(string) bool { panic("unreachable") }
func EncodeLogTailMetricsDelta() string { return "" }
func WritePrometheusExpositionFormat(any) {}
var zeroMetric Metric
func NewCounter(string) *Metric { return &zeroMetric }
func NewGauge(string) *Metric { return &zeroMetric }
func NewAggregateCounter(string) *Metric { return &zeroMetric }