preflight

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package preflight runs read-only checks against a PostgreSQL instance to answer: "is this database ready to be a DBGorilla collector source?"

Each check returns a storage-agnostic Result with a severity and, when relevant, copy-pastable fix commands. The check logic is isolated from pgx via the Inspector port; the pgxInspector adapter is the only thing that imports pgx, so the rules are unit-testable against an in-memory fake.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsLib

func ContainsLib(libs, needle string) bool

ContainsLib reports whether a comma-separated preload list contains needle.

func DSNSummary

func DSNSummary(dsn string) string

DSNSummary returns a host/db-only view of a DSN, hiding credentials.

Types

type Inspector

type Inspector interface {
	Summary() string
	ServerVersionNum(ctx context.Context) (string, error)
	ShowParam(ctx context.Context, name string) (string, error)
	HasExtension(ctx context.Context, name string) (bool, error)
	CanReadStats(ctx context.Context) error
	UnreadableUserTables(ctx context.Context) (int, error)
}

Inspector is the port the checks read DB state through.

type Report

type Report struct {
	Results []Result
}

Report aggregates all check results from a run.

func Run

func Run(ctx context.Context, dsn string) Report

Run opens a pgx connection to dsn and runs all checks. A connection failure short-circuits to a single Fail result.

func RunWith

func RunWith(ctx context.Context, ins Inspector) Report

RunWith runs the checks against a given Inspector (for tests / reused conns).

func (Report) Failed

func (r Report) Failed() bool

Failed returns true if any result is a Fail.

func (Report) HasWarnings

func (r Report) HasWarnings() bool

HasWarnings returns true if any result is a Warn.

type Result

type Result struct {
	Name     string
	Severity Severity
	Detail   string
	// Fix, when non-empty, is copy-pastable remediation. Empty on OK.
	Fix []string
}

Result is the outcome of one preflight check.

func CheckExtension

func CheckExtension(ctx context.Context, ins Inspector) Result

CheckExtension requires the pg_stat_statements extension in the current DB.

func CheckServerVersion

func CheckServerVersion(ctx context.Context, ins Inspector) Result

CheckServerVersion requires Postgres 13+.

func CheckSharedPreload

func CheckSharedPreload(ctx context.Context, ins Inspector) Result

CheckSharedPreload requires pg_stat_statements in shared_preload_libraries.

func CheckStatsGrants

func CheckStatsGrants(ctx context.Context, ins Inspector) Result

CheckStatsGrants requires the role to be able to read pg_stat_statements.

func CheckTopologyGrants

func CheckTopologyGrants(ctx context.Context, ins Inspector) Result

CheckTopologyGrants warns if the role cannot read every user table. The topology scrape uses pg_dump, which LOCKs each table IN ACCESS SHARE MODE and reads its definition; without read access the scrape fails and the topology view stays empty (metrics are unaffected). pg_read_all_stats is NOT enough -- it grants stats, not table data.

func CheckTrackFunctions

func CheckTrackFunctions(ctx context.Context, ins Inspector) Result

CheckTrackFunctions warns if track_functions is 'none'.

func CheckTrackIOTiming

func CheckTrackIOTiming(ctx context.Context, ins Inspector) Result

CheckTrackIOTiming warns if track_io_timing is off.

type Severity

type Severity string

Severity classifies a preflight outcome.

const (
	OK   Severity = "ok"
	Warn Severity = "warn"
	Fail Severity = "fail"
)

Jump to

Keyboard shortcuts

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