-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Metrics and preliminary multi-API support (#6)
Two somewhat unrelated things in this change: 1. Metrics about the workings of TailscaleSD are now exported at /metrics 2. Introduces a MultiDiscoverer to aggregate results from multiple Discoverers. The MultiDiscoverer feature will be expanded to support multiple tailnets in an upcoming change. It wasn't supposed to be included but I implemented it in the wrong branch and figured, "what the hell?"
- Loading branch information
Showing
9 changed files
with
638 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package tailscalesd | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promauto" | ||
) | ||
|
||
var ( | ||
apiRequestCounter = promauto.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Name: "tailscalesd_tailscale_api_requests", | ||
Help: "Counter of requests made to Tailscale APIs. Labeled with the API host to which requests are made.", | ||
}, | ||
[]string{"api", "host"}) | ||
|
||
apiRequestLatencyHistogram = promauto.NewHistogramVec( | ||
prometheus.HistogramOpts{ | ||
Name: "tailscalesd_tailscale_api_request_latency_ms", | ||
Help: "Histogram of API request latency measured in milliseconds. " + | ||
"Bucketted geometrically.", | ||
Buckets: []float64{1, 2.75, 7.5625, 20.7969, 57.1914, 157.2764, 432.5100, 1189.4025, 3270.8569, 8994.8566}, | ||
}, | ||
[]string{"api", "host"}) | ||
|
||
apiRequestErrorCounter = promauto.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Name: "tailscalesd_tailscale_api_errors", | ||
Help: "Counter of errors during requests to Tailscale APIs. " + | ||
"Denominated by tailscalesd_tailscale_api_requests.", | ||
}, | ||
[]string{"api", "host"}) | ||
|
||
apiPayloadErrorCounter = promauto.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Name: "tailscalesd_tailscale_api_payload_errors", | ||
Help: "Counter of bad payload responses from Tailscale APIs. Denominated by tailscalesd_tailscale_api_requests.", | ||
}, | ||
[]string{"api", "host"}) | ||
|
||
multiDiscovererRequestCounter = promauto.NewCounter( | ||
prometheus.CounterOpts{ | ||
Name: "tailscalesd_tailscale_multi_requests", | ||
Help: "Counter of all requests to a multi-discoverer.", | ||
}) | ||
|
||
multiDiscovererErrorCounter = promauto.NewCounter( | ||
prometheus.CounterOpts{ | ||
Name: "tailscalesd_tailscale_multi_errors", | ||
Help: "Counter of errors during requests to all multi-discoverer. " + | ||
"Denominated by tailscalesd_tailscale_multi_requests.", | ||
}) | ||
|
||
rateLimitedRequests = promauto.NewCounter( | ||
prometheus.CounterOpts{ | ||
Name: "tailscalesd_tailscale_rate_limited_requests", | ||
Help: "Counter of all requests to a rate limited discoverer.", | ||
}) | ||
|
||
rateLimitedRequestRefreshses = promauto.NewCounter( | ||
prometheus.CounterOpts{ | ||
Name: "tailscalesd_tailscale_rate_limited_refreshes", | ||
Help: "Counter of requests to a rate limited discoverer which result in a data refresh.", | ||
}) | ||
|
||
rateLimitedStaleResults = promauto.NewCounter( | ||
prometheus.CounterOpts{ | ||
Name: "tailscalesd_tailscale_rate_limited_stale", | ||
Help: "Counter of requests to a rate limited discoverer which result a return of stale results.", | ||
}) | ||
|
||
tailnetDevicesFoundCounter = promauto.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Name: "tailscalesd_public_api_devices_found", | ||
Help: "Counter of devices found using the public API, labeled with tailnet name.", | ||
}, | ||
[]string{"tailnet"}) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package tailscalesd | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
) | ||
|
||
// MultiDiscoverer aggregates responses from multiple Discoverers. | ||
type MultiDiscoverer []Discoverer | ||
|
||
type discoveryResult struct { | ||
devices []Device | ||
err error | ||
} | ||
|
||
// Devices aggregates the results of calling Devices on each contained | ||
// Discoverer. Returns the first encountered error. | ||
func (md MultiDiscoverer) Devices(ctx context.Context) ([]Device, error) { | ||
multiDiscovererRequestCounter.Inc() | ||
var wg sync.WaitGroup | ||
n := len(md) | ||
results := make([]discoveryResult, n) | ||
wg.Add(n) | ||
for i, d := range md { | ||
go func(d Discoverer, result *discoveryResult) { | ||
defer wg.Done() | ||
result.devices, result.err = d.Devices(ctx) | ||
}(d, &results[i]) | ||
} | ||
wg.Wait() | ||
|
||
var ret []Device | ||
for i := range results { | ||
if err := results[i].err; err != nil { | ||
multiDiscovererErrorCounter.Inc() | ||
return ret, err | ||
} | ||
ret = append(ret, results[i].devices...) | ||
} | ||
return ret, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters