Documentation ¶
Index ¶
- type Constraint
- type Constraints
- type CustomSegmenter
- func (s *CustomSegmenter) ConvertCustomSegmenterValues(segmenterTypes map[string]schema.SegmenterType, ...) error
- func (s *CustomSegmenter) ConvertToTypedValues(segmenterTypes map[string]schema.SegmenterType) error
- func (s *CustomSegmenter) FromStorageSchema(segmenterTypes map[string]schema.SegmenterType) error
- func (s *CustomSegmenter) GetBaseSegmenter() (segmenters.Segmenter, error)
- func (s *CustomSegmenter) GetConfiguration() (*_segmenters.SegmenterConfiguration, error)
- func (s *CustomSegmenter) GetExperimentVariables() *_segmenters.ListExperimentVariables
- func (s *CustomSegmenter) GetName() string
- func (s *CustomSegmenter) GetType() _segmenters.SegmenterValueType
- func (s *CustomSegmenter) IsValidType(inputValues []*_segmenters.SegmenterValue) bool
- func (s *CustomSegmenter) ToApiSchema() schema.Segmenter
- func (s *CustomSegmenter) ToStorageSchema(segmenterTypes map[string]schema.SegmenterType) error
- func (s *CustomSegmenter) ValidateConstraintValues() error
- func (s *CustomSegmenter) ValidateSegmenterAndConstraints(segment map[string]*_segmenters.ListSegmenterValue) error
- func (s *CustomSegmenter) ValidateSegmenterNotPreRequisiteOfItself() error
- type Experiment
- type ExperimentField
- type ExperimentHistory
- type ExperimentSegment
- func (s *ExperimentSegment) Scan(value interface{}) error
- func (s ExperimentSegment) ToApiSchema(segmentersType map[string]schema.SegmenterType) schema.ExperimentSegment
- func (s ExperimentSegment) ToProtoSchema(segmenterTypes map[string]schema.SegmenterType) map[string]*_segmenters.ListSegmenterValue
- func (s ExperimentSegment) ToRawSchema(segmentersType map[string]schema.SegmenterType) (ExperimentSegmentRaw, error)
- func (s ExperimentSegment) Value() (driver.Value, error)
- type ExperimentSegmentRaw
- type ExperimentStatus
- type ExperimentTier
- type ExperimentTreatment
- type ExperimentTreatments
- type ExperimentType
- type ExperimentationConfig
- type ID
- type Model
- type Options
- type PreRequisite
- type Project
- type ProjectSegmenters
- type ProjectSettings
- type Rule
- type Segment
- type SegmentField
- type SegmentHistory
- type SegmenterValueType
- type Settings
- type Treatment
- type TreatmentConfig
- type TreatmentField
- type TreatmentHistory
- type TreatmentSchema
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Constraint ¶
type Constraint struct { PreRequisites []PreRequisite `json:"pre_requisites"` AllowedValues []interface{} `json:"allowed_values"` Options *Options `json:"options"` }
func (*Constraint) ToApiSchema ¶
func (c *Constraint) ToApiSchema() schema.Constraint
type Constraints ¶
type Constraints []Constraint
func (*Constraints) Scan ¶
func (ct *Constraints) Scan(value interface{}) error
type CustomSegmenter ¶
type CustomSegmenter struct { Model // ProjectID is the id of the MLP project ProjectID ID `json:"project_id" gorm:"primary_key"` // Name is the human-readable name of the segmenter. This must be unique across global and project segmenters. Name string `json:"name" gorm:"primary_key"` // Type of the segmenter's values. All values of a segmenter should be of the same type. Type SegmenterValueType `json:"type" validate:"notBlank"` // Additional information about segmenter Description *string `json:"description"` // Required represents whether the segmenter must be chosen in an experiment Required bool `json:"required"` // MultiValued represents whether multiple values of the segmenter can be // chosen in an experiment. Only single-valued segmenters can act as // pre-requisites. MultiValued bool `json:"multi_valued"` // A map of the segmenter values (human-readable name -> internal value) Options *Options `json:"options"` // Constraints captures an optional list of rules. Each constraint has one or // more pre-requisite conditions, which when satisfied, narrows the list of // available values for the current segmenter. If none of the constraints are // satisfied, all values of the segmenter described by the options field may // be applicable. Constraints *Constraints `json:"constraints"` }
func NewCustomSegmenter ¶
func NewCustomSegmenter( projectId ID, name string, segmenterType SegmenterValueType, description *string, required bool, multiValued bool, options *Options, constraints *Constraints, segmenterTypes map[string]schema.SegmenterType, ) (*CustomSegmenter, error)
NewCustomSegmenter creates a new CustomSegmenter object and ensures that its segmenter values are all of the correct type specified
func (*CustomSegmenter) ConvertCustomSegmenterValues ¶
func (s *CustomSegmenter) ConvertCustomSegmenterValues( segmenterTypes map[string]schema.SegmenterType, conversionFunction func(interface{}, SegmenterValueType) (interface{}, error), ) error
func (*CustomSegmenter) ConvertToTypedValues ¶
func (s *CustomSegmenter) ConvertToTypedValues(segmenterTypes map[string]schema.SegmenterType) error
ConvertToTypedValues converts a CustomSegmenter's segmenter values that are untyped to the type specified in the Type field. As this method also indirectly validates the type of each value, it is also used to validate unknown segmenter value types (i.e. validate values passed in as user input with respect to the specified type)
func (*CustomSegmenter) FromStorageSchema ¶
func (s *CustomSegmenter) FromStorageSchema(segmenterTypes map[string]schema.SegmenterType) error
FromStorageSchema converts a CustomSegmenter's segmenter value types from strings to the type specified
func (*CustomSegmenter) GetBaseSegmenter ¶
func (s *CustomSegmenter) GetBaseSegmenter() (segmenters.Segmenter, error)
GetBaseSegmenter returns a BaseSegmenter object (just as how global segmenters are registered) constructed using data contained in the custom segmenter
func (*CustomSegmenter) GetConfiguration ¶
func (s *CustomSegmenter) GetConfiguration() (*_segmenters.SegmenterConfiguration, error)
func (*CustomSegmenter) GetExperimentVariables ¶
func (s *CustomSegmenter) GetExperimentVariables() *_segmenters.ListExperimentVariables
func (*CustomSegmenter) GetName ¶
func (s *CustomSegmenter) GetName() string
func (*CustomSegmenter) GetType ¶
func (s *CustomSegmenter) GetType() _segmenters.SegmenterValueType
func (*CustomSegmenter) IsValidType ¶
func (s *CustomSegmenter) IsValidType(inputValues []*_segmenters.SegmenterValue) bool
func (*CustomSegmenter) ToApiSchema ¶
func (s *CustomSegmenter) ToApiSchema() schema.Segmenter
ToApiSchema converts the configured segmenter DB model to a format compatible with the OpenAPI specifications.
func (*CustomSegmenter) ToStorageSchema ¶
func (s *CustomSegmenter) ToStorageSchema(segmenterTypes map[string]schema.SegmenterType) error
ToStorageSchema converts a CustomSegmenter's segmenter value types to strings for storing in the database
func (*CustomSegmenter) ValidateConstraintValues ¶
func (s *CustomSegmenter) ValidateConstraintValues() error
ValidateConstraintValues checks if all the allowed values and options of all the constraints in the segmenter are present within the options specified. If no options or no constraints are specified, this check passes.
func (*CustomSegmenter) ValidateSegmenterAndConstraints ¶
func (s *CustomSegmenter) ValidateSegmenterAndConstraints(segment map[string]*_segmenters.ListSegmenterValue) error
func (*CustomSegmenter) ValidateSegmenterNotPreRequisiteOfItself ¶
func (s *CustomSegmenter) ValidateSegmenterNotPreRequisiteOfItself() error
ValidateSegmenterNotPreRequisiteOfItself checks if all the segmenter names of all the prerequisites specified for all the constraints in the segmenter do not refer to the actual segmenter's name.
type Experiment ¶
type Experiment struct { Model // ID is the id of the Experiment ID ID `json:"id" gorm:"primary_key"` // ProjectID is the id of the project that this client belongs to, // as retrieved from the MLP API. ProjectID ID `json:"project_id"` // Version is the version number of the experiment, starts at 1 for each experiment. Version int64 `json:"version"` // Name is the experiment's name Name string `json:"name"` // Description is an optional value that has additional info on the experiment Description *string `json:"description"` // Type captures the experiment's type Type ExperimentType `json:"type"` // Interval holds the switchback interval in minutes Interval *int32 `json:"interval"` // Tier holds the priority of the experiment Tier ExperimentTier `json:"tier"` // Treatments holds the experiment treatment configurations Treatments ExperimentTreatments `json:"treatments"` // Segment holds the combination of segmenters that the experiment applies to Segment ExperimentSegment `json:"segment"` // Status is the experiment's status Status ExperimentStatus `json:"status"` // StartTime describes the time at which an experiment starts StartTime time.Time `json:"start_time"` // EndTime describes the time at which an experiment ends EndTime time.Time `json:"end_time"` // UpdatedBy holds the details of the last person/job that updated the experiment UpdatedBy string `json:"updated_by"` }
func (*Experiment) AfterFind ¶
func (e *Experiment) AfterFind(tx *gorm.DB) error
AfterFind sets the retrieved start and end times to be in UTC as opposed to Local. This is needed for integration tests as the new version of Gorm doesn't respect the timezone info in the connection string anymore.
func (*Experiment) ToApiSchema ¶
func (e *Experiment) ToApiSchema(segmentersType map[string]schema.SegmenterType, fields ...ExperimentField) schema.Experiment
ToApiSchema converts the experiment DB model to a format compatible with the OpenAPI specifications.
func (*Experiment) ToProtoSchema ¶
func (e *Experiment) ToProtoSchema(segmentersType map[string]schema.SegmenterType) (*_pubsub.Experiment, error)
ToProtoSchema converts the experiment DB model to a format compatible with the Protobuf specifications.
type ExperimentField ¶
type ExperimentField string
const ( ExperimentFieldEndTime ExperimentField = "end_time" ExperimentFieldId ExperimentField = "id" ExperimentFieldName ExperimentField = "name" ExperimentFieldStartTime ExperimentField = "start_time" ExperimentFieldStatusFriendly ExperimentField = "status_friendly" // ExperimentFieldStatus is only used for querying the db because status_friendly does not exist as a column ExperimentFieldStatus ExperimentField = "status" ExperimentFieldTier ExperimentField = "tier" ExperimentFieldTreatments ExperimentField = "treatments" ExperimentFieldType ExperimentField = "type" ExperimentFieldUpdatedAt ExperimentField = "updated_at" )
Defines values for ExperimentField.
type ExperimentHistory ¶
type ExperimentHistory struct { // CreatedAt - the current value of the UpdatedAt timestamp of the experiment. // This is effectively the time when the version was created. // UpdatedAt - the time of creation of the experiment history record. // The experiment history record is immutable. Model // ID is the id of the ExperimentHistory record ID ID `json:"id" gorm:"primary_key"` // ExperimentID is the id of the experiment whose version this record represents ExperimentID ID `json:"experiment_id"` // Version is the version number of the experiment, starts at 1 for each experiment. Version int64 `json:"version"` // The following values are copied from the experiment record at the time of versioning Name string `json:"name"` Description *string `json:"description"` Type ExperimentType `json:"type"` Interval *int32 `json:"interval"` Tier ExperimentTier `json:"tier"` Treatments ExperimentTreatments `json:"treatments"` Segment ExperimentSegment `json:"segment"` Status ExperimentStatus `json:"status"` StartTime time.Time `json:"start_time"` EndTime time.Time `json:"end_time"` UpdatedBy string `json:"updated_by"` }
func (*ExperimentHistory) AfterFind ¶
func (e *ExperimentHistory) AfterFind(tx *gorm.DB) error
AfterFind sets the retrieved start and end times to be in UTC as opposed to Local. This is needed for integration tests as the new version of Gorm doesn't respect the timezone info in the connection string anymore.
func (ExperimentHistory) TableName ¶
func (ExperimentHistory) TableName() string
TableName overrides Gorm's default pluralised name: "experiment_histories"
func (*ExperimentHistory) ToApiSchema ¶
func (e *ExperimentHistory) ToApiSchema(segmentersType map[string]schema.SegmenterType) schema.ExperimentHistory
ToApiSchema converts the experiment history DB model to a format compatible with the OpenAPI specifications.
type ExperimentSegment ¶
func (*ExperimentSegment) Scan ¶
func (s *ExperimentSegment) Scan(value interface{}) error
func (ExperimentSegment) ToApiSchema ¶
func (s ExperimentSegment) ToApiSchema(segmentersType map[string]schema.SegmenterType) schema.ExperimentSegment
ToApiSchema converts all DB string values to appropriate ExperimentSegment values based on registered SegmenterType to be used when returning API response
func (ExperimentSegment) ToProtoSchema ¶
func (s ExperimentSegment) ToProtoSchema(segmenterTypes map[string]schema.SegmenterType) map[string]*_segmenters.ListSegmenterValue
ToProtoSchema converts all DB string values to appropriate ListSegmenterValue based on registered SegmenterType to be used when sending messages to Treatment Service
func (ExperimentSegment) ToRawSchema ¶
func (s ExperimentSegment) ToRawSchema(segmentersType map[string]schema.SegmenterType) (ExperimentSegmentRaw, error)
ToRawSchema converts ExperimentSegment string values from the DB into their actual value types. Optional segmenters will automatically be removed by this method.
type ExperimentSegmentRaw ¶
type ExperimentSegmentRaw map[string]interface{}
func (ExperimentSegmentRaw) ToStorageSchema ¶
func (s ExperimentSegmentRaw) ToStorageSchema(segmenterTypes map[string]schema.SegmenterType) (ExperimentSegment, error)
ToStorageSchema converts raw request ExperimentSegment values to string values for storing in DB
type ExperimentStatus ¶
type ExperimentStatus string
const ( ExperimentStatusActive ExperimentStatus = "active" ExperimentStatusInactive ExperimentStatus = "inactive" )
type ExperimentTier ¶
type ExperimentTier string
const ( ExperimentTierDefault ExperimentTier = "default" ExperimentTierOverride ExperimentTier = "override" )
Defines values for ExperimentTier.
type ExperimentTreatment ¶
type ExperimentTreatments ¶
type ExperimentTreatments []ExperimentTreatment
func (*ExperimentTreatments) Scan ¶
func (t *ExperimentTreatments) Scan(value interface{}) error
func (ExperimentTreatments) ToApiSchema ¶
func (t ExperimentTreatments) ToApiSchema() []schema.ExperimentTreatment
func (ExperimentTreatments) ToProtoSchema ¶
func (t ExperimentTreatments) ToProtoSchema() ([]*_pubsub.ExperimentTreatment, error)
type ExperimentType ¶
type ExperimentType string
const ( ExperimentTypeAB ExperimentType = "A/B" ExperimentTypeSwitchback ExperimentType = "Switchback" )
Defines values for ExperimentType.
type ExperimentationConfig ¶
type ExperimentationConfig struct { // Segmenters is a list of names of segmenters chosen for the project Segmenters ProjectSegmenters `json:"segmenters"` // RandomizationKey is the of the randomization key in the request payload RandomizationKey string `json:"randomization_key"` // S2IDClusteringEnabled determines whether S2ID cluster ID should be used // as the randomization key, for randomized switchback experiments S2IDClusteringEnabled bool `json:"enable_s2id_clustering"` }
func (*ExperimentationConfig) Scan ¶
func (ec *ExperimentationConfig) Scan(value interface{}) error
type Model ¶
type Model struct { // Created timestamp. Populated when the object is saved to the db. CreatedAt time.Time `json:"created_at"` // Last updated timestamp. Updated when the object is updated in the db. UpdatedAt time.Time `json:"updated_at"` }
Model is a struct containing the basic fields for a persisted entity defined in the API.
func (Model) GetCreatedAt ¶
func (Model) GetUpdatedAt ¶
type PreRequisite ¶
type PreRequisite struct { // segmenter_name is the name of the free segmenter. This must be single-valued. SegmenterName string `json:"segmenter_name"` // segmenter_values is the set of values of the pre-requisite segmenter, one // of which must be matched. SegmenterValues []interface{} `json:"segmenter_values"` }
func (*PreRequisite) ToApiSchema ¶
func (p *PreRequisite) ToApiSchema() schema.PreRequisite
type Project ¶
type Project struct { CreatedAt time.Time `json:"created_at"` Id int64 `json:"id"` RandomizationKey string `json:"randomization_key"` Segmenters []string `json:"segmenters"` UpdatedAt time.Time `json:"updated_at"` Username string `json:"username"` }
func (*Project) ToApiSchema ¶
type ProjectSegmenters ¶
type ProjectSettings ¶
type ProjectSettings struct { CreatedAt time.Time `json:"created_at"` EnableS2idClustering bool `json:"enable_s2id_clustering"` Passkey string `json:"passkey"` ProjectId int64 `json:"project_id"` RandomizationKey string `json:"randomization_key"` Segmenters ProjectSegmenters `json:"segmenters"` UpdatedAt time.Time `json:"updated_at"` Username string `json:"username"` }
type Segment ¶
type Segment struct { Model // ID is the id of the Segment ID ID `json:"id" gorm:"primary_key"` // ProjectID is the id of the project that this client belongs to, // as retrieved from the MLP API. ProjectID ID `json:"project_id"` // Name is the segment's name Name string `json:"name"` Segment ExperimentSegment `json:"segment"` // UpdatedBy holds the details of the last person/job that updated the experiment UpdatedBy string `json:"updated_by"` }
func (*Segment) ToApiSchema ¶
func (s *Segment) ToApiSchema(segmentersType map[string]schema.SegmenterType, fields ...SegmentField) schema.Segment
ToApiSchema converts the configured segment DB model to a format compatible with the OpenAPI specifications.
type SegmentField ¶
type SegmentField string
const ( SegmentFieldId SegmentField = "id" SegmentFieldName SegmentField = "name" )
Defines values for SegmentField.
type SegmentHistory ¶
type SegmentHistory struct { // CreatedAt - the current value of the UpdatedAt timestamp of the segment. // This is effectively the time when the version was created. // UpdatedAt - the time of creation of the segment history record. // The segment history record is immutable. Model // ID is the id of the SegmentHistory record ID ID `json:"id" gorm:"primary_key"` // SegmentID is the id of the segment whose version this record represents SegmentID ID `json:"segment_id"` // Version is the version number of the segment, starts at 1 for each segment. Version int64 `json:"version"` // The following values are copied from the segment record at the time of versioning Name string `json:"name"` Segment ExperimentSegment `json:"segment"` UpdatedBy string `json:"updated_by"` }
func (SegmentHistory) TableName ¶
func (SegmentHistory) TableName() string
TableName overrides Gorm's default pluralised name: "segment_histories"
func (*SegmentHistory) ToApiSchema ¶
func (s *SegmentHistory) ToApiSchema(segmentersType map[string]schema.SegmenterType) schema.SegmentHistory
ToApiSchema converts the segment history DB model to a format compatible with the OpenAPI specifications.
type SegmenterValueType ¶
type SegmenterValueType string
SegmenterValueType represents the possible types that segmenter values can take.
const ( SegmenterValueTypeString SegmenterValueType = "STRING" SegmenterValueTypeBool SegmenterValueType = "BOOL" SegmenterValueTypeInteger SegmenterValueType = "INTEGER" SegmenterValueTypeReal SegmenterValueType = "REAL" )
type Settings ¶
type Settings struct { Model // ProjectID is the id of the MLP project ProjectID ID `json:"project_id" gorm:"primary_key;auto_increment:false"` // Username is used for authentication by the Fetch Treatment API Username string `json:"username"` // Passkey is in plaintext and is used for authentication by the Fetch Treatment API Passkey string `json:"passkey"` // Config holds the project-wide experimentation configs, as configured by the user Config *ExperimentationConfig `json:"config"` // TreatmentSchema holds the rules that define the treatment schema TreatmentSchema *TreatmentSchema `json:"treatment_schema"` // ValidationUrl holds the custom validation endpoint defined by the user ValidationUrl *string `json:"validation_url"` }
Settings stores the project's Experimentation settings
func (*Settings) ToApiSchema ¶
func (c *Settings) ToApiSchema() schema.ProjectSettings
ToApiSchema converts the settings DB model to a format compatible with the OpenAPI specifications.
func (*Settings) ToProtoSchema ¶
func (c *Settings) ToProtoSchema() _pubsub.ProjectSettings
type Treatment ¶
type Treatment struct { Model // ID is the id of the Treatment ID ID `json:"id" gorm:"primary_key"` // ProjectID is the id of the project that this client belongs to, // as retrieved from the MLP API. ProjectID ID `json:"project_id"` // Name is the treatment's name Name string `json:"name"` Configuration TreatmentConfig `json:"configuration"` // UpdatedBy holds the details of the last person/job that updated the experiment UpdatedBy string `json:"updated_by"` }
func (*Treatment) ToApiSchema ¶
func (t *Treatment) ToApiSchema(fields ...TreatmentField) schema.Treatment
ToApiSchema converts the configured treatment DB model to a format compatible with the OpenAPI specifications.
type TreatmentConfig ¶
type TreatmentConfig map[string]interface{}
func (*TreatmentConfig) Scan ¶
func (t *TreatmentConfig) Scan(value interface{}) error
type TreatmentField ¶
type TreatmentField string
const ( TreatmentFieldId TreatmentField = "id" TreatmentFieldName TreatmentField = "name" )
Defines values for TreatmentField.
type TreatmentHistory ¶
type TreatmentHistory struct { // CreatedAt - the current value of the UpdatedAt timestamp of the treatment. // This is effectively the time when the version was created. // UpdatedAt - the time of creation of the treatment history record. // The treatment history record is immutable. Model // ID is the id of the TreatmentHistory record ID ID `json:"id" gorm:"primary_key"` // TreatmentID is the id of the treatment whose version this record represents TreatmentID ID `json:"treatment_id"` // Version is the version number of the treatment, starts at 1 for each treatment. Version int64 `json:"version"` // The following values are copied from the treatment record at the time of versioning Name string `json:"name"` Configuration TreatmentConfig `json:"configuration"` UpdatedBy string `json:"updated_by"` }
func (TreatmentHistory) TableName ¶
func (TreatmentHistory) TableName() string
TableName overrides Gorm's default pluralised name: "treatment_histories"
func (*TreatmentHistory) ToApiSchema ¶
func (t *TreatmentHistory) ToApiSchema() schema.TreatmentHistory
ToApiSchema converts the treatment history DB model to a format compatible with the OpenAPI specifications.
type TreatmentSchema ¶
type TreatmentSchema struct {
Rules []Rule `json:"rules" validate:"required,unique=Name,dive,required"`
}
func (*TreatmentSchema) Scan ¶
func (ts *TreatmentSchema) Scan(value interface{}) error
func (*TreatmentSchema) ToOpenApi ¶
func (ts *TreatmentSchema) ToOpenApi() *schema.TreatmentSchema