Documentation
¶
Overview ¶
Package dbprovision records and summarizes the steps of creating a database, so the dashboard, CLI and API all show the same truth.
Index ¶
- Constants
- Variables
- func EncodeCrash(info CrashInfo) string
- func FailStepForReason(reason string, pullFinished bool, errText string) string
- func RedactTail(s string) string
- type Attempt
- type Cause
- type CrashInfo
- type EventView
- type Failure
- type Fix
- type LeftoverVolumeError
- type Recorder
- type StepView
- type Store
- type Tracker
- func (t *Tracker) Done(step, detail string)
- func (t *Tracker) Fail(step string, err error)
- func (t *Tracker) Finish()
- func (t *Tracker) LogTail(info CrashInfo)
- func (t *Tracker) Progress(step, detail string, cur, total int64)
- func (t *Tracker) Pull(ev docker.PullEvent)
- func (t *Tracker) PullFinished() bool
- func (t *Tracker) Skip(step, detail string)
- func (t *Tracker) Start(step, detail string)
- type VolumeInfo
Constants ¶
const ( CausePermission = "permission" CauseOutOfMemory = "out_of_memory" CausePortInUse = "port_in_use" CauseBadVolume = "bad_volume" CauseBadConfig = "bad_config" )
Typed crash reasons.
const ( FixGrantCapabilities = "grant_capabilities" FixRaiseMemory = "raise_memory" FixFreePort = "free_port" FixResetVolume = "reset_volume" FixReviewConfig = "review_config" )
Fix ids for crash causes. They are guided: the client shows the hint, none is applied server side.
const ( StepAccepted = "accepted" StepDockerCheck = "docker_check" StepPullImage = "pull_image" StepCreateVolume = "create_volume" StepCredentials = "credentials_and_tls" StepCreateContainer = "create_container" StepStart = "start" StepWaitReady = "wait_ready" StepApplySettings = "apply_settings" StepReady = "ready" )
Step names, in the order they run.
const ( StatusPending = "pending" StatusStarted = "started" StatusDone = "done" StatusFailed = "failed" StatusSkipped = "skipped" )
Step statuses.
const ( AttemptInProgress = "in_progress" AttemptFailed = "failed" AttemptReady = "ready" )
Attempt statuses.
const ( FixRecheckDocker = "recheck_docker" FixRetry = "retry" FixRemoveVolume = "remove_leftover_volume" FixFreeDisk = "free_disk" FixReuseVolume = "reuse_existing_volume" FixChooseName = "choose_another_name" )
Fix ids a client can act on.
const ( EnvKeepAttempts = "APP_DB_PROVISION_KEEP_ATTEMPTS" EnvEventInterval = "APP_DB_PROVISION_EVENT_INTERVAL" )
Environment variables.
const ReasonCrashLoop = "CrashLoop"
ReasonCrashLoop is the Ready-condition reason when the container restarts repeatedly while starting.
const ReasonLeftoverVolume = "LeftoverVolume"
ReasonLeftoverVolume is the Ready-condition reason of the create_volume stop.
const StatusInfo = "info"
StatusInfo marks an event that records data rather than progress.
const StepLogTail = "log_tail"
StepLogTail is the pseudo step that carries a crashed container's output; it is not a provisioning step.
Variables ¶
var Steps = []string{ StepAccepted, StepDockerCheck, StepPullImage, StepCreateVolume, StepCredentials, StepCreateContainer, StepStart, StepWaitReady, StepApplySettings, StepReady, }
Steps is the canonical order.
Functions ¶
func EncodeCrash ¶
EncodeCrash serializes info for a log_tail event, redacting the tail.
func FailStepForReason ¶
FailStepForReason maps a reconciler Ready-condition reason to the step it belongs to; "" means the reason is not a provisioning failure.
func RedactTail ¶
RedactTail hides anything that looks like a password or token and keeps the last maxTailLines lines.
Types ¶
type Attempt ¶
type Attempt struct {
ID string `json:"attempt_id"`
Status string `json:"status"`
CurrentStep string `json:"current_step,omitempty"`
StartedAt *time.Time `json:"started_at,omitempty"`
FinishedAt *time.Time `json:"finished_at,omitempty"`
Steps []StepView `json:"steps"`
Events []EventView `json:"events"`
Failure *Failure `json:"failure,omitempty"`
}
Attempt is the latest provisioning attempt of a database.
type Cause ¶
type Cause struct {
Kind string `json:"kind"`
Hint string `json:"hint"`
Fix *Fix `json:"fix,omitempty"`
}
Cause is a classified reason a database container stopped, with a typed fix.
type CrashInfo ¶
type CrashInfo struct {
Tail string `json:"tail"`
ExitCode int `json:"exit_code"`
OOMKilled bool `json:"oom_killed,omitempty"`
Restarts int `json:"restarts,omitempty"`
}
CrashInfo is the recorded output and exit facts of a crashed container.
type EventView ¶
type EventView struct {
Step string `json:"step"`
Status string `json:"status"`
Detail string `json:"detail,omitempty"`
At time.Time `json:"at"`
}
EventView is one raw event for the Details log.
type Failure ¶
type Failure struct {
Step string `json:"step"`
Reason string `json:"reason"`
Fix *Fix `json:"fix,omitempty"`
// Fixes lists every choice when the stop needs the owner to decide.
Fixes []Fix `json:"fixes,omitempty"`
Volume *VolumeInfo `json:"volume,omitempty"`
// LogTail is the redacted last output of the crashed container.
LogTail string `json:"log_tail,omitempty"`
// Cause is the classified crash reason, when the output matched one.
Cause *Cause `json:"cause,omitempty"`
}
Failure describes why an attempt stopped.
type Fix ¶
type Fix struct {
ID string `json:"id"`
Label string `json:"label"`
Confirm bool `json:"confirm,omitempty"`
}
Fix is a typed way to recover from a failed step.
func ClassifyFix ¶
ClassifyFix suggests a fix for a failure, or nil when none is known.
type LeftoverVolumeError ¶
LeftoverVolumeError is the create_volume stop for a data volume a deleted database of the same name left behind.
func (*LeftoverVolumeError) Error ¶
func (e *LeftoverVolumeError) Error() string
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder writes provisioning events.
func NewRecorder ¶
NewRecorder reads the attempt and throttle settings from the environment.
type StepView ¶
type StepView struct {
Step string `json:"step"`
Status string `json:"status"`
Detail string `json:"detail,omitempty"`
Current int64 `json:"current,omitempty"`
Total int64 `json:"total,omitempty"`
At *time.Time `json:"at,omitempty"`
}
StepView is one step of an attempt as clients render it.
type Store ¶
type Store interface {
AppendDatabaseProvisionEvent(ctx context.Context, e store.DatabaseProvisionEvent) error
BeginDatabaseProvisionAttempt(ctx context.Context, name string, keep int) (string, error)
LatestDatabaseProvisionAttempt(ctx context.Context, name string) (string, []store.DatabaseProvisionEvent, error)
}
Store is what the recorder needs; *store.DB satisfies it.
type Tracker ¶
type Tracker struct {
// contains filtered or unexported fields
}
Tracker writes one attempt's events. A nil Tracker ignores every call.
func (*Tracker) Finish ¶
func (t *Tracker) Finish()
Finish marks every remaining step done and the attempt ready.
func (*Tracker) LogTail ¶
LogTail records a crashed container's output on the current attempt. A nil Tracker ignores it.
func (*Tracker) PullFinished ¶
PullFinished reports whether the pull step completed.
type VolumeInfo ¶
VolumeInfo names the leftover volume a failure is about.
func ParseLeftover ¶
func ParseLeftover(text string) (VolumeInfo, bool)
ParseLeftover extracts the volume name and size from a LeftoverVolumeError text.