ipn/localapi: add API for uploading client metrics

Clients may have platform-specific metrics they would like uploaded
(e.g. extracted from MetricKit on iOS). Add a new local API endpoint
that allows metrics to be updated by a simple name/value JSON-encoded
struct.

Signed-off-by: Mihai Parparita <mihai@tailscale.com>
This commit is contained in:
Mihai Parparita
2022-07-08 11:57:34 -07:00
committed by Mihai Parparita
parent d6b8a18b09
commit e37167b3ef
2 changed files with 70 additions and 0 deletions

View File

@@ -136,6 +136,15 @@ func Metrics() []*Metric {
return sorted
}
// HasPublished reports whether a metric with the given name has already been
// published.
func HasPublished(name string) bool {
mu.Lock()
defer mu.Unlock()
_, ok := metrics[name]
return ok
}
// NewUnpublished initializes a new Metric without calling Publish on
// it.
func NewUnpublished(name string, typ Type) *Metric {