state_machine

package
v0.0.0-...-2ad74da Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 21, 2024 License: BSD-3-Clause Imports: 17 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// State names.
	S_NORMAL_IDLE                  = "idle"
	S_NORMAL_ACTIVE                = "active"
	S_NORMAL_SUCCESS               = "success"
	S_NORMAL_SUCCESS_THROTTLED     = "success throttled"
	S_NORMAL_FAILURE               = "failure"
	S_NORMAL_FAILURE_THROTTLED     = "failure throttled"
	S_NORMAL_SAFETY_THROTTLED      = "safety throttled"
	S_NORMAL_WAIT_FOR_WINDOW       = "waiting for roll window"
	S_TOO_MANY_CLS                 = "too many CLs to same revision"
	S_DRY_RUN_IDLE                 = "dry run idle"
	S_DRY_RUN_ACTIVE               = "dry run active"
	S_DRY_RUN_SUCCESS              = "dry run success"
	S_DRY_RUN_SUCCESS_LEAVING_OPEN = "dry run success; leaving open"
	S_DRY_RUN_FAILURE              = "dry run failure"
	S_DRY_RUN_FAILURE_THROTTLED    = "dry run failure throttled"
	S_DRY_RUN_SAFETY_THROTTLED     = "dry run safety throttled"
	S_STOPPED                      = "stopped"
	S_CURRENT_ROLL_MISSING         = "current roll missing"
	S_OFFLINE                      = "offline"

	// Transition function names.
	F_NOOP                       = "no-op"
	F_UPDATE_REPOS               = "update repos"
	F_UPLOAD_ROLL                = "upload roll"
	F_UPLOAD_DRY_RUN             = "upload dry run"
	F_UPDATE_ROLL                = "update roll"
	F_SWITCH_TO_DRY_RUN          = "switch roll to dry run"
	F_SWITCH_TO_NORMAL           = "switch roll to normal"
	F_CLOSE_FAILED               = "close roll (failed)"
	F_CLOSE_STOPPED              = "close roll (stopped)"
	F_CLOSE_DRY_RUN_FAILED       = "close roll (dry run failed)"
	F_CLOSE_DRY_RUN_OUTDATED     = "close roll (dry run outdated)"
	F_WAIT_FOR_LAND              = "wait for roll to land"
	F_RETRY_FAILED_NORMAL        = "retry failed roll"
	F_RETRY_FAILED_DRY_RUN       = "retry failed dry run"
	F_NOTIFY_FAILURE_THROTTLE    = "notify failure throttled"
	F_NOTIFY_SAFETY_THROTTLE     = "notify safety throttled"
	F_NOTIFY_TOO_MANY_CLS        = "notify too many CLs"
	F_ERROR_CURRENT_ROLL_MISSING = "error: current roll missing"

	// Maximum number of no-op transitions to perform at once. This is an
	// arbitrary limit just to keep us from performing an unbounded number
	// of transitions at a time.
	MAX_NOOP_TRANSITIONS = 10
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AutoRollStateMachine

type AutoRollStateMachine struct {
	// contains filtered or unexported fields
}

AutoRollStateMachine is a StateMachine for the AutoRoller.

func New

New returns a StateMachine for the autoroller.

func (*AutoRollStateMachine) Current

func (s *AutoRollStateMachine) Current() string

Return the current state.

func (*AutoRollStateMachine) GetNext

func (s *AutoRollStateMachine) GetNext(ctx context.Context) (string, error)

Get the next state.

func (*AutoRollStateMachine) NextTransition

func (s *AutoRollStateMachine) NextTransition(ctx context.Context) error

Attempt to perform the next state transition.

func (*AutoRollStateMachine) NextTransitionSequence

func (s *AutoRollStateMachine) NextTransitionSequence(ctx context.Context) error

Perform the next state transition, plus any subsequent transitions which are no-ops.

func (*AutoRollStateMachine) Transition

func (s *AutoRollStateMachine) Transition(ctx context.Context, dest string) error

Attempt to perform the given state transition.

type AutoRollerImpl

