bootstrap

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package bootstrap provides a small bootstrap layer for exporters that want the common exporter-toolkit web flags, logging setup, landing page wiring, and listener startup behavior.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bootstrap

type Bootstrap struct {
	// Logger is the configured logger for the exporter process.
	Logger *slog.Logger
	// MetricsPath is the parsed value of --web.telemetry-path.
	MetricsPath string
	// FlagConfig contains the parsed exporter-toolkit web flags.
	FlagConfig *web.FlagConfig
	// DisableExporterMetrics reports whether exporter self-metrics should be disabled.
	DisableExporterMetrics bool
	// MaxRequests is the parsed value of --web.max-requests.
	MaxRequests int
	// contains filtered or unexported fields
}

Bootstrap captures parsed startup options that handler factories can use to construct exporter-specific HTTP handlers after CLI parsing.

func (*Bootstrap) Handle added in v0.19.0

func (b *Bootstrap) Handle(pattern string, handler http.Handler)

Handle registers an additional handler on the exporter mux. Handlers registered from a MetricsHandlerFactory are served alongside the metrics endpoint and the landing page.

func (*Bootstrap) HandleFunc added in v0.19.0

func (b *Bootstrap) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))

HandleFunc registers an additional handler function on the exporter mux.

type Config

type Config struct {
	// App is the Kingpin application to register flags on. When nil,
	// kingpin.CommandLine is used.
	App *kingpin.Application
	// Name is the exporter name used for version output and startup logging.
	Name string
	// Description is used as the default landing page description.
	Description string
	// DefaultAddress is the default value for --web.listen-address.
	DefaultAddress string
	// Logger is the logger to use. When nil, toolkit configures promslog flags
	// and builds a logger during Parse.
	Logger *slog.Logger
	// LandingConfig customizes the generated landing page.
	LandingConfig web.LandingConfig
	// MetricsHandler is the static handler to register at the metrics path.
	MetricsHandler http.Handler
	// MetricsHandlerFactory builds the metrics handler after flags are parsed.
	MetricsHandlerFactory MetricsHandlerFactory
	// ReadHeaderTimeout bounds request-header reads, mitigating Slowloris
	// (gosec G112). Non-positive values select the one-minute default.
	ReadHeaderTimeout time.Duration
}

Config defines the generic exporter bootstrap inputs.

type MetricsHandlerFactory

type MetricsHandlerFactory func(*Bootstrap) (http.Handler, error)

MetricsHandlerFactory builds an exporter-specific metrics handler after the common toolkit flags have been parsed.

type Runner

type Runner struct {

	// Logger is the resolved logger after parsing configuration.
	Logger *slog.Logger
	// MetricsPath is the parsed value of --web.telemetry-path.
	MetricsPath string
	// FlagConfig contains the parsed exporter-toolkit web flags.
	FlagConfig *web.FlagConfig
	// DisableExporterMetrics is the parsed value of --web.disable-exporter-metrics.
	DisableExporterMetrics bool
	// MaxRequests is the parsed value of --web.max-requests.
	MaxRequests int
	// LandingConfig is the resolved landing page configuration.
	LandingConfig web.LandingConfig
	// MetricsHandler is the configured static metrics handler.
	MetricsHandler http.Handler
	// MetricsHandlerFactory is the configured deferred metrics handler builder.
	MetricsHandlerFactory MetricsHandlerFactory
	// contains filtered or unexported fields
}

Runner manages generic exporter startup around flag parsing, landing page setup, and web listener bootstrapping.

func New

func New(c Config) *Runner

New creates a generic exporter bootstrap instance.

func (*Runner) Run

func (t *Runner) Run() error

Run parses os.Args and starts serving the configured exporter endpoints.

Jump to

Keyboard shortcuts

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