Documentation ¶
Index ¶
- Constants
- Variables
- func CreateFlagEntityType(db *gorm.DB, key string) error
- func CreateFlagKey(key string) (string, error)
- func GetDB() *gorm.DB
- func NewSQLiteDB(filePath string) *gorm.DB
- func NewTestDB() *gorm.DB
- func PopulateTestDB(flag Flag) *gorm.DB
- func PreloadConstraintsDistribution(db *gorm.DB) *gorm.DB
- func PreloadSegmentsVariants(db *gorm.DB) *gorm.DB
- func SaveFlagSnapshot(db *gorm.DB, flagID uint, updatedBy string)
- type Attachment
- type Constraint
- type ConstraintArray
- type Distribution
- type DistributionArray
- type DistributionDebugLog
- type EvalContext
- type EvalDebugLog
- type EvalResult
- type Flag
- type FlagEntityType
- type FlagEvaluation
- type FlagSnapshot
- type Segment
- type SegmentDebugLog
- type SegmentEvaluation
- type User
- type Variant
Constants ¶
const ( // TotalBucketNum represents how many buckets we can use to determine the consistent hashing // distribution and rollout TotalBucketNum uint = 1000 // PercentMultiplier implies that the multiplier between percentage (100) and TotalBucketNum PercentMultiplier uint = TotalBucketNum / uint(100) )
const SegmentDefaultRank = uint(999)
SegmentDefaultRank is the default rank when we create the segment
Variables ¶
var AutoMigrateTables = []interface{}{ Constraint{}, Distribution{}, FlagSnapshot{}, Flag{}, Segment{}, User{}, Variant{}, FlagEntityType{}, }
AutoMigrateTables stores the entity tables that we can auto migrate in gorm
var OperatorToExprMap = map[string]string{ models.ConstraintOperatorEQ: "==", models.ConstraintOperatorNEQ: "!=", models.ConstraintOperatorLT: "<", models.ConstraintOperatorLTE: "<=", models.ConstraintOperatorGT: ">", models.ConstraintOperatorGTE: ">=", models.ConstraintOperatorEREG: "=~", models.ConstraintOperatorNEREG: "!~", models.ConstraintOperatorIN: "IN", models.ConstraintOperatorNOTIN: "NOT IN", models.ConstraintOperatorCONTAINS: "CONTAINS", models.ConstraintOperatorNOTCONTAINS: "NOT CONTAINS", }
OperatorToExprMap maps from the swagger model operator to condition operator
Functions ¶
func CreateFlagEntityType ¶
CreateFlagEntityType creates the FlagEntityType if not exists
func CreateFlagKey ¶
CreateFlagKey creates the key based on the given key
func NewSQLiteDB ¶
NewSQLiteDB creates a new sqlite db useful for backup exports and unit tests
func PreloadConstraintsDistribution ¶
PreloadConstraintsDistribution preloads constraints and distributions for segment
func PreloadSegmentsVariants ¶
PreloadSegmentsVariants preloads segments and variants for flag
Types ¶
type Attachment ¶
type Attachment map[string]interface{}
Attachment supports dynamic configuration in variant
func (*Attachment) Scan ¶
func (a *Attachment) Scan(value interface{}) error
Scan implements scanner interface
type Constraint ¶
type Constraint struct { gorm.Model SegmentID uint `gorm:"index:idx_constraint_segmentid"` Property string Operator string Value string `sql:"type:text"` }
Constraint is the unit of constraints
func (*Constraint) ToExpr ¶
func (c *Constraint) ToExpr() (conditions.Expr, error)
ToExpr transfer the constraint to conditions.Expr for evaluation
type ConstraintArray ¶
type ConstraintArray []Constraint
ConstraintArray is an array of Constraint
func (ConstraintArray) ToExpr ¶
func (cs ConstraintArray) ToExpr() (conditions.Expr, error)
ToExpr maps ConstraintArray to expr by joining 'AND'
type Distribution ¶
type Distribution struct { gorm.Model SegmentID uint `gorm:"index:idx_distribution_segmentid"` VariantID uint `gorm:"index:idx_distribution_variantid"` VariantKey string Percent uint // Percent is an uint from 0 to 100, percent is always derived from Bitmap Bitmap string `sql:"type:text" json:"-"` }
Distribution is the struct represents distribution under segment and links to variant
type DistributionArray ¶
type DistributionArray struct { VariantIDs []uint PercentsAccumulated []int // useful for binary search to find the rollout variant }
DistributionArray is useful for faster evalution
type DistributionDebugLog ¶
type DistributionDebugLog struct { BucketNum uint DistributionArray DistributionArray VariantID uint RolloutPercent uint }
DistributionDebugLog is useful for making debug logs
type EvalContext ¶
type EvalContext struct { EntityID string EntityType string EntityContext map[string]interface{} EnableDebug bool }
EvalContext represents the context we can evaluate and log
type EvalDebugLog ¶
type EvalDebugLog struct { SegmentDebugLogs []SegmentDebugLog Msg string }
EvalDebugLog is the debugging log of evaluation
type EvalResult ¶
type EvalResult struct { FlagID uint SegmentID uint VariantID uint EvalContext EvalContext Timestamp time.Time EvalDebugLog *EvalDebugLog }
EvalResult represents the result of the evaluation
type Flag ¶
type Flag struct { gorm.Model Key string `gorm:"type:varchar(64);unique_index:idx_flag_key"` Description string `sql:"type:text"` CreatedBy string UpdatedBy string Enabled bool Segments []Segment Variants []Variant SnapshotID uint `json:"-"` DataRecordsEnabled bool EntityType string FlagEvaluation FlagEvaluation `gorm:"-" json:"-"` }
Flag is the unit of flags
func (*Flag) PrepareEvaluation ¶
PrepareEvaluation prepares the information for evaluation
type FlagEntityType ¶
type FlagEntityType struct { gorm.Model Key string `gorm:"type:varchar(64);unique_index:flag_entity_type_key"` }
FlagEntityType is the entity_type that will overwrite into evaluation logs.
type FlagEvaluation ¶
FlagEvaluation is a struct that holds the necessary info for evaluation
type FlagSnapshot ¶
type FlagSnapshot struct { gorm.Model FlagID uint `gorm:"index:idx_flagsnapshot_flagid"` UpdatedBy string Flag []byte `sql:"type:text"` }
FlagSnapshot is the snapshot of a flag Any change of the flag will create a new snapshot
type Segment ¶
type Segment struct { gorm.Model FlagID uint `gorm:"index:idx_segment_flagid"` Description string `sql:"type:text"` Rank uint RolloutPercent uint Constraints ConstraintArray Distributions []Distribution // Purely for evaluation SegmentEvaluation SegmentEvaluation `gorm:"-" json:"-"` }
Segment is the unit of segmentation
func (*Segment) PrepareEvaluation ¶
PrepareEvaluation prepares the segment for evaluation by parsing constraints and denormalize distributions
type SegmentDebugLog ¶
SegmentDebugLog is the segmebnt level of debugging logs
type SegmentEvaluation ¶
type SegmentEvaluation struct { ConditionsExpr conditions.Expr DistributionArray DistributionArray }
SegmentEvaluation is a struct that holds the necessary info for evaluation