Documentation
¶
Overview ¶
Package experiments holds the use cases of the experiments context. Every write locks its project's row first, the lock the flags context's writes take, so an experiment is judged against the flags and the salts of its project as they are when it commits.
Index ¶
- Constants
- Variables
- type AcknowledgeAlert
- type AcknowledgeAlertCommand
- type AcknowledgeAlertDeps
- type AlertReader
- type AlertStore
- type AlertView
- type ArchiveExperiment
- type ArchiveExperimentDeps
- type AuditLog
- type CheckStore
- type CheckUniformity
- type ChecksLock
- type CloneExperiment
- type CloneExperimentCommand
- type CloneExperimentDeps
- type CreateExperiment
- type CreateExperimentCommand
- type CreateExperimentDeps
- type DeleteExperiment
- type DeleteExperimentDeps
- type ExperimentCloner
- type ExperimentCommand
- type ExperimentCreator
- type ExperimentDeleter
- type ExperimentFilter
- type ExperimentLister
- type ExperimentPage
- type ExperimentRules
- type ExperimentUpdater
- type ExposureActivity
- type FinalExposures
- type FirstExposures
- type Flags
- type GetAssignment
- type GetExperiment
- type GetSampleRatio
- type Holders
- type ImportCommand
- type ImportEffect
- type ImportStore
- type Importer
- func (i *Importer) CheckSalts(ctx context.Context) error
- func (i *Importer) CheckServed(ctx context.Context, project workspace.ProjectID, keys []string) error
- func (i *Importer) CreateExperiment(ctx context.Context, cmd ImportCommand) (ImportEffect, error)
- func (i *Importer) DeleteExperiment(ctx context.Context, project workspace.ProjectID, key string, leaving []string, ...) error
- func (i *Importer) UpdateExperiment(ctx context.Context, cmd ImportCommand) (ImportEffect, error)
- type ImporterDeps
- type ListAlerts
- type ListExperiments
- type Owners
- type PendingFinalChecks
- type ProjectLocker
- type Reader
- type Recorder
- type RegenerateSalts
- type RegenerateSaltsDeps
- type RolloutSalts
- type Rulesets
- type RunChecks
- type RunChecksDeps
- type RunningExperiments
- type SaltRegenerator
- type SampleRatioReader
- type SampleRatioState
- type SetDecisionNote
- type SetDecisionNoteCommand
- type SetDecisionNoteDeps
- type StartExperiment
- type StartExperimentDeps
- type StopExperiment
- type StopExperimentCommand
- type StopExperimentDeps
- type Transactor
- type Transitions
- func (t *Transitions) Apply(ctx context.Context, project workspace.ProjectID, key string, ...) error
- func (t *Transitions) Current(ctx context.Context, project workspace.ProjectID, key string) (experiments.Experiment, error)
- func (t *Transitions) Propose(ctx context.Context, project workspace.ProjectID, key string, ...) (experiments.Experiment, error)
- type UniformityCommand
- type UnitTypes
- type UpdateExperiment
- type UpdateExperimentCommand
- type UpdateExperimentDeps
Constants ¶
const AwaitingCodeRemovalDays = 7
AwaitingCodeRemovalDays is how many UTC days, today included, an SDK's evaluation of a stopped experiment's flag keeps it awaiting code removal: a week covers a release cycle, so code that is gone from every deployed version stops being reported within one.
const CheckInterval = 10 * time.Minute
CheckInterval is how often the checks run over every running experiment: often enough that a broken split is caught within the hour, rarely enough that the round stays small beside the traffic it judges.
Variables ¶
var ErrNotFound = errors.New("experiments: not found")
ErrNotFound is what a store answers for an entity it does not hold.
Functions ¶
This section is empty.
Types ¶
type AcknowledgeAlert ¶
type AcknowledgeAlert struct {
// contains filtered or unexported fields
}
AcknowledgeAlert hides an alert until it clears.
func NewAcknowledgeAlert ¶
func NewAcknowledgeAlert(d AcknowledgeAlertDeps) *AcknowledgeAlert
NewAcknowledgeAlert returns the handler.
func (*AcknowledgeAlert) Handle ¶
func (h *AcknowledgeAlert) Handle(ctx context.Context, cmd AcknowledgeAlertCommand) (AlertView, error)
Handle acknowledges the alert and returns it. The first acknowledgement is recorded and kept; a later one changes and records nothing. An alert carries no version: acknowledging is the same whoever does it first, so no write is lost by two members doing it at once.
type AcknowledgeAlertCommand ¶
type AcknowledgeAlertCommand struct {
Project workspace.ProjectID
Key string
Alert experiments.AlertID
Request governance.Request
}
AcknowledgeAlertCommand acknowledges the alert Alert of the experiment keyed Key.
type AcknowledgeAlertDeps ¶
type AcknowledgeAlertDeps struct {
Tx Transactor
Store AlertStore
Recorder Recorder
}
AcknowledgeAlertDeps are what AcknowledgeAlert runs on.
type AlertReader ¶
type AlertReader interface {
Reader
// Alerts returns experiment's alerts, the most recently raised first;
// active, when not nil, keeps only the active (true) or the cleared
// (false) ones.
Alerts(ctx context.Context, experiment experiments.ExperimentID, active *bool) ([]AlertView, error)
}
AlertReader reads an experiment's alerts.
type AlertStore ¶
type AlertStore interface {
Reader
// AlertOf returns experiment's alert alert, held until the unit of
// work ends, or ErrNotFound.
AlertOf(ctx context.Context, experiment experiments.ExperimentID, alert experiments.AlertID) (AlertView, error)
// SaveAlert stores a, new or changed.
SaveAlert(ctx context.Context, a experiments.Alert) error
}
AlertStore reads and changes one alert.
type AlertView ¶
type AlertView struct {
experiments.Alert
EnvironmentKey *string
}
AlertView is an alert as it is read, with the key of its environment, nil for one about the experiment as a whole.
type ArchiveExperiment ¶
type ArchiveExperiment struct {
// contains filtered or unexported fields
}
ArchiveExperiment archives a draft or stopped experiment.
func NewArchiveExperiment ¶
func NewArchiveExperiment(d ArchiveExperimentDeps) *ArchiveExperiment
NewArchiveExperiment returns the handler.
func (*ArchiveExperiment) Handle ¶
func (h *ArchiveExperiment) Handle(ctx context.Context, cmd ExperimentCommand) (experiments.Experiment, error)
Handle archives the experiment and returns it archived. Neither a draft nor a stopped experiment is in any ruleset, so no ruleset moves.
type ArchiveExperimentDeps ¶
type ArchiveExperimentDeps struct {
Tx Transactor
Projects ProjectLocker
Store ExperimentUpdater
Recorder Recorder
}
ArchiveExperimentDeps are what ArchiveExperiment runs on.
type AuditLog ¶
type AuditLog interface {
Record(ctx context.Context, e governance.Entry) error
}
AuditLog records the audit entry of a change, in the unit of work of the change.
type CheckStore ¶
type CheckStore interface {
// SaveSampleRatio stores r, checked at, as the latest check of
// experiment in environment, final when nothing is left to wait for.
SaveSampleRatio(ctx context.Context, experiment experiments.ExperimentID, environment workspace.EnvironmentID,
r experiments.SampleRatio, at time.Time, final bool) error
// ActiveAlert returns the active alert of kind of experiment in
// environment, nil for the experiment as a whole, held until the unit
// of work ends; nil when there is none.
ActiveAlert(ctx context.Context, experiment experiments.ExperimentID, environment *workspace.EnvironmentID,
kind experiments.AlertKind) (*experiments.Alert, error)
// SaveAlert stores a, new or changed.
SaveAlert(ctx context.Context, a experiments.Alert) error
// ActiveAlerts returns the active alerts of kind of experiment, in
// every environment, held until the unit of work ends.
ActiveAlerts(ctx context.Context, experiment experiments.ExperimentID, kind experiments.AlertKind) ([]experiments.Alert, error)
}
CheckStore keeps the checks' results and alerts.
type CheckUniformity ¶
type CheckUniformity struct{}
CheckUniformity runs the uniformity check: the management API and the offline command line run this one handler, so both answer alike. It reads and records nothing, so unit IDs checked offline never leave the machine.
func NewCheckUniformity ¶
func NewCheckUniformity() *CheckUniformity
NewCheckUniformity returns the handler.
func (*CheckUniformity) Handle ¶
func (h *CheckUniformity) Handle(cmd UniformityCommand) (experiments.Uniformity, error)
Handle checks how evenly the bucketing hash spreads cmd's unit IDs, and whether a second salt's buckets are independent of the first's.
type ChecksLock ¶
type ChecksLock interface {
// TryLockChecks takes the checks' lock for one round; held is false
// when another replica holds it. release lets it go.
TryLockChecks(ctx context.Context) (release func(), held bool, err error)
}
ChecksLock keeps two replicas from running the checks at once.
type CloneExperiment ¶
type CloneExperiment struct {
// contains filtered or unexported fields
}
CloneExperiment copies an experiment of any status into a new draft.
func NewCloneExperiment ¶
func NewCloneExperiment(d CloneExperimentDeps) *CloneExperiment
NewCloneExperiment returns the handler.
func (*CloneExperiment) Handle ¶
func (h *CloneExperiment) Handle(ctx context.Context, cmd CloneExperimentCommand) (experiments.Experiment, error)
Handle creates the clone and returns it. It is a draft with new salts and no decision, whatever the source's status, over what the source compared: a rerun never reuses an assignment. It is judged as a create is, so a source whose flag has since been archived cannot be cloned. The owner is the calling member, the source's for a project token, which acts for nobody.
type CloneExperimentCommand ¶
type CloneExperimentCommand struct {
Project workspace.ProjectID
Source string
Key string
Name *string
Caller *access.MemberID
Request governance.Request
}
CloneExperimentCommand clones the experiment Source of Project as Key. Name is the clone's, the source's when nil; Caller is the member making the request, nil for a project token.
type CloneExperimentDeps ¶
type CloneExperimentDeps struct {
Tx Transactor
Projects ProjectLocker
Store ExperimentCloner
Flags Flags
UnitTypes UnitTypes
Rollouts RolloutSalts
Owners Owners
Recorder Recorder
}
CloneExperimentDeps are what CloneExperiment runs on.
type CreateExperiment ¶
type CreateExperiment struct {
// contains filtered or unexported fields
}
CreateExperiment creates an experiment as a draft, with two salts no other experiment or rollout of the project uses. A draft changes nothing SDKs receive, so no ruleset moves.
func NewCreateExperiment ¶
func NewCreateExperiment(d CreateExperimentDeps) *CreateExperiment
NewCreateExperiment returns the handler.
func (*CreateExperiment) Handle ¶
func (h *CreateExperiment) Handle(ctx context.Context, cmd CreateExperimentCommand) (experiments.Experiment, error)
Handle creates the experiment and returns it.
type CreateExperimentCommand ¶
type CreateExperimentCommand struct {
Project workspace.ProjectID
Key string
Name string
Hypothesis string
Owner *access.MemberID
Caller *access.MemberID
Tags []string
Flag string
UnitType string
Variations []experiments.Weight
TrafficAllocation *int
ExpectedEndAt *time.Time
Request governance.Request
}
CreateExperimentCommand is the experiment to create. Owner is the member the request names, nil when it names none; Caller is the member making the request, nil for a project token.
type CreateExperimentDeps ¶
type CreateExperimentDeps struct {
Tx Transactor
Projects ProjectLocker
Store ExperimentCreator
Flags Flags
UnitTypes UnitTypes
Rollouts RolloutSalts
Owners Owners
Recorder Recorder
}
CreateExperimentDeps are what CreateExperiment runs on.
type DeleteExperiment ¶
type DeleteExperiment struct {
// contains filtered or unexported fields
}
DeleteExperiment deletes a draft experiment.
func NewDeleteExperiment ¶
func NewDeleteExperiment(d DeleteExperimentDeps) *DeleteExperiment
NewDeleteExperiment returns the handler.
func (*DeleteExperiment) Handle ¶
func (h *DeleteExperiment) Handle(ctx context.Context, cmd ExperimentCommand) error
Handle deletes the experiment, recording it as it was. A draft is in no ruleset, so no ruleset moves, but a rule of a flag may serve it by its key, and deleting it is refused while one does; the change requests proposing to start it are superseded by the deletion.
type DeleteExperimentDeps ¶
type DeleteExperimentDeps struct {
Tx Transactor
Projects ProjectLocker
Store ExperimentDeleter
Holders Holders
Recorder Recorder
}
DeleteExperimentDeps are what DeleteExperiment runs on.
type ExperimentCloner ¶
type ExperimentCloner interface {
Reader
ExperimentCreator
}
ExperimentCloner reads the experiment to clone and stores the clone.
type ExperimentCommand ¶
type ExperimentCommand struct {
Project workspace.ProjectID
Key string
Expected precondition.Version
Request governance.Request
}
ExperimentCommand names the experiment Key of Project, based on the version Expected names.
type ExperimentCreator ¶
type ExperimentCreator interface {
// CreateExperiment refuses a key the project uses as already_exists.
CreateExperiment(ctx context.Context, e experiments.Experiment) error
// ExperimentSalts returns both salts of every experiment of project.
ExperimentSalts(ctx context.Context, project workspace.ProjectID) ([]string, error)
}
ExperimentCreator stores a new experiment and reads the salts of the project's experiments.
type ExperimentDeleter ¶
type ExperimentDeleter interface {
Reader
DeleteExperiment(ctx context.Context, e experiments.ExperimentID) error
}
ExperimentDeleter deletes an experiment.
type ExperimentFilter ¶
type ExperimentFilter struct {
// Status lists the experiments in that status; "" for any.
Status experiments.Status
// Flag lists the experiments comparing the flag with that key; "" for any.
Flag string
// Owner lists the experiments owned by that member; nil for any.
Owner *access.MemberID
// Tag lists the experiments carrying that tag, matched exactly; "" for any.
Tag string
// IncludeArchived lists archived experiments too. They are hidden
// otherwise, unless Status asks for them.
IncludeArchived bool
// PastExpectedEnd lists only the running experiments past their
// expected end, from the UTC day after it.
PastExpectedEnd bool
// AwaitingCodeRemoval lists only the stopped experiments whose flag an
// SDK evaluated after the stop, on one of the last
// AwaitingCodeRemovalDays UTC days, in some environment.
AwaitingCodeRemoval bool
}
ExperimentFilter narrows a list of experiments; every field given applies.
type ExperimentLister ¶
type ExperimentLister interface {
// Experiments returns up to limit experiments of project matching
// filter at now, ordered by key in byte order, whose key is greater
// than after when it is not "".
Experiments(ctx context.Context, project workspace.ProjectID, filter ExperimentFilter, now time.Time, after string, limit int,
) ([]experiments.Experiment, error)
}
ExperimentLister lists experiments.
type ExperimentPage ¶
type ExperimentPage struct {
ExperimentFilter
// After is the key the page starts after, "" for the first page.
After string
Limit int
}
ExperimentPage asks for one page of a project's experiments, by key in byte order.
type ExperimentRules ¶
type ExperimentRules interface {
// ApplyDecision makes every rule of project's flag keyed flag
// serving the experiment keyed experiment serve the variation winner,
// or deletes it when winner is "", in every environment, each
// configuration it changes written and recorded on its own and its
// ruleset moved on, as the member by (nil for a project token) at now in
// req, in the unit of work ctx carries.
ApplyDecision(ctx context.Context, project workspace.ProjectID, flag, experiment, winner string,
by *access.MemberID, now time.Time, req governance.Request) error
}
ExperimentRules rewrites the rules serving an experiment.
type ExperimentUpdater ¶
type ExperimentUpdater interface {
Reader
UpdateExperiment(ctx context.Context, e experiments.Experiment) error
}
ExperimentUpdater stores an experiment's changed definition.
type ExposureActivity ¶
type ExposureActivity interface {
// ConflictTotals returns how many exposures of experiment in
// environment named another variation than their unit's first one,
// and how many units had one.
ConflictTotals(ctx context.Context, environment workspace.EnvironmentID, experiment experiments.ExperimentID) (total, units int64, err error)
// LastExposureAt returns when the server last received, after after
// and at or before at, an exposure of experiment in environment that
// no override decided; nil when it did not. A zero after sets no lower
// bound.
LastExposureAt(ctx context.Context, environment workspace.EnvironmentID, experiment experiments.ExperimentID, after, at time.Time,
) (*time.Time, error)
}
ExposureActivity reads what the exposures of an experiment came to beyond the first exposures.
type FinalExposures ¶ added in v0.3.0
type FinalExposures interface {
// ExposuresReadThrough reports whether the exposure rollup has read
// every exposure received at or before at, so that nothing accepted
// by then still waits for it.
ExposuresReadThrough(ctx context.Context, at time.Time) (bool, error)
// FirstExposureCountsReceivedBy returns the first exposures of
// experiment in environment among the exposures received at or before
// by, by variation, whatever the rollup has read since.
FirstExposureCountsReceivedBy(ctx context.Context, environment workspace.EnvironmentID, experiment experiments.ExperimentID,
by time.Time) (map[string]int64, error)
}
FinalExposures reads the exposures a stopped experiment's final check is over.
type FirstExposures ¶
type FirstExposures interface {
// FirstExposureCounts returns the experiment's first exposures in
// environment, summed over every day, by variation.
FirstExposureCounts(ctx context.Context, environment workspace.EnvironmentID, experiment experiments.ExperimentID) (map[string]int64, error)
}
FirstExposures reads what the exposure rollup counted of an experiment.
type Flags ¶
type Flags interface {
// ExperimentFlag returns project's flag with key, or ErrNotFound.
ExperimentFlag(ctx context.Context, project workspace.ProjectID, key string) (experiments.FlagFacts, error)
}
Flags reads the flags of a project, as much of them as an experiment needs.
type GetAssignment ¶
type GetAssignment struct {
// contains filtered or unexported fields
}
GetAssignment answers how an experiment treats one unit.
func NewGetAssignment ¶
func NewGetAssignment(store Reader) *GetAssignment
NewGetAssignment returns the handler.
func (*GetAssignment) Handle ¶
func (h *GetAssignment) Handle(ctx context.Context, project workspace.ProjectID, key, unitID string) (experiments.Assignment, error)
Handle returns unitID's assignment in project's experiment with key, from the experiment's own fields whatever its status, or not_found. It reads no event and records nothing.
type GetExperiment ¶
type GetExperiment struct {
// contains filtered or unexported fields
}
GetExperiment reads an experiment.
func NewGetExperiment ¶
func NewGetExperiment(store Reader) *GetExperiment
NewGetExperiment returns the handler.
func (*GetExperiment) Handle ¶
func (h *GetExperiment) Handle(ctx context.Context, project workspace.ProjectID, key string) (experiments.Experiment, error)
Handle returns project's experiment with key, or not_found.
type GetSampleRatio ¶
type GetSampleRatio struct {
// contains filtered or unexported fields
}
GetSampleRatio reads an experiment's latest sample-ratio check in one environment.
func NewGetSampleRatio ¶
func NewGetSampleRatio(store SampleRatioReader) *GetSampleRatio
NewGetSampleRatio returns the handler.
func (*GetSampleRatio) Handle ¶
func (h *GetSampleRatio) Handle(ctx context.Context, project workspace.ProjectID, key, environment string) (*SampleRatioState, error)
Handle returns the latest check of project's experiment keyed key in the environment keyed environment, nil before the first, or not_found.
type Holders ¶
type Holders interface {
// HoldingEnvironments returns the environments of project whose
// configuration of some flag has a rule serving the experiment keyed
// key.
HoldingEnvironments(ctx context.Context, project workspace.ProjectID, key string) ([]workspace.EnvironmentID, error)
// HoldingConfigurations returns, as references, the configurations of
// project, one per flag and environment, that have a rule serving the
// experiment keyed key, ordered by flag key, then by the environments'
// order.
HoldingConfigurations(ctx context.Context, project workspace.ProjectID, key string) ([]flags.Reference, error)
}
Holders reads where an experiment is served.
type ImportCommand ¶ added in v0.3.0
type ImportCommand struct {
Project workspace.ProjectID
Key string
Name string
Hypothesis string
Owner *access.MemberID
Caller *access.MemberID
Tags []string
Flag string
UnitType string
Variations []experiments.Weight
TrafficAllocation int
// InclusionSalt and VariationSalt are the document's; a new draft is given
// the one it lacks, and an experiment that exists keeps it.
InclusionSalt string
VariationSalt string
Status experiments.Status
ExpectedEndAt *time.Time
StartedAt *time.Time
StoppedAt *time.Time
ArchivedAt *time.Time
Decision *experiments.Decision
// Avoid are salts the import is about to give rollouts, which no salt it
// draws for the experiment may be.
Avoid []string
Request governance.Request
}
ImportCommand is an experiment as a document gives it. Owner is the member the document's owner resolved to, nil when it resolved to none: the importing member, Caller, owns a new experiment then, and an existing one keeps its owner.
type ImportEffect ¶ added in v0.3.0
type ImportEffect struct {
// Changed is false for a write that changed nothing, which stores and
// records nothing.
Changed bool
// Environments are the environments whose ruleset the ordinary write
// would have moved on: the ones holding a rule that serves a running
// experiment whose traffic allocation grew.
Environments []workspace.EnvironmentID
}
ImportEffect is what a write of the importer did.
type ImportStore ¶ added in v0.3.0
type ImportStore interface {
ExperimentCreator
ExperimentUpdater
ExperimentDeleter
// DeferSaltChecks lets an experiment of the project take, until
// CheckSalts or the end of the unit of work, a salt another still has:
// an import may hand one draft's salt to another experiment, or swap two
// drafts' salts, in whatever order it writes them.
DeferSaltChecks(ctx context.Context) error
// CheckSalts refuses, from now on, two experiments of a project sharing
// a salt.
CheckSalts(ctx context.Context) error
}
ImportStore is what the import writes experiments with.
type Importer ¶ added in v0.3.0
type Importer struct {
// contains filtered or unexported fields
}
Importer writes the experiments of a project document. It is the import's port into the context: each method is the ordinary write of the experiment, run in the unit of work the caller's context carries and recorded as the ordinary write is, except that it moves no ruleset on but says which environments the ordinary write would have, since the import does that once per environment when it is done, and that it takes what no client write may set: the status, both salts, the timestamps and the decision a document names, which is what keeps a unit in its assignment in a copy. It never moves an experiment through its status: an experiment that exists changes only as an edit of its status allows.
func NewImporter ¶ added in v0.3.0
func NewImporter(d ImporterDeps) *Importer
NewImporter returns the importer.
func (*Importer) CheckSalts ¶ added in v0.3.0
CheckSalts checks, once the import has written every experiment, that no two experiments of a project share a salt, which the writes let wait so that one may take a salt another gives up later. Checked here rather than when the unit of work commits, a dry run, which never commits, is checked as the import it previews.
func (*Importer) CheckServed ¶ added in v0.4.0
func (i *Importer) CheckServed(ctx context.Context, project workspace.ProjectID, keys []string) error
CheckServed refuses with in_use, naming them, the configurations that serve one of the experiments keyed keys, once the import has written every configuration, although they belong to a flag other than the experiment's: an import may move a draft to another flag and drop the rules serving it in the same document, which it writes experiments first.
func (*Importer) CreateExperiment ¶ added in v0.3.0
func (i *Importer) CreateExperiment(ctx context.Context, cmd ImportCommand) (ImportEffect, error)
CreateExperiment creates the experiment exactly as the command says, recorded as created.
func (*Importer) DeleteExperiment ¶ added in v0.4.0
func (i *Importer) DeleteExperiment(ctx context.Context, project workspace.ProjectID, key string, leaving []string, req governance.Request) error
DeleteExperiment deletes the draft experiment keyed key as an ordinary request does, recorded as deleted; any other is not_draft or archived. A rule serving it in a configuration of one of the flags keyed leaving, which the import deletes as well, does not keep it.
func (*Importer) UpdateExperiment ¶ added in v0.3.0
func (i *Importer) UpdateExperiment(ctx context.Context, cmd ImportCommand) (ImportEffect, error)
UpdateExperiment changes the experiment keyed Key to what the command says as far as an edit of its status allows, and refuses with frozen what it does not. A growth of a running experiment's traffic allocation is recorded as the allocation change it is and names the environments that hold its rules, as an ordinary edit moves their rulesets on.
type ImporterDeps ¶ added in v0.3.0
type ImporterDeps struct {
Tx Transactor
Projects ProjectLocker
Store ImportStore
Flags Flags
UnitTypes UnitTypes
Rollouts RolloutSalts
Owners Owners
Holders Holders
Recorder Recorder
}
ImporterDeps are what the Importer runs on.
type ListAlerts ¶
type ListAlerts struct {
// contains filtered or unexported fields
}
ListAlerts lists an experiment's alerts.
func NewListAlerts ¶
func NewListAlerts(store AlertReader) *ListAlerts
NewListAlerts returns the handler.
type ListExperiments ¶
type ListExperiments struct {
// contains filtered or unexported fields
}
ListExperiments lists a project's experiments.
func NewListExperiments ¶
func NewListExperiments(store ExperimentLister, c clock.Clock) *ListExperiments
NewListExperiments returns the handler.
func (*ListExperiments) Handle ¶
func (h *ListExperiments) Handle(ctx context.Context, project workspace.ProjectID, page ExperimentPage) ([]experiments.Experiment, *string, error)
Handle returns one page of project's experiments, and the key to start the next page after, nil on the last page.
type Owners ¶
type Owners interface {
// MayOwn reports whether member is an active member holding a grant
// in project, or an instance admin.
MayOwn(ctx context.Context, project workspace.ProjectID, member access.MemberID) (bool, error)
}
Owners judges who may own an experiment.
type PendingFinalChecks ¶ added in v0.3.0
type PendingFinalChecks interface {
// PendingFinalExperiments returns the stopped or archived experiments
// of every project with a sample-ratio result that is not final: an
// experiment archived before its final check is still owed it.
PendingFinalExperiments(ctx context.Context) ([]experiments.Experiment, error)
// PendingFinalEnvironments returns the environments in which
// experiment's sample-ratio result is not final: the ones its stop
// checked.
PendingFinalEnvironments(ctx context.Context, experiment experiments.ExperimentID) ([]workspace.EnvironmentID, error)
}
PendingFinalChecks lists the experiments whose stop took a sample-ratio check that is not final yet.
type ProjectLocker ¶
type ProjectLocker interface {
// LockProject locks the project's row, or answers ErrNotFound when
// there is none.
LockProject(ctx context.Context, project workspace.ProjectID) error
}
ProjectLocker locks a project's row for the unit of work. Every write of the context takes this lock first and no other, in the lock order of the flags context's writes.
type Reader ¶
type Reader interface {
// ExperimentByKey returns project's experiment with key, or ErrNotFound.
ExperimentByKey(ctx context.Context, project workspace.ProjectID, key string) (experiments.Experiment, error)
}
Reader reads experiments.
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder is what every command handler of the context runs on besides its store: the clock a change is timed by, the source its identifiers are drawn from, and the audit log it is recorded in, so a change and its entry carry the same instant.
type RegenerateSalts ¶
type RegenerateSalts struct {
// contains filtered or unexported fields
}
RegenerateSalts draws new salts for a draft experiment.
func NewRegenerateSalts ¶
func NewRegenerateSalts(d RegenerateSaltsDeps) *RegenerateSalts
NewRegenerateSalts returns the handler.
func (*RegenerateSalts) Handle ¶
func (h *RegenerateSalts) Handle(ctx context.Context, cmd ExperimentCommand) (experiments.Experiment, error)
Handle gives the draft two new salts, apart from every salt of the project's experiments (its own old ones included) and rollouts, and returns it. The project's lock is held, so no other write of the project takes a salt meanwhile.
type RegenerateSaltsDeps ¶
type RegenerateSaltsDeps struct {
Tx Transactor
Projects ProjectLocker
Store SaltRegenerator
Rollouts RolloutSalts
Recorder Recorder
}
RegenerateSaltsDeps are what RegenerateSalts runs on.
type RolloutSalts ¶
type RolloutSalts interface {
// RolloutSalts returns the salt of every rollout in every flag
// configuration of project, archived flags included.
RolloutSalts(ctx context.Context, project workspace.ProjectID) ([]string, error)
}
RolloutSalts reads the salts rollouts use.
type Rulesets ¶
type Rulesets interface {
// Environment marks the ruleset of environment changed, in the unit
// of work ctx carries.
Environment(ctx context.Context, environment workspace.EnvironmentID) error
}
Rulesets marks rulesets changed.
type RunChecks ¶
type RunChecks struct {
// contains filtered or unexported fields
}
RunChecks runs the checks of every running experiment once, and takes the final sample-ratio check of every stopped one that waits for it.
func (*RunChecks) Handle ¶
Handle checks every running experiment, then completes the sample-ratio check of every stopped one that is pending, each in a unit of work of its own, so one that fails or runs out of time rolls back alone and the others are still checked. A replica finding another one checking does nothing: a round is for the whole instance, and running it twice would only repeat it.
type RunChecksDeps ¶
type RunChecksDeps struct {
Tx Transactor
Lock ChecksLock
Running RunningExperiments
Pending PendingFinalChecks
Final FinalExposures
// Retention is how long raw exposures are kept: an experiment started
// before it may have lost raw rows its final check would count.
Retention time.Duration
Projects ProjectLocker
Store Reader
Holders Holders
FirstExposures FirstExposures
Exposures ExposureActivity
Checks CheckStore
Recorder Recorder
}
RunChecksDeps are what RunChecks runs on.
type RunningExperiments ¶
type RunningExperiments interface {
// RunningExperiments returns the running experiments of every
// project.
RunningExperiments(ctx context.Context) ([]experiments.Experiment, error)
}
RunningExperiments lists what the checks run over.
type SaltRegenerator ¶
type SaltRegenerator interface {
ExperimentUpdater
// ExperimentSalts returns both salts of every experiment of project.
ExperimentSalts(ctx context.Context, project workspace.ProjectID) ([]string, error)
}
SaltRegenerator stores an experiment with new salts and reads the salts the project's experiments hold.
type SampleRatioReader ¶
type SampleRatioReader interface {
Reader
// EnvironmentByKey returns project's environment keyed key, or
// ErrNotFound.
EnvironmentByKey(ctx context.Context, project workspace.ProjectID, key string) (workspace.EnvironmentID, error)
// SampleRatioOf returns the latest sample-ratio check of experiment in
// environment, nil before the first.
SampleRatioOf(ctx context.Context, experiment experiments.ExperimentID, environment workspace.EnvironmentID) (*SampleRatioState, error)
}
SampleRatioReader reads the latest sample-ratio checks.
type SampleRatioState ¶
type SampleRatioState struct {
experiments.SampleRatio
CheckedAt time.Time
Active bool
Final bool
}
SampleRatioState is the latest sample-ratio check of an experiment in one environment, when it ran, whether a sample-ratio alert is active there, and whether it is the check the experiment keeps: the stop's own is not, until the final check completes it.
type SetDecisionNote ¶
type SetDecisionNote struct {
// contains filtered or unexported fields
}
SetDecisionNote changes the note of a stopped experiment's decision.
func NewSetDecisionNote ¶
func NewSetDecisionNote(d SetDecisionNoteDeps) *SetDecisionNote
NewSetDecisionNote returns the handler.
func (*SetDecisionNote) Handle ¶
func (h *SetDecisionNote) Handle(ctx context.Context, cmd SetDecisionNoteCommand) (experiments.Experiment, error)
Handle sets the note and returns the experiment as it is after; the same note stores and records nothing. The note is in no ruleset.
type SetDecisionNoteCommand ¶
type SetDecisionNoteCommand struct {
Experiment ExperimentCommand
Note string
}
SetDecisionNoteCommand sets the note of the decision of the experiment Experiment names to Note, "" clearing it.
type SetDecisionNoteDeps ¶
type SetDecisionNoteDeps struct {
Tx Transactor
Projects ProjectLocker
Store ExperimentUpdater
Recorder Recorder
}
SetDecisionNoteDeps are what SetDecisionNote runs on.
type StartExperiment ¶
type StartExperiment struct {
// contains filtered or unexported fields
}
StartExperiment starts a draft experiment.
func NewStartExperiment ¶
func NewStartExperiment(d StartExperimentDeps) *StartExperiment
NewStartExperiment returns the handler.
func (*StartExperiment) Handle ¶
func (h *StartExperiment) Handle(ctx context.Context, cmd ExperimentCommand) (experiments.Experiment, error)
Handle starts the experiment and returns it running. In the same unit of work it moves on the ruleset of every environment holding a rule serving it, so every SDK of those environments is given the experiment from the same commit, and none of the others is moved. An experiment no environment holds starts all the same.
The handler runs in the unit of work ctx carries when there is one, so a caller applying a start together with its own write commits or rolls back both at once.
type StartExperimentDeps ¶
type StartExperimentDeps struct {
Tx Transactor
Projects ProjectLocker
Store ExperimentUpdater
Flags Flags
UnitTypes UnitTypes
Holders Holders
Rulesets Rulesets
Recorder Recorder
}
StartExperimentDeps are what StartExperiment runs on.
type StopExperiment ¶
type StopExperiment struct {
// contains filtered or unexported fields
}
StopExperiment stops a running experiment with a decision.
func NewStopExperiment ¶
func NewStopExperiment(d StopExperimentDeps) *StopExperiment
NewStopExperiment returns the handler.
func (*StopExperiment) Handle ¶
func (h *StopExperiment) Handle(ctx context.Context, cmd StopExperimentCommand) (experiments.Experiment, error)
Handle stops the experiment and returns it stopped. In the same unit of work every rule serving it, in every environment, serves the winner in its place or is deleted, and each environment whose configuration changed has its ruleset moved on, so every SDK stops assigning the experiment from the same commit that records the decision. The final sample-ratio check is taken there too, in the environments holding the experiment's rule until the decision rewrites it; nothing checks the experiment again, so it is the result the experiment keeps. The stop clears the alerts it ends, past the expected end and without exposures.
type StopExperimentCommand ¶
type StopExperimentCommand struct {
Experiment ExperimentCommand
Decision experiments.Decision
Caller *access.MemberID
}
StopExperimentCommand stops the experiment Experiment names with Decision. Caller is the member stopping it, nil for a project token, who is recorded as the writer of every configuration the stop rewrites.
type StopExperimentDeps ¶
type StopExperimentDeps struct {
Tx Transactor
Projects ProjectLocker
Store ExperimentUpdater
Rules ExperimentRules
Holders Holders
FirstExposures FirstExposures
Checks CheckStore
Recorder Recorder
}
StopExperimentDeps are what StopExperiment runs on.
type Transactor ¶
Transactor runs a unit of work.
type Transitions ¶
type Transitions struct {
// contains filtered or unexported fields
}
Transitions are an experiment's transitions as a change request proposes, bases itself on and applies them: checked as the transition itself checks them, read, and run by the transition's own handler.
func NewTransitions ¶
func NewTransitions(store Reader, start *StartExperiment, stop *StopExperiment, update *UpdateExperiment) *Transitions
NewTransitions returns the transitions run by start, stop and update, reading experiments from store.
func (*Transitions) Apply ¶
func (t *Transitions) Apply(ctx context.Context, project workspace.ProjectID, key string, tr experiments.Transition, baseVersion int64, by *access.MemberID, req governance.Request, ) error
Apply runs tr on project's experiment keyed key, based on its version baseVersion, in the unit of work ctx carries, through the handler a direct call runs, so the transition, the rules it rewrites and the rulesets it moves on commit with the change request's application: a refusal rolls it back. by is the member applying, nil for a project token or the system, recorded as the writer of the configurations a stop rewrites; req is who makes the change, for its audit entries.
func (*Transitions) Current ¶
func (t *Transitions) Current(ctx context.Context, project workspace.ProjectID, key string) (experiments.Experiment, error)
Current returns project's experiment keyed key, or not_found, read in the unit of work ctx carries.
func (*Transitions) Propose ¶
func (t *Transitions) Propose(ctx context.Context, project workspace.ProjectID, key string, tr experiments.Transition, ) (experiments.Experiment, error)
Propose returns project's experiment keyed key, or the refusal running tr on it now would get, writing nothing, so a change request that could never be applied is refused when it is proposed and not at review.
type UniformityCommand ¶
UniformityCommand asks for a uniformity check. A nil Salt draws a random one in an experiment salt's form; a nil Bins groups the buckets into the default 100 bins.
type UnitTypes ¶
type UnitTypes interface {
// UnitTypes returns the project's unit types.
UnitTypes(ctx context.Context, project workspace.ProjectID) ([]workspace.UnitType, error)
}
UnitTypes reads the unit types a project declares.
type UpdateExperiment ¶
type UpdateExperiment struct {
// contains filtered or unexported fields
}
UpdateExperiment changes an experiment's definition.
func NewUpdateExperiment ¶
func NewUpdateExperiment(d UpdateExperimentDeps) *UpdateExperiment
NewUpdateExperiment returns the handler.
func (*UpdateExperiment) Handle ¶
func (h *UpdateExperiment) Handle(ctx context.Context, cmd UpdateExperimentCommand) (experiments.Experiment, error)
Handle applies the change and returns the experiment as it is after it. The change is validated first, then judged against the version it was based on; a change to the values the experiment already has stores and records nothing. A draft is in no ruleset, and a running experiment's description is in none either, so neither moves a ruleset; a running experiment's traffic allocation is embedded in its holders' rulesets, so growing it moves exactly those on, and is recorded as the allocation change it is.
type UpdateExperimentCommand ¶
type UpdateExperimentCommand struct {
Project workspace.ProjectID
Key string
Change experiments.Change
Owner *access.MemberID
Expected precondition.Version
Request governance.Request
}
UpdateExperimentCommand is a change to the experiment Key of Project, based on the version Expected names. Owner is the new owner the change names, if any; Change.Owner, Change.Flag and Change.DeclaredUnitTypes are the handler's to fill in.
type UpdateExperimentDeps ¶
type UpdateExperimentDeps struct {
Tx Transactor
Projects ProjectLocker
Store ExperimentUpdater
Flags Flags
UnitTypes UnitTypes
Owners Owners
Holders Holders
Rulesets Rulesets
Recorder Recorder
}
UpdateExperimentDeps are what UpdateExperiment runs on.