evaluation

package
v0.1.25 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2024 License: Apache-2.0 Imports: 15 Imported by: 6

Documentation

Index

Constants

View Source
const (
	// OneHundred MAX value for bucket
	OneHundred = 100
)

Variables

View Source
var (
	// ErrQueryProviderMissing ...
	ErrQueryProviderMissing = errors.New("query field is missing in evaluator")
	// ErrVariationNotFound ...
	ErrVariationNotFound = errors.New("variation not found")
	// ErrEvaluationFlag ...
	ErrEvaluationFlag = errors.New("error while evaluating flag")
	// ErrFlagKindMismatch ...
	ErrFlagKindMismatch = errors.New("flag kind mismatch")
)
View Source
var (
	ErrNilFlag = errors.New("flag is nil")
)

Functions

func GetNormalizedNumber

func GetNormalizedNumber(identifier string, bucketBy string) int

GetNormalizedNumber returns normalized value with normalizer OneHundred

func GetNormalizedNumberWithNormalizer

func GetNormalizedNumberWithNormalizer(identifier string, bucketBy string, normalizer int) int

GetNormalizedNumberWithNormalizer returns a murmur hash value based on input arguments

func GetStructFieldValue

func GetStructFieldValue(target interface{}, attr string) reflect.Value

GetStructFieldValue returns struct field value or simple value using attr field

Types

type Clause

type Clause struct {
	Attribute string
	ID        string
	Negate    bool
	Op        string
	Value     []string
}

Clause object

func (*Clause) Evaluate

func (c *Clause) Evaluate(target *Target, segments Segments, operator types.ValueType) bool

Evaluate clause using target but it can be used also with segments if Op field is segmentMach

type Clauses

type Clauses []Clause

Clauses slice

func (Clauses) Evaluate

func (c Clauses) Evaluate(target *Target, segments Segments) bool

Evaluate clauses using target but it can be used also with segments if Op field is segmentMach TODO this func can return false because of an error. We need a way to indicate to the caller if this is false because it evaluated false, or because it actually failed to work.

type Distribution

type Distribution struct {
	BucketBy   string
	Variations []WeightedVariation
}

Distribution object used for Percentage Rollout evaluations

func (*Distribution) GetKeyName

func (d *Distribution) GetKeyName(target *Target) string

GetKeyName returns variation identifier based on target

type Evaluation

type Evaluation struct {
	Flag      string
	Variation Variation
}

Evaluation object is in most cases returned value from evaluation methods and contains results of evaluated feature flag for target object

type Evaluator added in v0.0.25

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

Evaluator engine evaluates flag from provided query

func NewEvaluator added in v0.0.25

func NewEvaluator(query Query, postEvalCallback PostEvaluateCallback, logger logger.Logger) (*Evaluator, error)

NewEvaluator constructs evaluator with query instance

func (Evaluator) BoolVariation added in v0.0.25

func (e Evaluator) BoolVariation(identifier string, target *Target, defaultValue bool) (bool, error)

BoolVariation returns boolean evaluation for target

func (Evaluator) Evaluate added in v0.1.4

func (e Evaluator) Evaluate(identifier string, target *Target) (FlagVariation, error)

Evaluate exposes evaluate to the caller.

func (Evaluator) EvaluateAll added in v0.1.5

func (e Evaluator) EvaluateAll(target *Target) (FlagVariations, error)

EvaluateAll evaluates all the flags

func (Evaluator) IntVariation added in v0.0.25

func (e Evaluator) IntVariation(identifier string, target *Target, defaultValue int) (int, error)

IntVariation returns int evaluation for target

func (Evaluator) JSONVariation added in v0.0.25

func (e Evaluator) JSONVariation(identifier string, target *Target,
	defaultValue map[string]interface{}) (map[string]interface{}, error)

JSONVariation returns json evaluation for target

func (Evaluator) NumberVariation added in v0.0.25

func (e Evaluator) NumberVariation(identifier string, target *Target, defaultValue float64) (float64, error)