type AutoRollerImpl interface {
	// Return a Throttler indicating that we have failed to roll too many
	// times within a time period.
	FailureThrottle() *Throttler

	// RequestCleanup requests that all local checkouts stored by the roller be
	// deleted.
	RequestCleanup(ctx context.Context, reason string) error

	// Return the currently-active roll. Should return untyped nil, as
	// opposed to RollCLImpl(nil), if no roll exists.
	GetActiveRoll() RollCLImpl

	// Return the config struct for the roller.
	GetConfig() *config.Config

	// Return the currently-rolled revision of the sub-project.
	GetCurrentRev() *revision.Revision

	// Return the next revision of the sub-project which we want to roll.
	// This is the same as GetCurrentRev when the sub-project is up-to-date.
	GetNextRollRev() *revision.Revision

	// Return the list of revisions included in a roll.
	GetRevisionsInRoll(context.Context, RollCLImpl) []*revision.Revision

	// GetLastNRollRevs returns the revision IDs for up to N most recent rolls,
	// sorted most recent first.
	GetLastNRollRevs(int) []string

	// Return the current mode of the AutoRoller.
	GetMode() string

	// InRollWindow returns true iff the roller is inside the configured
	// time window in which it is allowed to roll.
	InRollWindow(time.Time) bool

	// Return true if we have already rolled past the given revision.
	RolledPast(context.Context, *revision.Revision) (bool, error)

	// Return a Throttler indicating that we have attempted to upload too
	// many CLs within a time period.
	SafetyThrottle() *Throttler

	// Return a Throttler indicating whether we have successfully rolled too
	// many times within a time period.
	SuccessThrottle() *Throttler

	// Return a Throttler indicating whether we have too recently completed a
	// dry run successfully.
	DryRunSuccessThrottle() *Throttler

	// Update the project and sub-project repos.
	UpdateRepos(context.Context) error

	// Upload a new roll. AutoRollerImpl should track the created roll.
	UploadNewRoll(ctx context.Context, from, to *revision.Revision, dryRun bool) (RollCLImpl, error)
}

Interface for interacting with the other elements of an autoroller.

type RollCLImpl

type RollCLImpl interface {
	// Add a comment to the CL.
	AddComment(context.Context, string) error

	// Attempt returns the number of the current attempt for this roll, starting
	// at zero for the first attempt.
	Attempt() int

	// AttemptStart returns the start time of the current attempt.
	AttemptStart() time.Time

	// Close the CL. The first string argument is the result of the roll,
	// and the second is the message to add to the CL on closing.
	Close(context.Context, string, string) error

	// IsClosed returns true iff the roll has been closed (ie. abandoned
	// or landed).
	IsClosed() bool

	// Return true iff the roll has finished (ie. succeeded or failed).
	IsFinished() bool

	// Return true iff the roll succeeded.
	IsSuccess() bool

	// Return true iff the roll has been committed.
	IsCommitted() bool

	// Return true iff the dry run is finished.
	IsDryRunFinished() bool

	// Return true iff the dry run succeeded.
	IsDryRunSuccess() bool

	// Return true iff the roll was triggered manually.
	IsManual() bool

	// Return the issue ID of the roll.
	IssueID() string

	// Return the URL of the roll.
	IssueURL() string

	// Retry the CQ in the case of a failure.
	RetryCQ(context.Context) error

	// Retry a dry run in the case of a failure.
	RetryDryRun(context.Context) error

	// Return the result of the roll.
	Result() string

	// The revision this roll is rolling from.
	RollingFrom() *revision.Revision

	// The revision this roll is rolling to.
	RollingTo() *revision.Revision

	// Set the dry run bit on the CL.
	SwitchToDryRun(context.Context) error

	// Set the full CQ bit on the CL.
	SwitchToNormal(context.Context) error

	// Update our local copy of the CL from the codereview server.
	Update(context.Context) error
}

Interface for interacting with a single autoroll CL.

type Throttler

type Throttler struct {
	// contains filtered or unexported fields
}

Throttler determines whether we should be throttled.

func NewThrottler

func NewThrottler(ctx context.Context, gcsClient gcs.GCSClient, gcsPath string, period time.Duration, attempts int64) (*Throttler, error)

NewThrottler returns a Throttler instance.

func (*Throttler) Inc

func (t *Throttler) Inc(ctx context.Context) error

Inc increments the Throttler's counter.

func (*Throttler) IsThrottled

func (t *Throttler) IsThrottled() bool

IsThrottled returns true iff we should be throttled.

func (*Throttler) Reset

func (t *Throttler) Reset(ctx context.Context) error

Reset forcibly unthrottles the Throttler.

func (*Throttler) ThrottledUntil

func (t *Throttler) ThrottledUntil() time.Time

ThrottledUntil returns the approximate time when the Throttler will no longer be throttled.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL