flag

package
v1.20.2 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PercentageMultiplier = float64(1000)
	MaxPercentage        = uint32(100 * PercentageMultiplier)
)
View Source
const VariationSDKDefault string = "SdkDefault"

Variables

This section is empty.

Functions

func MergeSetOfRules added in v1.0.0

func MergeSetOfRules(initialRules []Rule, updates []Rule) *[]Rule

MergeSetOfRules is taking a collection of rules and merge it with the updates from a schedule steps. If you want to edit a rule this rule should have a name already to be able to target the updates to the right place.

Types

type Context added in v1.12.0

type Context struct {
	// EvaluationContextEnrichment will be merged with the evaluation context sent during the evaluation.
	// It is useful to add common attributes to all the evaluation, such as a server version, environment, ...
	//
	// All those fields will be included in the custom attributes of the evaluation context,
	// if in the evaluation context you have a field with the same name, it will override the common one.
	// Default: nil
	EvaluationContextEnrichment map[string]interface{}

	// DefaultSdkValue is the default value of the SDK when calling the variation.
	DefaultSdkValue interface{}
}

func (*Context) AddIntoEvaluationContextEnrichment added in v1.19.0

func (s *Context) AddIntoEvaluationContextEnrichment(key string, value interface{})

type ErrorCode added in v0.27.0

type ErrorCode = string

ErrorCode is an enum following the open-feature specs about error code.

const (
	// Proposed in the open-feature specs
	ErrorCodeProviderNotReady ErrorCode = "PROVIDER_NOT_READY"
	ErrorCodeFlagNotFound     ErrorCode = "FLAG_NOT_FOUND"
	ErrorCodeParseError       ErrorCode = "PARSE_ERROR"
	ErrorCodeTypeMismatch     ErrorCode = "TYPE_MISMATCH"
	ErrorCodeGeneral          ErrorCode = "GENERAL"

	// 	ErrorFlagConfiguration is returned when we were not able to use the flag because of a misconfiguration
	ErrorFlagConfiguration ErrorCode = "FLAG_CONFIG"
)

type ExperimentationRollout added in v1.0.0

type ExperimentationRollout struct {
	// Start is the starting time of the experimentation
	Start *time.Time `json:"start,omitempty" yaml:"start,omitempty" toml:"start,omitempty"`

	// End is the ending time of the experimentation
	End *time.Time `json:"end,omitempty" yaml:"end,omitempty" toml:"end,omitempty"`
}

type Flag

type Flag interface {
	// Value is returning the Value associate to the flag
	Value(flagName string, evaluationContext ffcontext.Context, flagContext Context) (interface{}, ResolutionDetails)

	// GetVersion is the getter for the field Version
	// Default: 0.0
	GetVersion() string

	// IsTrackEvents is the getter of the field TrackEvents
	// Default: true
	IsTrackEvents() bool

	// IsDisable is the getter for the field Disable
	// Default: false
	IsDisable() bool

	// GetVariationValue return the value of variation from his name
	GetVariationValue(name string) interface{}

	// GetMetadata return the metadata associated to the flag
	GetMetadata() map[string]interface{}
}

type InternalFlag added in v1.0.0

type InternalFlag struct {
	// Variations are all the variations available for this flag. You can have as many variation as needed.
	Variations *map[string]*interface{} `json:"variations,omitempty" yaml:"variations,omitempty" toml:"variations,omitempty"` // nolint:lll

	// Rules is the list of Rule for this flag.
	// This an optional field.
	Rules *[]Rule `json:"targeting,omitempty" yaml:"targeting,omitempty" toml:"targeting,omitempty"`

	// DefaultRule is the originalRule applied after checking that any other rules
	// matched the user.
	DefaultRule *Rule `json:"defaultRule,omitempty" yaml:"defaultRule,omitempty" toml:"defaultRule,omitempty"`

	// Experimentation is your struct to configure an experimentation, it will allow you to configure a start date and
	// an end date for your flag.
	// When the experimentation is not running, the flag will serve the default value.
	Experimentation *ExperimentationRollout `json:"experimentation,omitempty" yaml:"experimentation,omitempty" toml:"experimentation,omitempty"` // nolint: lll

	// Scheduled is your struct to configure an update on some fields of your flag over time.
	// You can add several steps that updates the flag, this is typically used if you want to gradually add more user
	// in your flag.
	Scheduled *[]ScheduledStep `json:"scheduledRollout,omitempty" yaml:"scheduledRollout,omitempty" toml:"scheduledRollout,omitempty"` // nolint: lll

	// TrackEvents is false if you don't want to export the data in your data exporter.
	// Default value is true
	TrackEvents *bool `json:"trackEvents,omitempty" yaml:"trackEvents,omitempty" toml:"trackEvents,omitempty"`

	// Disable is true if the flag is disabled.
	Disable *bool `json:"disable,omitempty" yaml:"disable,omitempty" toml:"disable,omitempty"`

	// Version (optional) This field contains the version of the flag.
	// The version is manually managed when you configure your flags, and it is used to display the information
	// in the notifications and data collection.
	Version *string `json:"version,omitempty" yaml:"version,omitempty" toml:"version,omitempty"`

	// Metadata is a field containing information about your flag such as an issue tracker link, a description, etc ...
	Metadata *map[string]interface{} `json:"metadata,omitempty" yaml:"metadata,omitempty" toml:"metadata,omitempty"`
}

InternalFlag is the internal representation of a flag when using go-feature-flag. All the flags in your configuration files can have different format but will be converted into an InternalFlag to be used in the library.

func (*InternalFlag) GetDefaultRule added in v1.0.0

func (f *InternalFlag) GetDefaultRule() *Rule

GetDefaultRule is the getter of the field DefaultRule

func (*InternalFlag) GetMetadata added in v1.11.0

func (f *InternalFlag) GetMetadata() map[string]interface{}

GetMetadata return the metadata associated to the flag

func (*InternalFlag) GetRuleIndexByName added in v1.0.0

func (f *InternalFlag) GetRuleIndexByName(name string) *int

func (*InternalFlag) GetRules added in v1.0.0

func (f *InternalFlag) GetRules() []Rule

func (*InternalFlag) GetVariationValue added in v1.0.0

func (f *InternalFlag) GetVariationValue(name string) interface{}

GetVariationValue return the value of variation from his name

func (*InternalFlag) GetVariations added in v1.0.0

func (f *InternalFlag) GetVariations() map[string]*interface{}

GetVariations is the getter of the field Variations

func (*InternalFlag) GetVersion added in v1.0.0

func (f *InternalFlag) GetVersion() string

GetVersion is the getter for the field Version

func (*InternalFlag) IsDisable added in v1.0.0

func (f *InternalFlag) IsDisable() bool

IsDisable is the getter for the field Disable

func (*InternalFlag) IsTrackEvents added in v1.0.0

func (f *InternalFlag) IsTrackEvents() bool

IsTrackEvents is the getter of the field TrackEvents

func (*InternalFlag) IsValid added in v1.0.0

func (f *InternalFlag) IsValid() error

IsValid is checking if the current flag is valid.

func (*InternalFlag) Value added in v1.0.0

func (f *InternalFlag) Value(
	flagName string,
	evaluationCtx ffcontext.Context,
	flagContext Context,
) (interface{}, ResolutionDetails)

Value is returning the Value associate to the flag

type ProgressiveRollout added in v1.0.0

type ProgressiveRollout struct {
	// Initial contains a description of the initial state of the rollout.
	Initial *ProgressiveRolloutStep `` // nolint: lll
	/* 164-byte string literal not displayed */

	// End contains what describes the end status of the rollout.
	End *ProgressiveRolloutStep `` // nolint: lll
	/* 148-byte string literal not displayed */
}

ProgressiveRollout represents how to progressively roll out a originalRule.

type ProgressiveRolloutStep added in v1.0.0

type ProgressiveRolloutStep struct {
	// Variation - name of the variation for this step
	Variation *string `` // nolint: lll
	/* 162-byte string literal not displayed */

	// Percentage is the percentage (initial or end) for the progressive rollout
	Percentage *float64 `` // nolint: lll
	/* 195-byte string literal not displayed */

	// Date is the time it starts or ends.
	Date *time.Time `` // nolint: lll
	/* 146-byte string literal not displayed */
}

ProgressiveRolloutStep define a progressive rollout step (initial and end)

type ResolutionDetails added in v0.27.0

type ResolutionDetails struct {
	// Variant indicates the name of the variant used when evaluating the flag
	Variant string

	// Reason indicates the reason of the decision
	Reason ResolutionReason

	// ErrorCode indicates the error code for this evaluation
	ErrorCode ErrorCode

	// RuleIndex indicates which rules applied
	RuleIndex *int

	// RuleName (optional) is the name of the associated rule if we have one
	RuleName *string

	// Cacheable is set to true if an SDK/provider can cache the value locally.
	Cacheable bool

	// Metadata is a field containing information about your flag such as an issue tracker link, a description, etc ...
	Metadata map[string]interface{}
}

ResolutionDetails is the object used to manipulate the data internally, it allows to retrieve the details of your evaluation.

type ResolutionReason added in v0.27.0

type ResolutionReason = string

ResolutionReason is an enum following the open-feature specs about resolution reasons.

const (
	// ReasonTargetingMatch The resolved value was the result of a dynamic evaluation,
	// such as a rule or specific user-targeting.
	// ex: serve variation A if username is Thomas
	ReasonTargetingMatch ResolutionReason = "TARGETING_MATCH"

	// ReasonTargetingMatchSplit The resolved value was the result of a dynamic evaluation,
	// that is serving a percentage.
	// ex: serve variation A to 10% of users with the username Thomas
	ReasonTargetingMatchSplit ResolutionReason = "TARGETING_MATCH_SPLIT"

	// ReasonSplit The resolved value was the result of pseudorandom assignment.
	// ex: serve variation A to 10% of all the users.
	ReasonSplit ResolutionReason = "SPLIT"

	// ReasonDisabled Indicates that the feature flag is disabled
	ReasonDisabled ResolutionReason = "DISABLED"

	// ReasonDefault The resolved value was the result of the flag being disabled in the management system.
	ReasonDefault ResolutionReason = "DEFAULT"

	// ReasonStatic	Indicates that the feature flag evaluated to a
	// static value, for example, the default value for the flag
	//
	// Note: Typically means that no dynamic evaluation has been
	// executed for the feature flag
	ReasonStatic ResolutionReason = "STATIC"

	// ReasonUnknown Indicates an unknown issue occurred during evaluation
	ReasonUnknown ResolutionReason = "UNKNOWN"

	// ReasonError Indicates that an error occurred during evaluation
	// Note: The `errorCode`-field contains the details of this error
	ReasonError ResolutionReason = "ERROR"

	// ReasonOffline Indicates that GO Feature Flag is currently evaluating in offline mode.
	ReasonOffline ResolutionReason = "OFFLINE"
)

type Rollout added in v1.0.0

type Rollout struct {
	// Experimentation is your struct to configure an experimentation, it will allow you to configure a start date and
	// an end date for your flag.
	// When the experimentation is not running, the flag will serve the default value.
	Experimentation *ExperimentationRollout `json:"experimentation,omitempty" yaml:"experimentation,omitempty" toml:"experimentation,omitempty"` // nolint: lll

	// Scheduled is your struct to configure an update on some fields of your flag over time.
	// You can add several steps that updates the flag, this is typically used if you want to gradually add more user
	// in your flag.
	Scheduled *[]ScheduledStep `json:"scheduled,omitempty" yaml:"scheduled,omitempty" toml:"scheduled,omitempty"`
}

type Rule added in v1.0.0

type Rule struct {
	// Name is the name of the rule, this field is mandatory if you want
	// to update the rule during scheduled rollout
	Name *string `` // nolint: lll
	/* 212-byte string literal not displayed */

	// Query represents an antlr query in the nikunjy/rules format
	Query *string `` // nolint: lll
	/* 217-byte string literal not displayed */

	// VariationResult represents the variation name to use if the rule apply for the user.
	// In case we have a percentage field in the config VariationResult is ignored
	VariationResult *string `` // nolint: lll
	/* 250-byte string literal not displayed */

	// Percentages represents the percentage we should give to each variation.
	// example: variationA = 10%, variationB = 80%, variationC = 10%
	Percentages *map[string]float64 `` // nolint: lll
	/* 185-byte string literal not displayed */

	// ProgressiveRollout is your struct to configure a progressive rollout deployment of your flag.
	// It will allow you to ramp up the percentage of your flag over time.
	// You can decide at which percentage you starts with and at what percentage you ends with in your release ramp.
	// Before the start date we will serve the initial percentage and, after we will serve the end percentage.
	ProgressiveRollout *ProgressiveRollout `` // nolint: lll
	/* 214-byte string literal not displayed */

	// Disable indicates that this rule is disabled.
	Disable *bool `` // nolint: lll
	/* 151-byte string literal not displayed */
}

Rule represents a rule applied by the flag.

func (*Rule) Evaluate added in v1.0.0

func (r *Rule) Evaluate(ctx ffcontext.Context, hashID uint32, isDefault bool,
) (string, error)

Evaluate is checking if the rule apply to for the user. If yes it returns the variation you should use for this rule.

func (*Rule) GetName added in v1.0.0

func (r *Rule) GetName() string

func (*Rule) GetPercentages added in v1.0.0

func (r *Rule) GetPercentages() map[string]float64

func (*Rule) GetProgressiveRollout added in v1.0.0

func (r *Rule) GetProgressiveRollout() ProgressiveRollout

func (*Rule) GetQuery added in v1.0.0

func (r *Rule) GetQuery() string

func (*Rule) GetTrimmedQuery added in v1.10.3

func (r *Rule) GetTrimmedQuery() string

GetTrimmedQuery is removing the break lines and return

func (*Rule) GetVariationResult added in v1.0.0

func (r *Rule) GetVariationResult() string

func (*Rule) IsDisable added in v1.0.0

func (r *Rule) IsDisable() bool

func (*Rule) IsDynamic added in v1.3.0

func (r *Rule) IsDynamic() bool

IsDynamic is a function that allows to know if the rule has a dynamic result or not.

func (*Rule) IsValid added in v1.0.0

func (r *Rule) IsValid(defaultRule bool) error

IsValid is checking if the rule is valid

func (*Rule) MergeRules added in v1.0.0

func (r *Rule) MergeRules(updatedRule Rule)

MergeRules is merging 2 rules. It is used when we have to update a rule in a scheduled rollout.

type ScheduledStep added in v1.0.0

type ScheduledStep struct {
	InternalFlag `yaml:",inline"`
	Date         *time.Time `json:"date,omitempty" yaml:"date,omitempty" toml:"date,omitempty"`
}

ScheduledStep is one change of the flag.

Jump to

Keyboard shortcuts

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