NumberVariation returns number evaluation for target

func (Evaluator) StringVariation added in v0.0.25

func (e Evaluator) StringVariation(identifier string, target *Target, defaultValue string) (string, error)

StringVariation returns string evaluation for target

type FeatureConfig

type FeatureConfig struct {
	DefaultServe         Serve
	Environment          string
	Feature              string
	Kind                 string
	OffVariation         string
	Prerequisites        []Prerequisite
	Project              string
	Rules                ServingRules
	State                FeatureState
	VariationToTargetMap []VariationMap
	Variations           Variations
	Segments             map[string]*Segment `json:"-"`
}

FeatureConfig object is actually where feature flag evaluation happens. It contains all data like rules, default values, variations and segments

func (*FeatureConfig) BoolVariation

func (fc *FeatureConfig) BoolVariation(target *Target) (Variation, error)

BoolVariation returns boolean evaluation for target

func (FeatureConfig) Evaluate

func (fc FeatureConfig) Evaluate(target *Target) (Evaluation, error)

Evaluate feature flag and return Evaluation object

func (FeatureConfig) EvaluateWithPreReqFlags added in v0.0.25

func (fc FeatureConfig) EvaluateWithPreReqFlags(target *Target, prereqFlags map[string]FeatureConfig) (Evaluation, error)

EvaluateWithPreReqFlags evaluates a feature flag against any flags that may be prerequisites returns an Evaluation object

func (*FeatureConfig) GetKind

func (fc *FeatureConfig) GetKind() reflect.Kind

GetKind returns kind of feature flag

func (FeatureConfig) GetSegmentIdentifiers

func (fc FeatureConfig) GetSegmentIdentifiers() StrSlice

GetSegmentIdentifiers returns all segments

func (FeatureConfig) GetVariationName

func (fc FeatureConfig) GetVariationName(target *Target) string

GetVariationName returns variation identifier for target

func (*FeatureConfig) IntVariation

func (fc *FeatureConfig) IntVariation(target *Target) (Variation, error)

IntVariation returns int evaluation for target

func (*FeatureConfig) JSONVariation

func (fc *FeatureConfig) JSONVariation(target *Target) (Variation, error)

JSONVariation returns json evaluation for target

func (*FeatureConfig) NumberVariation

func (fc *FeatureConfig) NumberVariation(target *Target) (Variation, error)

NumberVariation returns number evaluation for target

func (*FeatureConfig) StringVariation

func (fc *FeatureConfig) StringVariation(target *Target) (Variation, error)

StringVariation returns string evaluation for target

type FeatureState

type FeatureState string

FeatureState represents feature flag ON or OFF state

const (
	// FeatureStateOff represents OFF state
	FeatureStateOff FeatureState = "off"
	// FeatureStateOn represents ON state
	FeatureStateOn FeatureState = "on"
)

type FlagVariation added in v0.1.5

type FlagVariation struct {
	FlagIdentifier string
	Kind           rest.FeatureConfigKind
	Variation      rest.Variation
}

FlagVariation contains all required for ff-server to evaluate.

type FlagVariations added in v0.1.5

type FlagVariations []FlagVariation

FlagVariations list of FlagVariations

type PostEvalData added in v0.0.25

type PostEvalData struct {
	FeatureConfig *rest.FeatureConfig
	Target        *Target
	Variation     *rest.Variation
}

PostEvalData holds information for post evaluation processing

type PostEvaluateCallback added in v0.0.25

type PostEvaluateCallback interface {
	PostEvaluateProcessor(data *PostEvalData)
}

PostEvaluateCallback interface can be used for advanced processing of evaluated data

type Prerequisite

type Prerequisite struct {
	Feature    string
	Variations []string
}

Prerequisite object

type Query added in v0.0.25

type Query interface {
	GetSegment(identifier string) (rest.Segment, error)
	GetFlag(identifier string) (rest.FeatureConfig, error)
	GetFlags() ([]rest.FeatureConfig, error)
	GetFlagMap() (map[string]*rest.FeatureConfig, error)
}

