Skip to main content

internal/infra/pg/operationalhealth.go

internal/infra/pg · 124 lines · 7 declarations · source

Declarations​

const FormationHealthMaxAge​

const FormationHealthMaxAge = 330 * time.Second

FormationHealthMaxAge allows one five-minute turn attempt plus scheduling overhead. A current heartbeat proves a responsive worker, not inference quality or completion of every scope.

source

type HealthExecutor​

type HealthExecutor interface {
Exec(context.Context, string, ...any) (pgconn.CommandTag, error)
}

source

func RecordFormationHealth​

func RecordFormationHealth(ctx context.Context, db HealthExecutor, schema Schema, formed, failed int64) error

RecordFormationHealth uses the worker's already-held connection when draining a scope. No caller-supplied identifiers or error strings enter this aggregate record.

source

func CheckServingHealth​

func CheckServingHealth(ctx context.Context, memory, registry *pgxpool.Pool, schema Schema, requireFormation bool) error

CheckServingHealth performs bounded-by-caller checks using the actual serving identities. The registry can be nil for a worker, which does not authenticate client requests.

source

type OperationalHealth​

type OperationalHealth struct {
Pending int64 `json:"pending"`
PendingLimit int64 `json:"pending_limit"`
ProjectPendingLimit int64 `json:"project_pending_limit"`
Parked int64 `json:"parked"`
OldestPendingAt *time.Time `json:"oldest_pending_at"`
HeartbeatAt *time.Time `json:"heartbeat_at"`
WorkerResponsive bool `json:"worker_responsive"`
LastProgressAt *time.Time `json:"last_progress_at"`
LastFailureAt *time.Time `json:"last_failure_at"`
FormedCount int64 `json:"formed_count"`
FailedAttempts int64 `json:"failed_attempts"`
DatabaseConnections int64 `json:"database_connections"`
ClusterConnections int64 `json:"cluster_connections"`
MaxConnections int64 `json:"max_connections"`
// ReservedConnections is what the server keeps for superuser recovery. Reported beside
// MaxConnections because an operator comparing demand against capacity who subtracts nothing is
// reading a ceiling that is not there, and finds out at the moment they most need to get in.
ReservedConnections int64 `json:"reserved_connections"`
}

source

method OperationalHealth.ConnectionHeadroom​

func (h OperationalHealth) ConnectionHeadroom() int64

ConnectionHeadroom is how many client sessions could still be opened before the server refuses.

Reported rather than left to be computed, because the deployment-level failure this exists for is exactly the one nobody computes: each process sizes its own pool, the chart chooses how many processes, and the substrate sets the ceiling — and nothing compared the three until a full server made it matter. A negative result is impossible on a live server and is clamped rather than shown, since a number below zero would read as a different kind of fault than "full".

source

func ReadOperationalHealth​

func ReadOperationalHealth(ctx context.Context, pool *pgxpool.Pool, schema Schema) (OperationalHealth, error)

ReadOperationalHealth is for an operator connection, never the unauthenticated HTTP probe. It returns one fixed-size aggregate snapshot without project labels or stored error text.

source