Documentation
¶
Overview ¶
Package controlplane holds the state store, the lease-based scheduler and drift monitoring.
Index ¶
- Constants
- Variables
- func AttachChanges(migs []PlanMigration, v *Validation)
- func Detect(migs []PlanMigration, plans []engine.Plan, v Validation, obs Observation) string
- func ExpandDown(plans []engine.Plan, applied []RunMigration) ([]engine.Plan, error)
- func ExpandPlan(p engine.Plan, exp Expansion) (engine.Plan, error)
- func ExpandUp(plans []engine.Plan, exps map[string]Expansion) ([]engine.Plan, error)
- func FilesHash(files map[string]string) string
- func HistoryHash(applied []engine.Applied, reps []engine.Repeatable) string
- func Migrate(ctx context.Context, pool *pgxpool.Pool) (int, error)
- func MigrationsFromFiles(files map[string]string) ([]engine.Migration, error)
- func NewHolder(name string) string
- func ParseSearchPath(value string) (string, error)
- func Pending(migs []engine.Migration, applied []engine.Applied, reps []engine.Repeatable) ([]engine.Migration, error)
- func PlanKey(target, rollout string, pending []engine.Migration) string
- func PlansFromFiles(files map[string]string, dir engine.Direction) ([]engine.Plan, error)
- func Policies() map[string]RolloutPolicy
- func Retired(exps map[string]Expansion) map[string][]RetiredColumn
- func RunEvent(r Run, typ, detail string) notify.Event
- func RunsBody(p engine.Plan, applied AppliedSet) bool
- func SameStatements(a, b []PlanMigration) bool
- func SetGitHubRepositories(config map[string]string, entries []string) error
- func Truncate(plans []engine.Plan, to int64, applied AppliedSet) (keep, withheld []engine.Plan)
- func Unreconciled(obs Observation, applied AppliedSet) []string
- type AppliedSet
- type ApplyRequest
- type AuditEntry
- type Baseliner
- type Checkpoint
- type Checkpointer
- type Config
- type CredentialStore
- type DiffBase
- type Differ
- type Direct
- type Divergence
- type Drift
- type DriftEvent
- type DriftMonitor
- type Engine
- type ExpandContract
- type Expander
- type Expansion
- type Fleet
- type FleetFilter
- type FleetGap
- type FleetMigration
- type FleetOn
- type GitHubRun
- type HistoryChange
- type HistoryMigration
- type HistoryReplayer
- type HistoryRun
- type Inspector
- func (i *Inspector) DataLoss(ctx context.Context, name string, drops []engine.Drop) ([]engine.Loss, error)
- func (i *Inspector) Journal(ctx context.Context, target, migration string) (MigrationJournal, error)
- func (i *Inspector) Observe(ctx context.Context, name string) (Observation, error)
- func (i *Inspector) Status(ctx context.Context, name string) (TargetStatus, error)
- type LedgerEntry
- type MigrationAttempt
- type MigrationJournal
- type MigrationStatement
- type Observation
- type PGEngine
- func (PGEngine) Applied(ctx context.Context, dsn string) ([]engine.Applied, []engine.Repeatable, error)
- func (e PGEngine) Apply(ctx context.Context, req ApplyRequest) error
- func (PGEngine) DataLoss(ctx context.Context, dsn string, drops []engine.Drop) ([]engine.Loss, error)
- func (PGEngine) Journal(ctx context.Context, dsn string, version int64, repeatable string) ([]engine.JournalRun, error)
- func (PGEngine) MarkApplied(ctx context.Context, dsn string, migs []engine.Migration) ([]engine.Migration, error)
- func (PGEngine) Observe(ctx context.Context, dsn string, scope engine.SnapshotScope) (Observation, error)
- func (PGEngine) Snapshot(ctx context.Context, dsn string, scope engine.SnapshotScope) (engine.Schema, error)
- type Plan
- type PlanAssert
- type PlanBatch
- type PlanDiff
- type PlanHazard
- type PlanMigration
- type PlanRequired
- type PlanStale
- type PlanStatement
- type Pool
- type Provenance
- type Reconciler
- type Recorder
- type RetiredColumn
- type RevertPlan
- type RolloutPolicy
- type Run
- type RunMigration
- type RunProgress
- type Scheduler
- type SchemaDiff
- type Scratch
- type ScratchFinding
- type Snapshot
- type Store
- func (s *Store) AdoptApplied(ctx context.Context, runID, migration string) (bool, error)
- func (s *Store) Applied(ctx context.Context, target string) (AppliedSet, error)
- func (s *Store) AppliedMigrations(ctx context.Context, runID string) ([]RunMigration, error)
- func (s *Store) Audit(ctx context.Context, e AuditEntry) error
- func (s *Store) AwaitingContract(ctx context.Context, target string) (Run, bool, error)
- func (s *Store) BindPlan(ctx context.Context, id, runID string) error
- func (s *Store) BoundPlan(ctx context.Context, target, rollout, filesHash string) (Plan, error)
- func (s *Store) CarriedBy(ctx context.Context, target, migration string) (LedgerEntry, error)
- func (s *Store) Checkpoints(ctx context.Context, target string) ([]engine.Migration, error)
- func (s *Store) Claim(ctx context.Context, holder string, ttl time.Duration) (Run, bool, error)
- func (s *Store) ClaimGitHubReports(ctx context.Context, lease time.Duration, limit int) ([]GitHubRun, error)
- func (s *Store) Confirm(ctx context.Context, id string) (Run, error)
- func (s *Store) CreateAdoption(ctx context.Context, id, target, kind string, migs []engine.Migration, ...) error
- func (s *Store) CreateRevert(ctx context.Context, id string, orig Run, force bool, t Timeouts, p Provenance) error
- func (s *Store) CreateRun(ctx context.Context, id, target, rollout string, files map[string]string, ...) error
- func (s *Store) Finish(ctx context.Context, id, state, errText string) error
- func (s *Store) FleetMigrations(ctx context.Context, f FleetFilter) (Fleet, error)
- func (s *Store) GetTS(ctx context.Context, kind, key string) (string, string, error)
- func (s *Store) GitHubBindings(ctx context.Context) (map[string]string, error)
- func (s *Store) GitHubRunsOf(ctx context.Context, repository string, pull int, target string) ([]GitHubRun, error)
- func (s *Store) Heartbeat(ctx context.Context, runID, holder string, ttl time.Duration) error
- func (s *Store) History(ctx context.Context, target string) ([]HistoryRun, error)
- func (s *Store) LastRun(ctx context.Context, target string) (r Run, ok bool, err error)
- func (s *Store) ListAudit(ctx context.Context, target, runID string, limit int) ([]AuditEntry, error)
- func (s *Store) ListCredentialStores(ctx context.Context) ([]CredentialStore, error)
- func (s *Store) ListDriftEvents(ctx context.Context, target string) ([]DriftEvent, error)
- func (s *Store) ListPlans(ctx context.Context, target string, limit int) ([]Plan, error)
- func (s *Store) ListRuns(ctx context.Context, target string) ([]Run, error)
- func (s *Store) ListTargets(ctx context.Context, since time.Time) ([]TargetSummary, error)
- func (s *Store) LockTarget(ctx context.Context, name string) (string, map[string]string, error)
- func (s *Store) MarkGitHubReported(ctx context.Context, runID, state string) error
- func (s *Store) MarkReverted(ctx context.Context, origID, revertID, migration string) error
- func (s *Store) Newer(ctx context.Context, orig Run) (bool, error)
- func (s *Store) OpenDrift(ctx context.Context, target string) (bool, error)
- func (s *Store) Ping(ctx context.Context) error
- func (s *Store) Plan(ctx context.Context, id string) (Plan, error)
- func (s *Store) PlanFiles(ctx context.Context, id string) (map[string]string, error)
- func (s *Store) PlanRevert(ctx context.Context, id string) (RevertPlan, error)
- func (s *Store) PutTS(ctx context.Context, kind, key, channel, ts string) error
- func (s *Store) ReadyPlan(ctx context.Context, target, key string, since time.Time) (Plan, error)
- func (s *Store) ReadyPlanCount(ctx context.Context, target string, since time.Time) (int, error)
- func (s *Store) RecordApplied(ctx context.Context, runID, migration string, held bool, exp *Expansion) error
- func (s *Store) RecordDelivery(ctx context.Context, id, event, repository string) (bool, error)
- func (s *Store) RecordDrift(ctx context.Context, target, baseline, diff string) (bool, error)
- func (s *Store) RecordGitHubRun(ctx context.Context, g GitHubRun) error
- func (s *Store) RegisterCredentialStore(ctx context.Context, cs CredentialStore) error
- func (s *Store) RegisterTarget(ctx context.Context, name, provider string, config map[string]string) error
- func (s *Store) ResolveDrift(ctx context.Context, target string) (bool, error)
- func (s *Store) Resume(ctx context.Context, id string) (Run, error)
- func (s *Store) RetireColumns(ctx context.Context, target, runID, migration string, cols []RetiredColumn) error
- func (s *Store) RetirePlan(ctx context.Context, id string) error
- func (s *Store) RetiredColumns(ctx context.Context, target string) ([]RetiredColumn, error)
- func (s *Store) Retry(ctx context.Context, id, errText string, wait time.Duration) error
- func (s *Store) RevertTarget(ctx context.Context, target string) (Run, error)
- func (s *Store) Run(ctx context.Context, id string) (Run, error)
- func (s *Store) RunFiles(ctx context.Context, id string) (map[string]string, error)
- func (s *Store) RunStats(ctx context.Context) ([]metrics.RunStat, error)
- func (s *Store) RunsApplying(ctx context.Context, target string, since time.Time) (map[string]string, error)
- func (s *Store) SavePlan(ctx context.Context, p Plan, files map[string]string) error
- func (s *Store) SaveProgress(ctx context.Context, id string, p RunProgress) error
- func (s *Store) SaveSnapshot(ctx context.Context, target, fingerprint, definition, runID string) error
- func (s *Store) SelectVersion(ctx context.Context, target string, plans []engine.Plan, to int64) (keep, withheld []engine.Plan, err error)
- func (s *Store) SnapshotFor(ctx context.Context, target string) (Snapshot, error)
- func (s *Store) SnapshotTargets(ctx context.Context) ([]string, error)
- func (s *Store) SupersedePlan(ctx context.Context, id string, next Plan, files map[string]string) error
- func (s *Store) SweepDeliveries(ctx context.Context, before time.Time) (int64, error)
- func (s *Store) SweepGitHubRuns(ctx context.Context, before time.Time) (int64, error)
- func (s *Store) SweepPlans(ctx context.Context, olderThan time.Time) (int64, error)
- func (s *Store) Target(ctx context.Context, name string) (string, map[string]string, error)
- func (s *Store) Transact(ctx context.Context, fn func(tx *Store) error) error
- func (s *Store) UnretireColumns(ctx context.Context, target string, cols []RetiredColumn) error
- func (s *Store) VaultStore(ctx context.Context, name string) (creds.VaultStore, error)
- type TargetRegistration
- type TargetStatus
- type TargetSummary
- type Timeouts
- type Validation
- type Validator
Constants ¶
const ( AuditTargetRegister = "target.register" AuditTargetBaseline = "target.baseline" AuditTargetReconcile = "target.reconcile" AuditRunCreate = "run.create" AuditRunRevert = "run.revert" AuditRunResume = "run.resume" AuditRunPark = "run.park" AuditRunConfirm = "run.confirm" AuditDriftAccept = "drift.accept" AuditPlanCreate = "plan.create" AuditPlanSupersede = "plan.supersede" AuditRunReattach = "run.reattach" AuditCheckpoint = "checkpoint.generate" AuditWebhookCommand = "webhook.command" AuditCredentialStore = "credential_store.register" )
Audit actions.
const ( OutcomeDone = "done" OutcomeFailed = "failed" OutcomeInFlight = "in flight" OutcomeNotReached = "not reached" )
Outcomes a journalled statement is reported under.
const ( PlanReady = "ready" PlanBound = "bound" PlanSuperseded = "superseded" )
Plan states.
const ( StaleHistory = "history" StaleSchema = "schema" StaleOrder = "order" StaleValidation = "validation" StaleContent = "content" )
Stale reasons carried by PlanStale.
const ( RolloutDirect = "direct" RolloutExpandContract = "expand-contract" )
Rollout policy names.
const ( ReasonNetwork = "network" ReasonTimeout = "timeout" )
Failure classes reported in notifications and metrics.
const ( DefaultMaxConcurrentRuns = 4 DefaultRunTimeout = 24 * time.Hour )
Scheduler defaults: a long backfill on one target must not park the others, and no run may hold a slot forever.
const ( StateQueued = "queued" StateRunning = "running" StateSucceeded = "succeeded" StateFailed = "failed" StateNeedsAttention = "needs_attention" StateAwaitingContract = "awaiting_contract" StateReverted = "reverted" )
Run states.
const ( PhaseExpand = "expand" PhaseContract = "contract" )
Run phases.
const ( KindMigrate = "migrate" KindBaseline = "baseline" KindReconcile = "reconcile" )
Run kinds.
const ( ConfigLockTimeout = "lock_timeout" ConfigStatementTimeout = "statement_timeout" ConfigRequirePlan = "require_plan" ConfigKeepOld = "keep_old" ConfigIgnoreAdopted = "ignore_adopted_tables" )
Target config keys holding the per-target timeouts, the plan requirement and the change-type default.
const ConfigSearchPath = "search_path"
ConfigSearchPath is the target config key holding the per-target search_path.
const DefaultBatchSize = 5000
DefaultBatchSize is how many rows a generated backfill touches per transaction when the directive is silent.
const DefaultScratchTemplate = "template0"
DefaultScratchTemplate is template0: template1 may carry an extension a non-superuser scratch role cannot add itself.
const DriftHistoryLimit = 100
DriftHistoryLimit is how many events one ListDriftEvents call returns; a caller holding that many is looking at a window, not at the history.
const JournalSchema = "godwit"
JournalSchema is where godwit's journal lives on every target, whatever the search_path is.
const MaxPageSize = 1000
MaxPageSize is the ceiling every listing clamps its caller's limit to, so one call cannot materialise a whole table.
Variables ¶
var ( ErrNotFound = errors.New("not found") ErrLeaseLost = errors.New("lease lost") ErrNotResumable = errors.New("run is not failed or parked") ErrNotAwaitingContract = errors.New("run is not awaiting contract") ErrNotRevertable = errors.New("run is not revertable") ErrBaselineRun = errors.New("baseline runs cannot be reverted") )
Sentinel errors.
var ( // ErrNoSuchVersion marks a version target that names no migration in the submitted set. ErrNoSuchVersion = errors.New("no migration in this set has version") // ErrVersionTarget marks a version target the target's own history will not honour. ErrVersionTarget = errors.New("version target") )
var ErrAppliedContent = errors.New("applied with different content")
ErrAppliedContent marks a file whose version is applied on the target with a different checksum.
var ErrBaselineFormat = errors.New("drift baseline predates the schema format")
ErrBaselineFormat marks a baseline taken before godwit changed what a schema snapshot describes.
var ErrCheckpoint = errors.New("checkpoint")
ErrCheckpoint marks a checkpoint godwit refuses to generate.
var ErrDesiredSchema = errors.New("desired schema failed to apply")
ErrDesiredSchema marks a desired schema the author must fix.
var ErrDirective = errors.New("godwit directive")
ErrDirective marks a directive godwit will not expand; the API reports it as invalid_argument.
var ErrDiverged = errors.New("target and ledger disagree")
ErrDiverged marks a target whose journal and the ledger cannot be reconciled without a decision only a person can take.
var ErrJournalOnSearchPath = errors.New("the target's search_path reaches godwit's journal schema")
ErrJournalOnSearchPath marks a target whose sessions resolve unqualified names against the journal schema.
var ErrMigrationFiles = errors.New("migration files failed to replay")
ErrMigrationFiles marks committed migration files that do not replay on top of the target's history.
var ErrRepeatableSchema = errors.New("repeatable migration does not build on the desired schema")
ErrRepeatableSchema marks a repeatable migration that does not build on the desired schema.
var ErrRepeatablesUnknown = errors.New("target records repeatable migrations and the request carried no migration files")
ErrRepeatablesUnknown marks a diff whose request carried no migration files while the target records repeatable migrations.
var ErrRevertPlan = errors.New("revert plan")
ErrRevertPlan marks a revert whose down side cannot be built from what the run applied.
var ErrScratchPrivileged = errors.New("scratch role can act outside its own scratch databases")
ErrScratchPrivileged marks a scratch connection whose role can act outside its own scratch databases.
var ErrValidationDisabled = errors.New("diffing against the committed files needs validation, which is disabled on this service")
ErrValidationDisabled marks a diff against the committed files on a service started with validation off.
var ErrValidationFailed = errors.New("migration failed validation")
ErrValidationFailed marks a migration the author must fix.
Functions ¶
func AttachChanges ¶
func AttachChanges(migs []PlanMigration, v *Validation)
AttachChanges puts what the scratch replay saw each migration do to the schema on the migration itself.
func Detect ¶
func Detect(migs []PlanMigration, plans []engine.Plan, v Validation, obs Observation) string
Detect marks the longest prefix of migs whose effect the target already holds; otherwise returns the drift.
func ExpandDown ¶
ExpandDown substitutes each migration's own frozen inverse from the ledger; a hand-written .down.sql has no expansion and wins untouched.
func ExpandPlan ¶
ExpandPlan rebuilds a plan from its frozen expansion; the migration keeps the checksum of the file, not of what godwit generated from it.
func ExpandUp ¶
ExpandUp replaces each directive migration's body with the expansion frozen on the plan or the run.
func FilesHash ¶
FilesHash identifies a set of submitted files independent of what is pending; the retry migration computes the same value in SQL.
func HistoryHash ¶
func HistoryHash(applied []engine.Applied, reps []engine.Repeatable) string
HistoryHash hashes an applied set as "id checksum" lines, versions ascending then repeatables by name.
func Migrate ¶
Migrate applies the control-plane schema and reports how many migrations ran; the advisory lock needs a dedicated session.
func MigrationsFromFiles ¶
MigrationsFromFiles loads migrations from in-memory files named like on disk.
func NewHolder ¶
NewHolder builds this process's lease identity, "<name>/<random>": a name alone collides across processes on one machine.
func ParseSearchPath ¶
ParseSearchPath validates a comma-separated list of unquoted schema names and folds it the way PostgreSQL does.
func Pending ¶
func Pending(migs []engine.Migration, applied []engine.Applied, reps []engine.Repeatable) ([]engine.Migration, error)
Pending returns the migrations the target would run: versions it has not applied, plus repeatables whose content differs.
func PlanKey ¶
PlanKey identifies a pending set on a target: the files and what the target has applied, nothing else.
func PlansFromFiles ¶
PlansFromFiles loads migration files and plans one direction; down plans come newest first.
func Policies ¶
func Policies() map[string]RolloutPolicy
Policies returns the built-in rollout policies.
func Retired ¶
func Retired(exps map[string]Expansion) map[string][]RetiredColumn
Retired lists every column the expansions of one run leave behind, keyed by migration.
func RunsBody ¶
func RunsBody(p engine.Plan, applied AppliedSet) bool
RunsBody reports whether the executor would run the plan's statements; a down plan runs because the target holds it.
func SameStatements ¶
func SameStatements(a, b []PlanMigration) bool
SameStatements reports whether two plans would run the same statements with the same hazards and phases.
func SetGitHubRepositories ¶
SetGitHubRepositories records the repositories a GitHub App delivery may reach this target from; an empty list clears them.
func Truncate ¶
Truncate splits plans at a version target: versioned migrations at or below to, plus the repeatables only when nothing versioned is held back, since a repeatable declares what the whole directory produces.
func Unreconciled ¶
func Unreconciled(obs Observation, applied AppliedSet) []string
Unreconciled names the migrations a target's journal records that no standing ledger row accounts for; an observation with no history reports none.
Types ¶
type AppliedSet ¶
AppliedSet is what a target already holds: versions the control plane ran and the content it recorded per repeatable.
func (AppliedSet) Has ¶
func (a AppliedSet) Has(m engine.Migration) bool
Has reports whether the target already holds m: the version, or the repeatable under that content.
func (AppliedSet) Newest ¶
func (a AppliedSet) Newest() int64
Newest is the highest version the target has applied, or zero when it has none.
type ApplyRequest ¶
type ApplyRequest struct {
RunID string
Target string
DSN string
Plans []engine.Plan
Opts engine.Options
Progress func(engine.StatementEvent)
Record Recorder
}
ApplyRequest is one run's worth of plans plus the effective execution options.
type AuditEntry ¶
type AuditEntry struct {
ID int64
At time.Time
Actor string
Action string
RunID string
Target string
Detail string
}
AuditEntry is one recorded mutation: who did what to which target or run.
type Baseliner ¶
type Baseliner struct {
// contains filtered or unexported fields
}
Baseliner marks migrations applied on a target without running them and records that as a succeeded run.
func NewBaseliner ¶
NewBaseliner shares the scheduler's store, credential providers and engine.
type Checkpoint ¶
Checkpoint is a generated checkpoint file: the schema a prefix of the migration directory produces.
func (Checkpoint) UpFile ¶
func (c Checkpoint) UpFile() string
UpFile is the name the checkpoint is written under.
type Checkpointer ¶
type Checkpointer struct {
Expander *Expander
// contains filtered or unexported fields
}
Checkpointer generates a checkpoint by replaying the files on a scratch database and rendering the schema they left as DDL.
func NewCheckpointer ¶
func NewCheckpointer(scratch *Scratch, newID func() string) *Checkpointer
NewCheckpointer wires a Checkpointer over the scratch connection.
func (*Checkpointer) Generate ¶
func (c *Checkpointer) Generate(ctx context.Context, files map[string]string, at int64, name string, now time.Time) (Checkpoint, error)
Generate collapses every version of files at or below at (zero takes the newest) into one checkpoint named name, and refuses unless replaying its DDL alone reproduces the same fingerprint.
type Config ¶
type Config struct {
Holder string
TTL time.Duration
Interval time.Duration
MaxAttempts int
MaxConcurrentRuns int
RunTimeout time.Duration
Jitter func() float64
}
Config tunes a Scheduler.
type CredentialStore ¶
type CredentialStore struct {
Name string
Address string
Role string
Mount string
TokenEnv string
Targets int
}
CredentialStore is a registered Vault a target's secret can be read from.
type Differ ¶
type Differ struct {
// contains filtered or unexported fields
}
Differ generates the migration between a target's live schema and a desired DDL applied on a scratch database.
type Divergence ¶
Divergence is how a target's journal and the control plane's ledger differ; Adopt is repairable, everything else is not.
func Diverged ¶
func Diverged(obs Observation, applied AppliedSet, migs []engine.Migration) Divergence
Diverged compares a target's journal with the ledger, reading the content of each migration from migs.
func (Divergence) Err ¶
func (d Divergence) Err(target string) error
Err reports what a reconcile cannot decide on its own, or nil.
type DriftEvent ¶
type DriftEvent struct {
ID int64
Target string
Diff string
DetectedAt time.Time
ResolvedAt *time.Time
}
DriftEvent is one detected divergence between expected and live schema.
type DriftMonitor ¶
type DriftMonitor struct {
Metrics *metrics.Metrics
PlanRetention time.Duration
DeliveryRetention time.Duration
// contains filtered or unexported fields
}
DriftMonitor periodically compares live schemas against their baselines.
func NewDriftMonitor ¶
func NewDriftMonitor(store *Store, sched *Scheduler, eng Engine, notifier notify.Notifier, interval time.Duration, log *slog.Logger) *DriftMonitor
NewDriftMonitor wires a DriftMonitor; interval <= 0 defaults to 5 minutes.
func (*DriftMonitor) AcceptBaseline ¶
func (m *DriftMonitor) AcceptBaseline(ctx context.Context, target string) error
AcceptBaseline records the live schema as the expected state and resolves open drift.
func (*DriftMonitor) Run ¶
func (m *DriftMonitor) Run(ctx context.Context)
Run checks all targets on every interval until ctx is done.
func (*DriftMonitor) Tick ¶
func (m *DriftMonitor) Tick(ctx context.Context)
Tick checks every baselined target once and sweeps plans and webhook deliveries past retention.
type Engine ¶
type Engine interface {
Apply(ctx context.Context, req ApplyRequest) error
MarkApplied(ctx context.Context, dsn string, migs []engine.Migration) ([]engine.Migration, error)
Snapshot(ctx context.Context, dsn string, scope engine.SnapshotScope) (engine.Schema, error)
Applied(ctx context.Context, dsn string) ([]engine.Applied, []engine.Repeatable, error)
Journal(ctx context.Context, dsn string, version int64, repeatable string) ([]engine.JournalRun, error)
Observe(ctx context.Context, dsn string, scope engine.SnapshotScope) (Observation, error)
DataLoss(ctx context.Context, dsn string, drops []engine.Drop) ([]engine.Loss, error)
}
Engine applies plans to a target database, marks migrations applied and inspects its schema and journal.
type ExpandContract ¶
type ExpandContract struct{}
ExpandContract holds the first destructive migration and everything after it.
type Expander ¶
Expander turns directives into statements using a catalog that already holds the target's history.
func NewExpander ¶
func NewExpander() *Expander
NewExpander returns an Expander with godwit's defaults.
type Expansion ¶
type Expansion struct {
ID string `json:"id"`
UpSQL string `json:"up_sql"`
DownSQL string `json:"down_sql"`
DownHeld string `json:"down_held_sql,omitempty"`
Phase []string `json:"phase"`
Batches []*engine.BatchSpec `json:"batches,omitempty"`
Asserts []*engine.AssertSpec `json:"asserts,omitempty"`
Notes []string `json:"notes,omitempty"`
Retired []RetiredColumn `json:"retired,omitempty"`
Unretired []RetiredColumn `json:"unretired,omitempty"`
Lines []string `json:"lines,omitempty"`
Hash string `json:"hash"`
}
Expansion is the SQL godwit generates for one migration's directives, frozen into the plan so the run applies what the pull request showed.
type Fleet ¶
type Fleet struct {
Targets []string
Migrations []FleetMigration
}
Fleet is the cross-target answer to "which of my databases has this migration".
type FleetFilter ¶
type FleetFilter struct {
Targets []string
FromVersion int64
ToVersion int64
NotEverywhere bool
In string
NotIn string
}
FleetFilter narrows the fleet view; a zero filter answers over every registered target.
type FleetGap ¶
type FleetGap struct {
Target string
NewestVersion int64
Behind bool
Holds bool
OtherChecksum string
}
FleetGap is a target the entry does not stand on, with what separates it from the ones that do.
type FleetMigration ¶
type FleetMigration struct {
Migration string
Version int64
Name string
Repeatable bool
Checkpoint bool
Checksum string
On []FleetOn
Missing []FleetGap
Divergent bool
}
FleetMigration is one migration as one content: a version standing under two checksums is two entries.
type GitHubRun ¶
type GitHubRun struct {
RunID string
Repository string
RepositoryID int64
Installation int64
PullRequest int
Head string
Command string
Target string
Marker string
Format string
CheckRun int64
State string
Reverts string
}
GitHubRun binds a run to the pull request whose command created it, so a replica that did not accept that command can still report it back.
type HistoryChange ¶
HistoryChange is one migration that entered or left the target's history since a plan was taken.
func (HistoryChange) String ¶
func (c HistoryChange) String() string
String renders the change as it appears in a stale report.
type HistoryMigration ¶
HistoryMigration is one standing ledger row: the pair the run carried for it and the expansion it froze.
type HistoryReplayer ¶
type HistoryReplayer interface {
Validate(ctx context.Context, target string, plans []engine.Plan, searchPath string) (Validation, error)
Replay(ctx context.Context, conn engine.DB, target, searchPath string, plans []engine.Plan) error
}
HistoryReplayer rebuilds a target's recorded history on a scratch database (implemented by Validator).
type HistoryRun ¶
type HistoryRun struct {
Migrations []HistoryMigration
}
HistoryRun is one run's contribution to a target's history: the migrations it applied that still stand, in the order it applied them.
type Inspector ¶
type Inspector struct {
// contains filtered or unexported fields
}
Inspector reads a target's applied versions, last run and drift baseline without changing anything.
func NewInspector ¶
NewInspector shares the scheduler's store, credential providers and engine.
func (*Inspector) DataLoss ¶
func (i *Inspector) DataLoss(ctx context.Context, name string, drops []engine.Drop) ([]engine.Loss, error)
DataLoss reports which of the drops would destroy data the target still holds.
func (*Inspector) Journal ¶
func (i *Inspector) Journal(ctx context.Context, target, migration string) (MigrationJournal, error)
Journal reads one migration's statement journal off the target and joins it to the SQL the applying run stored.
type LedgerEntry ¶
type LedgerEntry struct {
RunID string
AppliedAt time.Time
Applied bool
Adopted bool
Expansion *Expansion
UpSQL string
DownSQL string
}
LedgerEntry is what the control plane holds about one migration on one target, with the file bodies of the run that carried it.
type MigrationAttempt ¶
type MigrationAttempt struct {
engine.JournalRun
Statements []MigrationStatement
}
MigrationAttempt is one godwit.runs row on the target with its statements.
type MigrationJournal ¶
type MigrationJournal struct {
Target string
Migration string
Attempts []MigrationAttempt
RunID string
AppliedAt time.Time
Adopted bool
RecordedOnly bool
Unreachable string
BodiesSwept bool
}
MigrationJournal is what one target recorded about one migration, from its own journal and the control plane's ledger.
type MigrationStatement ¶
type MigrationStatement struct {
engine.JournalStatement
SQL string
NoTx bool
Verifier string
Outcome string
}
MigrationStatement is one statement of an attempt: what the target journalled, and the SQL the run executed.
type Observation ¶
type Observation struct {
Applied []engine.Applied
Repeatables []engine.Repeatable
Definition string
Fingerprint string
SearchPath string
At time.Time
Ignored []engine.Adopted
}
Observation is a target's live migration history and schema at one moment.
func (Observation) HistoryHash ¶
func (o Observation) HistoryHash() string
HistoryHash hashes the observed history, ascending by version then by repeatable name.
type PGEngine ¶
PGEngine is the PostgreSQL Engine; Metrics and Log are optional.
func (PGEngine) Applied ¶
func (PGEngine) Applied(ctx context.Context, dsn string) ([]engine.Applied, []engine.Repeatable, error)
Applied implements Engine.
func (PGEngine) Apply ¶
func (e PGEngine) Apply(ctx context.Context, req ApplyRequest) error
Apply implements Engine.
func (PGEngine) DataLoss ¶
func (PGEngine) DataLoss(ctx context.Context, dsn string, drops []engine.Drop) ([]engine.Loss, error)
DataLoss implements Engine.
func (PGEngine) Journal ¶
func (PGEngine) Journal(ctx context.Context, dsn string, version int64, repeatable string) ([]engine.JournalRun, error)
Journal implements Engine.
func (PGEngine) MarkApplied ¶
func (PGEngine) MarkApplied(ctx context.Context, dsn string, migs []engine.Migration) ([]engine.Migration, error)
MarkApplied implements Engine.
func (PGEngine) Observe ¶
func (PGEngine) Observe(ctx context.Context, dsn string, scope engine.SnapshotScope) (Observation, error)
Observe implements Engine: history and schema read over one connection.
type Plan ¶
type Plan struct {
ID string
Target string
Key string
Rollout string
State string
HistoryHash string
Applied []engine.Applied
Repeatables []engine.Repeatable
SchemaFingerprint string
SchemaDefinition string
SearchPath string
Drift string
Migrations []PlanMigration
Validated bool
Acked []string
AllowOutOfOrder bool
CreatedBy string
Source string
CreatedAt time.Time
RunID string
SupersededBy string
Expansions map[string]Expansion
}
Plan is a stored admission result plus the observation it was taken against.
func (Plan) PathMoved ¶
func (p Plan) PathMoved(obs Observation) bool
PathMoved reports whether the target's effective search_path changed since the plan was taken; one stored before the path was recorded never moved.
func (Plan) Pending ¶
func (p Plan) Pending() []PlanMigration
Pending returns the migrations the plan would run; one a version target withheld is not among them.
type PlanAssert ¶
type PlanAssert struct {
Op string `json:"op"`
Kind string `json:"kind"`
Value string `json:"value"`
}
PlanAssert is the condition an assert statement states about the value its query returns.
type PlanBatch ¶
type PlanBatch struct {
Key string `json:"key"`
Kind string `json:"kind"`
Size int `json:"size"`
Pause string `json:"pause,omitempty"`
}
PlanBatch describes a statement the executor runs as a resumable loop instead of once.
type PlanDiff ¶
type PlanDiff struct {
Added []HistoryChange
Removed []HistoryChange
Schema []string
Path string
}
PlanDiff is how a target moved away from a plan's observation.
func StaleDiff ¶
func StaleDiff(p Plan, obs Observation) PlanDiff
StaleDiff compares a plan's observation with a fresh one; a repeatable recorded under new content counts as removed and added.
type PlanHazard ¶
type PlanHazard struct {
Code string `json:"code"`
Detail string `json:"detail"`
Recipe string `json:"recipe,omitempty"`
Object string `json:"object,omitempty"`
Attribute string `json:"attribute,omitempty"`
}
PlanHazard is one hazard on a planned statement.
type PlanMigration ¶
type PlanMigration struct {
Version int64 `json:"version"`
Name string `json:"name"`
Repeatable bool `json:"repeatable,omitempty"`
Checksum string `json:"checksum"`
Applied bool `json:"applied"`
Phase string `json:"phase"`
Statements []PlanStatement `json:"statements"`
AlreadyApplied bool `json:"already_applied,omitempty"`
Effect string `json:"effect,omitempty"`
Note string `json:"note,omitempty"`
Withheld bool `json:"withheld,omitempty"`
Changes []engine.ObjectChange `json:"changes,omitempty"`
// Stored inverted: a plan written before the field existed keeps counting every hazard rather than none.
Skipped bool `json:"skipped,omitempty"`
Checkpoint bool `json:"checkpoint,omitempty"`
Through int64 `json:"collapses_through,omitempty"`
Directives []string `json:"directives,omitempty"`
Expanded bool `json:"expanded,omitempty"`
Notes []string `json:"notes,omitempty"`
Expansion string `json:"expansion,omitempty"`
}
PlanMigration is one migration of a stored plan with its phase and applied flag.
func BuildPlanMigrations ¶
func BuildPlanMigrations(rollout string, plans []engine.Plan, applied AppliedSet, exps map[string]Expansion) []PlanMigration
BuildPlanMigrations records what admission decided for each plan: phase under the rollout and whether it is applied.
func WithheldMigrations ¶
func WithheldMigrations(plans []engine.Plan, applied AppliedSet) []PlanMigration
WithheldMigrations reports what a version target kept out of the run, so a plan says what it is not doing.
func (PlanMigration) ID ¶
func (m PlanMigration) ID() string
ID identifies the migration in plan keys and reports.
type PlanRequired ¶
PlanRequired is returned when a target demands a stored plan and none matches the migration set.
func (*PlanRequired) Error ¶
func (e *PlanRequired) Error() string
Error renders the report with the nearest stored plans next to this set.
func (*PlanRequired) FilesDiff ¶
func (e *PlanRequired) FilesDiff() string
FilesDiff renders this set against each nearest plan, one line per plan.
type PlanStale ¶
PlanStale is returned when a stored plan no longer matches the target it was taken against.
type PlanStatement ¶
type PlanStatement struct {
SQL string `json:"sql"`
NoTx bool `json:"no_tx,omitempty"`
Phase string `json:"phase,omitempty"`
Batch *PlanBatch `json:"batch,omitempty"`
Assert *PlanAssert `json:"assert,omitempty"`
Hazards []PlanHazard `json:"hazards,omitempty"`
}
PlanStatement is one classified statement of a stored plan.
func PlanStatements ¶
func PlanStatements(sts []engine.Statement) []PlanStatement
PlanStatements keeps the SQL, transaction mode and hazards of classified statements.
type Pool ¶
type Pool interface {
Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
Begin(ctx context.Context) (pgx.Tx, error)
}
Pool is the connection-pool surface the store needs; *pgxpool.Pool and pgx.Tx satisfy it.
type Provenance ¶
Provenance records who created a run and where its files came from.
type Reconciler ¶
type Reconciler struct {
// contains filtered or unexported fields
}
Reconciler repairs the control plane's ledger from a target's own journal. It never writes to the target.
func NewReconciler ¶
func NewReconciler(sched *Scheduler) *Reconciler
NewReconciler shares the scheduler's store, credential providers and engine.
func (*Reconciler) Reconcile ¶
func (r *Reconciler) Reconcile(ctx context.Context, runID, target string, migs []engine.Migration, p Provenance) (Divergence, error)
Reconcile adopts into run runID every migration target's journal records that the ledger does not, taking each body from migs.
type Recorder ¶
Recorder sees the outcome of every plan as it completes, so the ledger survives a failure mid-run.
type RetiredColumn ¶
type RetiredColumn struct {
Schema string `json:"schema"`
Table string `json:"table"`
Column string `json:"column"`
Retires string `json:"retires"`
}
RetiredColumn is a column a change-type left behind as the rollback of a completed swap.
func Unretired ¶
func Unretired(exps map[string]Expansion) []RetiredColumn
Unretired lists every column the expansions of one run remove, so a retired one stops being reported as a rollback the target holds.
func (RetiredColumn) String ¶
func (c RetiredColumn) String() string
String renders the retired column as a qualified reference.
type RevertPlan ¶
type RevertPlan struct {
Run Run
Applied []RunMigration
Plans []engine.Plan
Newer bool
}
RevertPlan is the down side of what a run actually applied, newest first.
type RolloutPolicy ¶
RolloutPolicy splits a run's plans into the expand and contract phases.
type Run ¶
type Run struct {
ID string
Seq int64
Target string
State string
Error string
Attempts int
Rollout string
Phase string
Reverts string
Kind string
Timeouts Timeouts
Provenance Provenance
PlanID string
Retries int
NotBefore *time.Time
CreatedAt time.Time
FinishedAt *time.Time
Progress *RunProgress
Expansions map[string]Expansion
}
Run is one migration run tracked by the control plane.
type RunMigration ¶
type RunMigration struct {
Migration string
AppliedAt time.Time
RevertedBy string
Held bool
Adopted bool
Expansion *Expansion
}
RunMigration is one migration a run put into its target's history, with the inverse frozen for it.
type RunProgress ¶
type RunProgress struct {
Migration string `json:"migration"`
Statement int `json:"statement"`
Phase string `json:"phase,omitempty"`
RowsDone int64 `json:"rows_done,omitempty"`
RowsTotal int64 `json:"rows_total,omitempty"`
Batches int `json:"batches,omitempty"`
}
RunProgress is the newest statement a running run reported, so a long backfill is visible while it runs.
type Scheduler ¶
type Scheduler struct {
Metrics *metrics.Metrics
Notifier notify.Notifier
// contains filtered or unexported fields
}
Scheduler claims runnable runs and executes them under a heartbeated lease.
func NewScheduler ¶
func NewScheduler(store *Store, providers map[string]creds.Provider, eng Engine, policies map[string]RolloutPolicy, cfg Config, log *slog.Logger) *Scheduler
NewScheduler wires a Scheduler.
func (*Scheduler) Run ¶
Run polls for work until ctx is done or Stop is called, then waits for the runs it started.
type SchemaDiff ¶
type SchemaDiff struct {
Observed Observation
UpSQL string
DownSQL string
Drift []string
Retained []string
RepeatableObjects []string
}
SchemaDiff is the migration from a target's live schema to a desired one, and back.
type Scratch ¶
type Scratch struct {
// contains filtered or unexported fields
}
Scratch creates and drops the throwaway databases validation and diff run submitted SQL on.
func NewScratch ¶
NewScratch wires scratch databases onto pool; an empty template means DefaultScratchTemplate.
type ScratchFinding ¶
ScratchFinding is one way the scratch role reaches past the databases it makes for itself.
type Snapshot ¶
type Snapshot struct {
Target string
Fingerprint string
Definition string
RunID string
TakenAt time.Time
}
Snapshot is the expected schema state recorded for a target.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store persists targets, runs, files and leases in the control-plane database.
func (*Store) AdoptApplied ¶
AdoptApplied records a migration the run found the target already holding, and reports whether it wrote a row.
func (*Store) Applied ¶
Applied returns what a target's runs applied and no revert undid, whether or not the run that applied it went on to succeed.
func (*Store) AppliedMigrations ¶
AppliedMigrations lists a run's ledger in the order the run applied it.
func (*Store) Audit ¶
func (s *Store) Audit(ctx context.Context, e AuditEntry) error
Audit appends an entry; at and id are assigned by the store.
func (*Store) AwaitingContract ¶
AwaitingContract returns the target's run stopped between its phases, if it has one.
func (*Store) BoundPlan ¶
BoundPlan returns the newest bound plan on a target whose rollout and submitted files match.
func (*Store) CarriedBy ¶
CarriedBy returns the run that applied the migration on the target, or the newest that carried its file when none did.
func (*Store) Checkpoints ¶
Checkpoints reads the checkpoints a target's standing ledger holds, newest first.
func (*Store) Claim ¶
Claim leases the next queued run, or a running one whose lease expired; one lease per target.
func (*Store) ClaimGitHubReports ¶
func (s *Store) ClaimGitHubReports(ctx context.Context, lease time.Duration, limit int) ([]GitHubRun, error)
ClaimGitHubReports takes the bindings whose run reached a state nobody reported yet and holds them for lease; an unmarked claim is taken again.
func (*Store) Confirm ¶
Confirm requeues an awaiting_contract run for its contract phase and returns it.
func (*Store) CreateAdoption ¶
func (s *Store) CreateAdoption(ctx context.Context, id, target, kind string, migs []engine.Migration, p Provenance) error
CreateAdoption records an already-succeeded run of kind carrying migs' files and one adopted ledger row per migration.
func (*Store) CreateRevert ¶
func (s *Store) CreateRevert(ctx context.Context, id string, orig Run, force bool, t Timeouts, p Provenance) error
CreateRevert queues a run that undoes what another run applied; force allows a run that is not the newest un-reverted one on its target.
func (*Store) CreateRun ¶
func (s *Store) CreateRun(ctx context.Context, id, target, rollout string, files map[string]string, t Timeouts, p Provenance, planID string, exps map[string]Expansion) error
CreateRun queues a run with its migration files, timeout overrides, provenance, bound plan and the expansions it applies in place of the file bodies.
func (*Store) Finish ¶
Finish records a terminal state and releases the lease by run id rather than by holder, because an operator parking a run holds none.
func (*Store) FleetMigrations ¶
FleetMigrations reports which targets hold each migration; it reads the ledger only, so it answers while a target is unreachable.
func (*Store) GitHubBindings ¶
GitHubBindings returns the stored repository binding of every target that carries one, by target name.
func (*Store) GitHubRunsOf ¶
func (s *Store) GitHubRunsOf(ctx context.Context, repository string, pull int, target string) ([]GitHubRun, error)
GitHubRunsOf lists the runs one pull request created on one target, newest first, with their live state.
func (*Store) Heartbeat ¶
Heartbeat extends the holder's lease; ErrLeaseLost means another holder took it, and holder is matched whole.
func (*Store) History ¶
History returns what every run of a target applied and no revert undid, oldest first; a held migration is in neither this nor Applied.
func (*Store) LastRun ¶
LastRun returns the most recently created run for target; ok is false when it never had one.
func (*Store) ListAudit ¶
func (s *Store) ListAudit(ctx context.Context, target, runID string, limit int) ([]AuditEntry, error)
ListAudit returns the newest entries first, optionally filtered by target and run; limit caps the page (100 when zero, MaxPageSize at most).
func (*Store) ListCredentialStores ¶
func (s *Store) ListCredentialStores(ctx context.Context) ([]CredentialStore, error)
ListCredentialStores returns every registered store by name.
func (*Store) ListDriftEvents ¶
ListDriftEvents returns recent drift events, optionally filtered by target.
func (*Store) ListPlans ¶
ListPlans returns a target's plans, newest first; limit caps the page (100 when zero, MaxPageSize at most).
func (*Store) ListTargets ¶
ListTargets summarises every target by name, counting ready plans created at or after since.
func (*Store) LockTarget ¶
LockTarget is Target for update, answering an unregistered name with an empty provider and config.
func (*Store) MarkGitHubReported ¶
MarkGitHubReported records the state the pull request was told about and releases the claim.
func (*Store) MarkReverted ¶
MarkReverted records that revertID undid one migration of run origID.
func (*Store) OpenDrift ¶
OpenDrift reports whether target has a drift event nobody has resolved or re-baselined.
func (*Store) PlanRevert ¶
PlanRevert builds the plans that undo run id: the down side of every migration its ledger still holds, in reverse order of application.
func (*Store) ReadyPlan ¶
ReadyPlan returns the ready plan for a key on a target, created at or after since.
func (*Store) ReadyPlanCount ¶
ReadyPlanCount counts a target's ready plans created at or after since.
func (*Store) RecordApplied ¶
func (s *Store) RecordApplied(ctx context.Context, runID, migration string, held bool, exp *Expansion) error
RecordApplied adds a migration to a run's ledger, or updates it when the contract phase completes it.
func (*Store) RecordDelivery ¶
RecordDelivery records a webhook delivery id and reports whether it is the first sight of it.
func (*Store) RecordDrift ¶
RecordDrift opens a drift event while baseline is still the target's fingerprint and no identical one is open; reports whether it did.
func (*Store) RecordGitHubRun ¶
RecordGitHubRun binds run to a pull request; a second command over the same run replaces the binding.
func (*Store) RegisterCredentialStore ¶
func (s *Store) RegisterCredentialStore(ctx context.Context, cs CredentialStore) error
RegisterCredentialStore upserts a credential store; a target already pointed at it moves with it.
func (*Store) RegisterTarget ¶
func (s *Store) RegisterTarget(ctx context.Context, name, provider string, config map[string]string) error
RegisterTarget upserts a target, replacing whatever config the row held; the credential store is a column, so a foreign key refuses a dangling one.
func (*Store) ResolveDrift ¶
ResolveDrift closes every open drift event for a target and reports whether any was open.
func (*Store) RetireColumns ¶
func (s *Store) RetireColumns(ctx context.Context, target, runID, migration string, cols []RetiredColumn) error
RetireColumns records the columns a run left behind so a desired-schema diff stops proposing their drop.
func (*Store) RetirePlan ¶
RetirePlan marks a bound plan superseded so a later job with the same files plans afresh.
func (*Store) RetiredColumns ¶
RetiredColumns lists the columns a target keeps only as the rollback of a completed change-type.
func (*Store) Retry ¶
Retry requeues a running run after a transient failure, holding it back for wait and releasing its lease.
func (*Store) RevertTarget ¶
RevertTarget returns the newest un-reverted run on target, which is what a revert with no run id acts on.
func (*Store) RunsApplying ¶
func (s *Store) RunsApplying(ctx context.Context, target string, since time.Time) (map[string]string, error)
RunsApplying maps each migration held by a succeeded run of target created after since to that run's id.
func (*Store) SavePlan ¶
SavePlan stores a ready plan with its files; a ready plan with the same key on the target is replaced.
func (*Store) SaveProgress ¶
SaveProgress records what the newest statement of a running run reported; every transition that starts or ends an attempt clears it.
func (*Store) SaveSnapshot ¶
func (s *Store) SaveSnapshot(ctx context.Context, target, fingerprint, definition, runID string) error
SaveSnapshot upserts the expected schema for a target and resolves open drift.
func (*Store) SelectVersion ¶
func (s *Store) SelectVersion(ctx context.Context, target string, plans []engine.Plan, to int64) (keep, withheld []engine.Plan, err error)
SelectVersion splits a submitted set at a version target: what is at or below to is kept, the rest withheld.
func (*Store) SnapshotFor ¶
SnapshotFor returns the expected schema recorded for a target.
func (*Store) SnapshotTargets ¶
SnapshotTargets lists targets that have an expected schema recorded.
func (*Store) SupersedePlan ¶
func (s *Store) SupersedePlan(ctx context.Context, id string, next Plan, files map[string]string) error
SupersedePlan retires a ready plan and stores next in its place, linking the two.
func (*Store) SweepDeliveries ¶
SweepDeliveries deletes recorded delivery ids received before t and reports how many went.
func (*Store) SweepGitHubRuns ¶
SweepGitHubRuns deletes reported bindings created before t and reports how many went.
func (*Store) SweepPlans ¶
SweepPlans deletes bound and superseded plans created before olderThan, keeping those an unfinished run still applies.
func (*Store) Transact ¶
Transact runs fn on a store bound to one transaction; its writes stay invisible to other sessions until fn returns nil.
func (*Store) UnretireColumns ¶
UnretireColumns forgets columns a revert renamed back into place.
func (*Store) VaultStore ¶
VaultStore answers where a named credential store points; it is the vault provider's lookup.
type TargetRegistration ¶
type TargetRegistration struct {
Name string
Provider string
CredentialStore string
VaultPath string
VaultTemplate string
SecretPath string
DSNRegistered bool
Timeouts Timeouts
SearchPath string
RequirePlan bool
KeepOld bool
IgnoreAdoptedTables bool
GitHubRepositories []string
}
TargetRegistration is a target as it was registered, and carries no credential.
func RegistrationOf ¶
func RegistrationOf(name, provider string, config map[string]string) TargetRegistration
RegistrationOf reads a stored target config back into the settings it was registered with.
func (TargetRegistration) Fields ¶
func (r TargetRegistration) Fields() []any
Fields is the registration as ordered log attributes, and the only rendering of one.
type TargetStatus ¶
type TargetStatus struct {
Target string
Provider string
Timeouts Timeouts
SearchPath string
Applied []engine.Applied
Repeatables []engine.Repeatable
LastRun *Run
Snapshot *Snapshot
OpenDrift bool
Unreachable string
}
TargetStatus is what the control plane knows about a target next to what its database reports.
type TargetSummary ¶
type TargetSummary struct {
TargetRegistration
LastRun *Run
AttentionRuns int
UnresolvedDrift bool
ReadyPlans int
AppliedCount int
}
TargetSummary is the control plane's own view of a registered target, assembled without connecting to it.
type Timeouts ¶
Timeouts are per-statement timeouts as Go duration strings; empty means inherit.
type Validation ¶
type Validation struct {
Base string
Effects [][]string
Fingerprints []string
Changes [][]engine.ObjectChange
Expansions map[string]Expansion
Plans []engine.Plan
Replayed int
Collapsed int
}
Validation is what the scratch database looked like after the history and after each plan in turn.
type Validator ¶
type Validator struct {
Expander *Expander
// contains filtered or unexported fields
}
Validator replays a target's history on a scratch database and applies new plans on top.
func NewValidator ¶
NewValidator wires a Validator over the scratch connection.
Source Files
¶
- audit_store.go
- baseline.go
- checkpoint.go
- checkpoint_body.go
- credential_store.go
- diff.go
- drift.go
- drift_store.go
- engine.go
- expand.go
- fleet.go
- github.go
- holder.go
- inspect.go
- journal.go
- ledger.go
- notify_store.go
- plan.go
- plan_store.go
- policy.go
- reconcile.go
- retry.go
- scheduler.go
- schema.go
- scratch.go
- searchpath.go
- store.go
- target.go
- timeouts.go
- validate.go
- version_target.go