Query provides methods for segment and flag retrieval

type Segment

type Segment struct {
	// Unique identifier for the target segment.
	Identifier string
	// Name of the target segment.
	Name string `json:"name"`

	CreatedAt   *int64
	ModifiedAt  *int64
	Environment *string

	Excluded StrSlice
	Included StrSlice

	// An array of rules that can cause a user to be included in this segment.
	Rules   SegmentRules
	Tags    []Tag
	Version int64
}

Segment object used in feature flag evaluation. Examples: beta users, premium customers

func (Segment) Evaluate

func (s Segment) Evaluate(target *Target) bool

Evaluate segment based on target input

type SegmentRules

type SegmentRules Clauses

SegmentRules is a set of clauses to determine if a target should be included in the segment.

func (SegmentRules) Evaluate

func (c SegmentRules) Evaluate(target *Target, segments Segments) bool

Evaluate SegmentRules. This determines if a segment rule is being used to include a target with the segment. SegmentRules are similar to ServingRules except a ServingRule can contain multiple clauses but a Segment rule only contains one clause.

type Segments

type Segments map[string]*Segment

Segments represents all segments with identifier as a key

func (Segments) Evaluate

func (s Segments) Evaluate(target *Target) bool

Evaluate through all segments based on target input

type Serve

type Serve struct {
	Distribution *Distribution
	Variation    *string
}

Serve object

type ServingRule

type ServingRule struct {
	Clauses  Clauses
	Priority int
	RuleID   string
	Serve    Serve
}

ServingRule object

type ServingRules

type ServingRules []ServingRule

ServingRules slice of ServingRule

func (ServingRules) GetVariationName

func (sr ServingRules) GetVariationName(target *Target, segments Segments, defaultServe Serve) string

GetVariationName returns variation identifier or defaultServe

type StrSlice

type StrSlice []string

StrSlice helper type used for string slice operations

func (StrSlice) Contains

func (slice StrSlice) Contains(s string) bool

Contains checks if slice contains string (case insensitive)

func (StrSlice) ContainsSensitive

func (slice StrSlice) ContainsSensitive(s string) bool

ContainsSensitive checks if slice contains string

type Tag

type Tag struct {
	Name  string
	Value *string
}

Tag object

type Target

type Target struct {
	Identifier string
	Name       string
	Anonymous  *bool
	Attributes *map[string]interface{}
}

Target object

func (Target) GetAttrValue

func (t Target) GetAttrValue(attr string) reflect.Value

GetAttrValue returns value from target with specified attribute

func (Target) GetOperator

func (t Target) GetOperator(attr string) (types.ValueType, error)

GetOperator returns interface based on attribute value

type Variation

type Variation struct {
	Description *string
	Identifier  string
	Name        *string
	Value       string
}

Variation object

func (*Variation) Bool

func (v *Variation) Bool(defaultValue bool) bool

Bool returns variation value as bool type

func (*Variation) Int

func (v *Variation) Int(defaultValue int64) int64

Int returns variation value as integer value

func (*Variation) JSON

func (v *Variation) JSON(defaultValue types.JSON) types.JSON

JSON returns variation value as JSON value

func (*Variation) Number

func (v *Variation) Number(defaultValue float64) float64

Number returns variation value as float

func (*Variation) String

func (v *Variation) String(defaultValue string) string

String returns variation value as string type

type VariationMap

type VariationMap struct {
	TargetSegments []string
	Targets        []string
	Variation      string
}

VariationMap object is variation which belongs to segments and targets

type Variations

type Variations []Variation

Variations slice of variation

func (Variations) FindByIdentifier

func (v Variations) FindByIdentifier(identifier string) *Variation

FindByIdentifier returns Variation with identifier if exist in variations

type WeightedVariation

type WeightedVariation struct {
	Variation string
	Weight    int
}

WeightedVariation represents Percentage Rollout data

Jump to

Keyboard shortcuts

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