nodesapi

package
v1.10.0-rc4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package nodesapi is the Go client for the pilot-geo-exporter `/nodes` service. The service exposes the registry's online-external-node set as JSON, gated by a shared token, reachable via the IAP tunnel to the rendezvous host.

Use this package from Go services that need to enumerate or filter live nodes — e.g. broadcast targets, onboarding agent's catalog, persona-agent peer discovery, validation harnesses.

Wire shape (HTTP/JSON, stable v1):

GET /nodes              → full external-online node list (token required)
GET /nodes/by_ip?ip=…   → filtered to one IP (token required)
GET /metrics            → Prometheus scrape (no token)
GET /healthz            → liveness probe (no token)

Token auth: pass via ?token=… query param OR X-Token header. This client uses the header by default to keep the token out of access logs.

"External" = NOT in the exporter's INFRA_IPS env var. "Online" = last_seen within ONLINE_THRESHOLD seconds (default 600). The full list may be capped at NODE_INFO_MAX entries server-side; check Response.MetricTruncated.

Index

Constants

View Source
const DefaultBaseURL = "http://127.0.0.1:9117"

DefaultBaseURL is the loopback address used when this client runs ON the rendezvous host (no IAP tunnel needed). Off-host callers should pass the IAP-tunneled local-port URL — typically `http://127.0.0.1:<local>` after `gcloud compute start-iap-tunnel pilot-rendezvous-new 9117`.

View Source
const DefaultTimeout = 30 * time.Second

DefaultTimeout matches a comfortable upper bound on `/nodes` response time at typical fleet sizes (~100k nodes ≈ 30 MB JSON over IAP).

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the minimal HTTP client. Construct with New and reuse — it's safe for concurrent use.

func New

func New(baseURL, token string) *Client

New constructs a Client. Pass an empty baseURL to use DefaultBaseURL. The token is required if the service is configured with NODES_TOKEN.

func (*Client) ByIP

func (c *Client) ByIP(ctx context.Context, ip string) (*Response, error)

ByIP fetches the subset of external-online nodes registered against the given IP. Server-side filter — much smaller payload than List + client-side.

func (*Client) Healthz

func (c *Client) Healthz(ctx context.Context) error

Healthz pings the no-auth liveness endpoint. Returns nil on 200.

func (*Client) List

func (c *Client) List(ctx context.Context) (*Response, error)

List fetches the full external-online node list.

func (*Client) WithHTTP

func (c *Client) WithHTTP(h *http.Client) *Client

WithHTTP swaps in a custom http.Client (e.g. one with a longer timeout). Returns the Client for chaining.

type Node

type Node struct {
	NodeID       uint32  `json:"node_id"`
	IP           string  `json:"ip"`
	Country      string  `json:"country"` // ISO-3166-1 alpha-2; "XX" = unresolved
	Hostname     string  `json:"hostname"`
	Public       bool    `json:"public"`
	RealAddr     string  `json:"real_addr"`
	LastSeen     string  `json:"last_seen"`      // RFC3339, may be empty
	LastSeenUnix float64 `json:"last_seen_unix"` // 0 if missing
	AgeS         *int    `json:"age_s"`          // nil if last_seen missing
}

Node is one entry in Response.Nodes. Field tags match the wire JSON.

func (Node) String

func (n Node) String() string

String returns a compact human-readable summary of one Node, useful for log lines and simple dumps.

type Response

type Response struct {
	UpdatedAt              float64  `json:"updated_at"`
	OnlineThresholdSeconds int      `json:"online_threshold_seconds"`
	InfraIPsExcluded       []string `json:"infra_ips_excluded"`
	MetricCap              int      `json:"metric_cap"`
	MetricTruncated        bool     `json:"metric_truncated"`
	RequireHostnameFilter  bool     `json:"require_hostname_filter"`
	Count                  int      `json:"count"`
	Nodes                  []Node   `json:"nodes"`
}

Response is the envelope returned by /nodes and /nodes/by_ip.

func (*Response) FilterCountry

func (r *Response) FilterCountry(iso string) []Node

FilterCountry returns nodes whose Country matches the given ISO code. Case-insensitive.

func (*Response) FilterHostnamed

func (r *Response) FilterHostnamed() []Node

FilterHostnamed returns only nodes that have a non-empty hostname (i.e. explicitly configured agents, not bare daemons).

func (*Response) FilterPublic

func (r *Response) FilterPublic() []Node

FilterPublic returns only nodes whose Public flag is true.

func (*Response) IDs

func (r *Response) IDs() []uint32

IDs returns just the node IDs from a Response, sorted ascending. Convenience for callers that only care about the ID set.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL