Documentation
¶
Overview ¶
Package job runs the backup test pipeline and builds its result.
Index ¶
- Constants
- func PlainTableKey(table TableRef) string
- func WorkFileFailure(err error) error
- type Backup
- type CheckName
- type CheckResult
- type CheckStatus
- type Checks
- type Dump
- type Engine
- type Failure
- type Instance
- type KeyedCount
- type Object
- type Options
- type Result
- type Source
- type Stage
- type StageTiming
- type Status
- type TableCount
- type TableFinding
- type TableKeyFunc
- type TableRef
- type TimestampCheck
- type TimestampReading
- type TimestampState
- type Version
- type VersionSource
Constants ¶
const ( ProblemMissing = "missing" ProblemRowCountChanged = "row_count_changed" )
Problems reported for a single table.
Variables ¶
This section is empty.
Functions ¶
func PlainTableKey ¶
PlainTableKey identifies a table by its readable name.
func WorkFileFailure ¶
WorkFileFailure explains why the runner couldn't write to its work directory.
Types ¶
type Backup ¶
type Backup struct {
File string `json:"file"`
ObjectKey string `json:"object_key,omitempty"`
SizeBytes int64 `json:"size_bytes"`
Time time.Time `json:"time,omitzero"`
Format archive.Format `json:"format,omitempty"`
Compression string `json:"compression,omitempty"`
Encryption string `json:"encryption,omitempty"`
PostgresVersion string `json:"postgres_version,omitempty"`
PostgresMajor int `json:"postgres_major,omitempty"`
VersionSource VersionSource `json:"version_source,omitempty"`
RestoredMajor int `json:"restored_major,omitempty"`
}
Backup describes the file that was tested.
type CheckResult ¶
type CheckResult struct {
Name CheckName `json:"name"`
Status CheckStatus `json:"status"`
Code string `json:"code,omitempty"`
Reason string `json:"reason,omitempty"`
Measured string `json:"measured,omitempty"`
Expected string `json:"expected,omitempty"`
Tables []TableFinding `json:"tables,omitempty"`
}
CheckResult reports one check. Table names stay in Tables, so they can be hashed before the result leaves the runner, and never appear in Reason.
type CheckStatus ¶
type CheckStatus string
CheckStatus is the outcome of one check.
const ( CheckPassed CheckStatus = "pass" CheckFailed CheckStatus = "fail" CheckSkipped CheckStatus = "skipped" )
Check outcomes.
type Checks ¶
type Checks struct {
// ExpectedTables, Baseline and TableTolerancePercent identify tables by table key.
ExpectedTables []string
// Baseline holds the row counts of the last passing run. It is empty on a source's first run.
Baseline []KeyedCount
TolerancePercent float64
TableTolerancePercent map[string]float64
EstimateRows bool
LatestTimestamp *TimestampCheck
// TableKey defaults to PlainTableKey.
TableKey TableKeyFunc
// BackupTime is when the backup was made. The file's modification time is used when it is zero.
BackupTime time.Time
}
Checks configures how a restored backup is judged.
type Engine ¶
type Engine interface {
Ready(ctx context.Context) error
DetectVersion(ctx context.Context, jobID string, dump Dump) (Version, error)
Start(ctx context.Context, jobID string, version Version) (Instance, error)
Cleanup(ctx context.Context, jobID string) error
RemoveOrphans(ctx context.Context, keepJobIDs ...string) error
}
Engine restores dumps of one database type.
type Failure ¶
type Failure struct {
Status Status
Code string
Reason string
// Stage overrides the running stage when one stage covers several steps.
Stage Stage
// contains filtered or unexported fields
}
Failure explains why a job didn't pass. Code and Reason must never contain SQL or row contents.
func RunnerError ¶
RunnerError reports that the runner couldn't do its job.
type Instance ¶
type Instance interface {
Major() int
Restore(ctx context.Context, dump Dump) error
Tables(ctx context.Context, estimate bool) ([]TableCount, error)
LatestTimestamp(ctx context.Context, check TimestampCheck) (TimestampReading, error)
}
Instance is a throwaway database server.
type KeyedCount ¶
KeyedCount is the number of rows in the table with this key.
type Options ¶
type Options struct {
Checks Checks
WorkDir string
SourceID string
Secrets config.SourceSecrets
// DiskMargin is how many times the backup's size must be free before downloading it.
DiskMargin float64
// PostgresHint is the major version to use when the backup doesn't say which one made it.
PostgresHint int
// OnStage is told when each stage starts.
OnStage func(Stage)
// RunningJobs lists the other jobs in progress, whose containers and files must be kept.
RunningJobs func() []string
}
Options configures one job.
type Result ¶
type Result struct {
SchemaVersion int `json:"schema_version"`
Status Status `json:"status"`
Stage Stage `json:"stage,omitempty"`
ReasonCode string `json:"reason_code,omitempty"`
Reason string `json:"reason,omitempty"`
Backup Backup `json:"backup"`
Stages []StageTiming `json:"stages"`
Tables []TableCount `json:"tables"`
Checks []CheckResult `json:"checks"`
Notes []string `json:"notes,omitempty"`
// contains filtered or unexported fields
}
Result is the report of one job.
func ErrorResult ¶
ErrorResult reports a job that couldn't start.
type Source ¶
type Source interface {
Latest(ctx context.Context) (Object, error)
Download(ctx context.Context, object Object, path string) error
}
Source finds and downloads backups.
type Stage ¶
type Stage string
Stage names a step of the pipeline.
const ( StageResolve Stage = "resolve" StagePreflight Stage = "preflight" StageDownload Stage = "download" StageDecrypt Stage = "decrypt" StageDecompress Stage = "decompress" StageDetectVersion Stage = "detect_version" StageRestore Stage = "restore" StageCheck Stage = "check" StageCleanup Stage = "cleanup" )
Pipeline stages, in the order they run.
type StageTiming ¶
StageTiming records how long a stage took.
type TableCount ¶
type TableCount struct {
Schema string `json:"schema"`
Name string `json:"name"`
Rows int64 `json:"rows"`
}
TableCount is the number of rows in a restored table.
type TableFinding ¶
type TableFinding struct {
Key string `json:"table_key"`
Problem string `json:"problem"`
MeasuredRows *int64 `json:"measured_rows,omitempty"`
ExpectedRows *int64 `json:"expected_rows,omitempty"`
ChangePercent *float64 `json:"change_percent,omitempty"`
TolerancePercent *float64 `json:"tolerance_percent,omitempty"`
}
TableFinding describes what is wrong with one table.
type TableKeyFunc ¶
TableKeyFunc turns a table into the key that identifies it outside the restored database.
func HashedTableKey ¶
func HashedTableKey(salt config.Secret) TableKeyFunc
HashedTableKey identifies tables without revealing their names. The salt stops anyone from recovering names by hashing common ones, and the NUL byte keeps schema and table apart.
type TimestampCheck ¶
TimestampCheck requires a recent row in the chosen column.
type TimestampReading ¶
type TimestampReading struct {
State TimestampState
Value time.Time
}
TimestampReading is the newest value in the chosen column.
type TimestampState ¶
type TimestampState int
TimestampState says what was found in the chosen column.
const ( TimestampFound TimestampState = iota TimestampNoColumn TimestampNoRows )
States of the chosen timestamp column.
type Version ¶
type Version struct {
Full string
Major int
Source VersionSource
}
Version is the Postgres version a dump was made with.
type VersionSource ¶
type VersionSource string
VersionSource says where the detected Postgres version came from.
const ( VersionFromDump VersionSource = "dump" VersionFromHint VersionSource = "hint" VersionDefault VersionSource = "default" )
Places a Postgres version can come from.