Documentation ¶
Overview ¶
Package tailscalesd provides Prometheus Service Discovery for Tailscale using a naive, bespoke Tailscale API client supporting both the public v2 and local APIs. It has only the functionality needed for tailscalesd. You should not be tempted to use it for anything else.
Index ¶
Constants ¶
const ( // LabelMetaAPI is the host which provided the details about this device. // Will be "localhost" for the local API. LabelMetaAPI = "__meta_tailscale_api" // LabelMetaDeviceAuthorized is whether the target is currently authorized // on the Tailnet. Will always be true when using the local API. LabelMetaDeviceAuthorized = "__meta_tailscale_device_authorized" // LabelMetaDeviceClientVersion is the Tailscale client version in use on // target. Not reported when using the local API. LabelMetaDeviceClientVersion = "__meta_tailscale_device_client_version" // LabelMetaDeviceHostname is the short hostname of the device. LabelMetaDeviceHostname = "__meta_tailscale_device_hostname" // LabelMetaDeviceID is the target's unique ID within Tailscale, as reported // by the API. The public API reports this as a large integer. The local API // reports a base64 string. // string. LabelMetaDeviceID = "__meta_tailscale_device_id" // LabelMetaDeviceName is the name of the device as reported by the API. Not // reported when using the local API. LabelMetaDeviceName = "__meta_tailscale_device_name" // LabelMetaDeviceOS is the OS of the target. LabelMetaDeviceOS = "__meta_tailscale_device_os" // LabelMetaDeviceTag is a Tailscale ACL tag applied to the target. LabelMetaDeviceTag = "__meta_tailscale_device_tag" // LabelMetaTailnet is the name of the Tailnet from which this target // information was retrieved. Not reported when using the local API. LabelMetaTailnet = "__meta_tailscale_tailnet" )
const LocalAPISocket = "/run/tailscale/tailscaled.sock"
LocalAPISocket is the path to the Unix domain socket on which tailscaled listens locally.
const PublicAPIHost = "api.tailscale.com"
PublicAPIHost host for Tailscale.
Variables ¶
This section is empty.
Functions ¶
func Export ¶
func Export(d Discoverer, with ...TargetFilter) http.Handler
Export the Tailscale Discoverer for Service Discovery via HTTP, optionally applying filters to the discovery results.
Types ¶
type Device ¶ added in v0.2.0
type Device struct { Addresses []string `json:"addresses"` API string `json:"api"` Authorized bool `json:"authorized"` ClientVersion string `json:"clientVersion,omitempty"` Hostname string `json:"hostname"` ID string `json:"id"` Name string `json:"name"` OS string `json:"os"` Tailnet string `json:"tailnet"` Tags []string `json:"tags"` }
Device in a Tailnet, as reported by one of the various Tailscale APIs.
type Discoverer ¶
type Discoverer interface { // Devices reported by the Tailscale public API as belonging to the // configured tailnet. Devices(context.Context) ([]Device, error) }
Discoverer of things exposed by the various Tailscale APIs.
func LocalAPI ¶ added in v0.2.0
func LocalAPI(socket string) Discoverer
LocalAPI Discoverer interrogates the Tailscale localapi for peer devices.
func PublicAPI ¶ added in v0.2.0
func PublicAPI(tailnet, token string, opts ...PublicAPIOption) Discoverer
PublicAPI Discoverer polls the public Tailscale API for hosts in the tailnet.
type MultiDiscoverer ¶ added in v0.2.1
type MultiDiscoverer []Discoverer
MultiDiscoverer aggregates responses from multiple Discoverers.
type PublicAPIOption ¶ added in v0.2.0
type PublicAPIOption func(*publicAPIDiscoverer)
func WithAPIHost ¶ added in v0.2.0
func WithAPIHost(host string) PublicAPIOption
WithAPIHost sets the API base against which the PublicAPI Discoverers will attempt discovery. If not used, defaults to PublicAPIHost.
func WithHTTPClient ¶ added in v0.2.0
func WithHTTPClient(client *http.Client) PublicAPIOption
WithHTTPClient is a PublicAPIOption which allows callers to provide a HTTP client to PublicAPI instances. If not used, the defaultHTTPClient is used.
type RateLimitedDiscoverer ¶ added in v0.2.0
type RateLimitedDiscoverer struct { Wrap Discoverer Frequency time.Duration // contains filtered or unexported fields }
RateLimitedDiscoverer wraps a Discoverer and limits calls to it to be no more frequent than once per Frequency, returning cached values if more frequent calls are made.
type TargetDescriptor ¶
type TargetDescriptor struct { Targets []string `json:"targets"` Labels map[string]string `json:"labels,omitempty"` }
TargetDescriptor as Prometheus expects it. For more details, see https://prometheus.io/docs/prometheus/latest/http_sd/.
func FilterIPv6Addresses ¶ added in v0.2.2
func FilterIPv6Addresses(td TargetDescriptor) TargetDescriptor
FilterIPv6Addresses from TargetDescriptors. Results in only IPv4 targets.
type TargetFilter ¶ added in v0.2.2
type TargetFilter func(TargetDescriptor) TargetDescriptor
TargetFilter maniupulates TargetDescriptors before being served.