server

package
v4.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package server wires up the HTTP endpoints exposed by the exporter.

Endpoints:

GET /metrics    Prometheus, never 500
GET /healthz    200 if process is alive
GET /readyz     200 once every source has produced its first sync
GET /           landing page

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Build

func Build(opts Options) *http.Server

Build constructs the main *http.Server (everything the chart's /metrics scrape needs). Caller starts and stops it; exporter-toolkit wraps it for TLS / mTLS / basic_auth when webConfiguration is set.

func BuildPprof

func BuildPprof(opts PprofOptions) *http.Server

BuildPprof constructs an isolated *http.Server exposing the standard net/http/pprof routes on its own dedicated ServeMux. Our metrics server (server.Build) uses a separate mux and never serves http.DefaultServeMux, so the pprof endpoints stay confined to this listener even though importing net/http/pprof unavoidably registers the same handlers on DefaultServeMux via its init().

func BuildProbe

func BuildProbe(opts ProbeOptions) *http.Server

BuildProbe constructs a separate *http.Server exposing **only** /healthz and /readyz, plain HTTP — no /metrics, no auth, no TLS. It shares the Readiness latch with the main server, so /readyz reflects the same state.

Run alongside the main server when the chart sets a non-empty `--probe.listen-address`. Default unused — when the flag is empty, the binary falls back to serving probes on the main port (current behaviour).

func Run

func Run(ctx context.Context, srv *http.Server, logger *slog.Logger) error

Run starts srv on its listener and blocks until ctx is cancelled, after which it triggers a graceful shutdown.

func RunPprof

func RunPprof(ctx context.Context, srv *http.Server, logger *slog.Logger)

RunPprof starts srv and blocks until ctx is cancelled. A graceful shutdown with a short timeout is attempted on exit. Logs at INFO when the server starts and stops; reports any non-nominal error.

Types

type Aggregate

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

Aggregate collects readiness signals from N sources. The Reach method returns a function that the source's OnReady callback can call. Once all sources have called success or failure, Mark is invoked.

func NewAggregate

func NewAggregate(r *Readiness, n int) *Aggregate

NewAggregate prepares an Aggregate for n sources.

func (*Aggregate) Reach

func (a *Aggregate) Reach() func(success bool)

Reach returns the per-source callback.

type Options

type Options struct {
	Listen       string
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
	Registry     prometheus.Gatherer
	Readiness    *Readiness
	Logger       *slog.Logger
	EnableStats  bool
	Stats        *registry.Registry
}

Options drives the server.

type PprofOptions

type PprofOptions struct {
	Listen       string
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
}

PprofOptions configure the optional debugging endpoint.

type ProbeOptions

type ProbeOptions struct {
	Listen       string
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
	Readiness    *Readiness
}

ProbeOptions drives the probe-only server. Used when the main server is auth-gated (webConfiguration / kube-rbac-proxy sidecar) and kubelet probes can't reach /healthz on the main port over plain HTTP.

type Readiness

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

Readiness is a simple latch flipped to true when all sources have synced.

func (*Readiness) IsReady

func (r *Readiness) IsReady() bool

IsReady returns the current state.

func (*Readiness) Mark

func (r *Readiness) Mark()

Mark sets the ready flag to true.

func (*Readiness) Reset

func (r *Readiness) Reset()

Reset returns the flag to false (for tests).

Jump to

Keyboard shortcuts

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