cliboot

package
v0.0.0-...-dba3308 Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package cliboot owns the cross-binary boot scaffolding shared by the all-in-one duckgres binary, cmd/duckgres-worker, and cmd/duckgres-controlplane. It centralizes build-info reporting, slog/redaction wiring, and OTLP log/trace exporters so production observability stays identical regardless of which entry point runs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitLogging

func InitLogging() func()

InitLogging configures slog to send logs to PostHog via OTLP when POSTHOG_API_KEY is set. Additional PostHog projects can be targeted by setting ADDITIONAL_POSTHOG_API_KEYS to a comma-separated list of API keys. Logs always go to stderr; PostHog is additive. The log level is controlled by DUCKGRES_LOG_LEVEL (debug, info, warn, error). Returns a shutdown function that flushes all OTLP batch processors.

func InitMetrics

func InitMetrics() *http.Server

InitMetrics starts the Prometheus metrics HTTP server on :9090/metrics and returns the *http.Server so callers can shut it down during graceful shutdown / handover. The listener loops on transient errors with a 1s backoff — production duckgres processes have run into ephemeral port rebinds during handover and we don't want metrics scraping to silently die. Workers in --mode duckdb-service intentionally do NOT call this: in K8s all worker pods would fight over :9090 since the control plane owns the metrics endpoint there.

func InitTracing

func InitTracing() func()

InitTracing configures an OTLP trace exporter when OTEL_EXPORTER_OTLP_TRACES_ENDPOINT (or DUCKGRES_TRACE_ENDPOINT) is set. When no endpoint is configured, the global TracerProvider remains the default no-op, adding zero overhead. Returns a shutdown function that flushes the batch span processor.

Types

type BuildInfo

type BuildInfo struct {
	Version string
	Commit  string
	Date    string
}

BuildInfo carries the version/commit/date triple that each binary receives via -ldflags -X main.* at link time. Each package main owns its own var version/commit/date because ldflags can only target package-main symbols; cliboot just reads them via a value-typed struct.

func (*BuildInfo) Enrich

func (b *BuildInfo) Enrich()

Enrich backfills Commit/Date from runtime/debug VCS settings when ldflags did not provide them — useful for local `go run` / `go build` where the linker flags aren't passed. ldflags-supplied values always win; the dirty marker only applies to VCS-backfilled commits because the release pipeline owns ldflags-injected values.

func (BuildInfo) Log

func (b BuildInfo) Log(mode string)

Log emits the canonical startup line tagging the binary's mode and build identity. Call once per process at startup so log readers can correlate behavior to a specific build, especially in K8s where worker pods often inherit the control plane image.

func (BuildInfo) String

func (b BuildInfo) String() string

String renders the human-readable single-line version string used by `--version` / `-v`.

type RedactingHandler

type RedactingHandler struct {
	Inner slog.Handler
}

RedactingHandler wraps an slog.Handler and scrubs password values from log messages and string attributes before forwarding to the inner handler.

func (*RedactingHandler) Enabled

func (h *RedactingHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*RedactingHandler) Handle

func (h *RedactingHandler) Handle(ctx context.Context, r slog.Record) error

func (*RedactingHandler) WithAttrs

func (h *RedactingHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*RedactingHandler) WithGroup

func (h *RedactingHandler) WithGroup(name string) slog.Handler

type StampedHandler

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

StampedHandler emits records as: time, level, pod, node, msg, attrs. slog.TextHandler forces attrs after msg, which pushes pod/node to the end of long lines. Putting them up front makes kubectl-logs triage scannable.

func NewStampedHandler

func NewStampedHandler(out io.Writer, level slog.Level) *StampedHandler

NewStampedHandler returns a handler with pod/node env vars pre-attached, writing to the provided writer. Tests pass a bytes.Buffer; production passes os.Stderr via newStderrStampedHandler.

func (*StampedHandler) Enabled

func (h *StampedHandler) Enabled(_ context.Context, l slog.Level) bool

func (*StampedHandler) Handle

func (h *StampedHandler) Handle(_ context.Context, r slog.Record) error

func (*StampedHandler) WithAttrs

func (h *StampedHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*StampedHandler) WithGroup

func (h *StampedHandler) WithGroup(_ string) slog.Handler

Jump to

Keyboard shortcuts

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