Documentation ¶
Overview ¶
This package provides a Reporter which scans a sqlite database for process exit information, writing it to the consul datastore. This is useful for allowing external systems to examine the success or failure of a pod.
Index ¶
Constants ¶
const ( // Specifies the amount of time to wait between SQLite queries for the latest finish events DefaultPollInterval = 15 * time.Second // Specifies the default amount of time to wait between pruning sqlite // rows. DefaultPruneInterval = 10 * time.Minute // Specifies the default amount to allow a row to exist in the sqlite // database before pruning it DefaultPruneAfter = 24 * time.Hour )
Variables ¶
This section is empty.
Functions ¶
func IsRetryable ¶
Types ¶
type EnvironmentExtractor ¶
func (EnvironmentExtractor) WriteFinish ¶
func (e EnvironmentExtractor) WriteFinish(exitCode int, exitStatus int) error
Write exit code and exit status along with some information pulled from the current environment into the configured sqlite database. The environment extractor is hooked into runits ./finish file (http://smarden.org/runit/runsv.8.html)
type FinishOutput ¶
type FinishOutput struct { PodID types.PodID `json:"pod_id"` LaunchableID launch.LaunchableID `json:"launchable_id"` EntryPoint string `json:"entry_point"` PodUniqueKey types.PodUniqueKey `json:"pod_unique_key"` // These two model the arguments given to the ./finish script under runit: // (http://smarden.org/runit/runsv.8.html) ExitCode int `json:"exit_code"` ExitStatus int `json:"exit_status"` // This is never written explicitly and is determined automatically by // sqlite (via AUTOINCREMENT) ID int64 // This is never written explicitly, it's determined automatically by // sqlite (via DEFAULT CURRENT_TIMESTAMP) ExitTime time.Time `json:"exit_time"` }
Represents a row in the sqlite database indicating the exit of a runit process.
type FinishService ¶
type FinishService interface { // Closes any resources such as database connection Close() error // Inserts a finish row corresponding to a process exit Insert(finish FinishOutput) error // Runs any outstanding migrations Migrate() error // Reads all finish data after the given ID GetLatestFinishes(lastID int64) ([]FinishOutput, error) // Gets the last finish result for a given PodUniqueKey LastFinishForPodUniqueKey(podUniqueKey types.PodUniqueKey) (FinishOutput, error) // Deletes any rows with dates before the specified time PruneRowsBefore(time.Time) error // LastFinishID() returns the highest ID in the finishes table. It is // useful for repairing the workspace file which is meant to contain // the last processed ID. LastFinishID() (int64, error) }
func NewSQLiteFinishService ¶
func NewSQLiteFinishService(sqliteDBPath string, logger logging.Logger) (FinishService, error)
type PodStatusStore ¶
type PodStatusStore interface {
SetLastExit(ctx context.Context, podUniqueKey types.PodUniqueKey, launchableID launch.LaunchableID, entryPoint string, exitStatus podstatus.ExitStatus) error
}
type Reporter ¶
type Reporter struct {
// contains filtered or unexported fields
}
func New ¶
func New(config ReporterConfig, logger logging.Logger, podStatusStore PodStatusStore, client consulutil.ConsulClient) (*Reporter, error)
Should only be called if config.FullyConfigured() returned true. Returns an error iff there is a configuration problem.
type ReporterConfig ¶
type ReporterConfig struct { // Path to the sqlite database that should be polled for finish // information. NOTE: the written file AND THE DIRECTORY IT'S IN will // be given file perms 0666, because sqlite works like that. you can't // write to a database unless you can also write to the directory it's // in. As a result, the path here should include at least one level of // directory to be created SQLiteDatabasePath string `yaml:"sqlite_database_path"` // Path to the executable that constructs finish information based on process environment EnvironmentExtractorPath string `yaml:"environment_extractor_path"` // Path to a file the pod process reporter can use as a workspace. It's used to store the most recently // recorded database id, and needs to persist across p2-preparer restarts WorkspaceDirPath string `yaml:"workspace_dir_path"` // e.g. to /usr/bin/timeout. This is useful because the finish script // blocks restart of runit processes, so it's recommended to wrap the // database insert in a timeout. TimeoutPath string `yaml:"timeout_path"` // Specifies the amount of time to wait between SQLite queries for the // latest finish events PollInterval time.Duration `yaml:"poll_interval"` // Length of time to leave rows in the sqlite database before deleting // them. PruneAfter time.Duration `yaml:"prune_after"` // Specifies the amount of time to wait between pruning sqlite rows PruneInterval time.Duration `yaml:"prune_interval"` }
func (ReporterConfig) FinishExec ¶
func (r ReporterConfig) FinishExec() []string
func (ReporterConfig) FullyConfigured ¶
func (r ReporterConfig) FullyConfigured() bool
Returns true if the contents of the ReporterConfig indicate that a pod process reporter should be run. In other words, if it returns true, New() should be called.
type RetryableError ¶
type RetryableError struct {
Inner error
}
func (RetryableError) Error ¶
func (r RetryableError) Error() string