ldreason

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2021 License: Apache-2.0 Imports: 5 Imported by: 12

Documentation

Overview

Package ldreason provides types that describe the outcome of a LaunchDarkly flag evaluation.

You do not need to use these types to evaluate feature flags with the LaunchDarkly SDK. They are only required for the "detail" methods that allow you to determine whether the result of a flag evaluation was due to, for instance, user key targeting or a specific flag rule.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BigSegmentsStatus added in v2.4.0

type BigSegmentsStatus string

BigSegmentsStatus defines the possible values of EvaluationReason.GetBigSegmentsStatus().

"Big segments" are a specific type of user segments. For more information, read the LaunchDarkly documentation about user segments: https://docs.launchdarkly.com/home/users

const (
	// BigSegmentsHealthy indicates that the big segment query involved in the flag
	// evaluation was successful, and that the segment state is considered up to date.
	BigSegmentsHealthy BigSegmentsStatus = "HEALTHY"

	// BigSegmentsStale indicates that the big segment query involved in the flag
	// evaluation was successful, but that the segment state may not be up to date.
	BigSegmentsStale BigSegmentsStatus = "STALE"

	// BigSegmentsNotConfigured indicates that big segments could not be queried for the
	// flag evaluation because the SDK configuration did not include a big segment store.
	BigSegmentsNotConfigured BigSegmentsStatus = "NOT_CONFIGURED"

	// BigSegmentsStoreError indicates that the big segment query involved in the flag
	// evaluation failed, for instance due to a database error.
	BigSegmentsStoreError BigSegmentsStatus = "STORE_ERROR"
)

type EvalErrorKind

type EvalErrorKind string

EvalErrorKind defines the possible values of EvaluationReason.GetErrorKind().

const (
	// EvalErrorClientNotReady indicates that the caller tried to evaluate a flag before the client
	// had successfully initialized.
	EvalErrorClientNotReady EvalErrorKind = "CLIENT_NOT_READY"
	// EvalErrorFlagNotFound indicates that the caller provided a flag key that did not match any
	// known flag.
	EvalErrorFlagNotFound EvalErrorKind = "FLAG_NOT_FOUND"
	// EvalErrorMalformedFlag indicates that there was an internal inconsistency in the flag data,
	// e.g. a rule specified a nonexistent variation.
	EvalErrorMalformedFlag EvalErrorKind = "MALFORMED_FLAG"
	// EvalErrorUserNotSpecified indicates that the caller passed a user without a key for the user
	// parameter.
	EvalErrorUserNotSpecified EvalErrorKind = "USER_NOT_SPECIFIED"
	// EvalErrorWrongType indicates that the result value was not of the requested type, e.g. you
	// called BoolVariationDetail but the value was an integer.
	EvalErrorWrongType EvalErrorKind = "WRONG_TYPE"
	// EvalErrorException indicates that an unexpected error stopped flag evaluation; check the
	// log for details.
	EvalErrorException EvalErrorKind = "EXCEPTION"
)

type EvalReasonKind

type EvalReasonKind string

EvalReasonKind defines the possible values of EvaluationReason.GetKind().

const (
	// EvalReasonOff indicates that the flag was off and therefore returned its configured off value.
	EvalReasonOff EvalReasonKind = "OFF"
	// EvalReasonTargetMatch indicates that the user key was specifically targeted for this flag.
	EvalReasonTargetMatch EvalReasonKind = "TARGET_MATCH"
	// EvalReasonRuleMatch indicates that the user matched one of the flag's rules.
	EvalReasonRuleMatch EvalReasonKind = "RULE_MATCH"
	// EvalReasonPrerequisiteFailed indicates that the flag was considered off because it had at
	// least one prerequisite flag that either was off or did not return the desired variation.
	EvalReasonPrerequisiteFailed EvalReasonKind = "PREREQUISITE_FAILED"
	// EvalReasonFallthrough indicates that the flag was on but the user did not match any targets
	// or rules.
	EvalReasonFallthrough EvalReasonKind = "FALLTHROUGH"
	// EvalReasonError indicates that the flag could not be evaluated, e.g. because it does not
	// exist or due to an unexpected error. In this case the result value will be the default value
	// that the caller passed to the client.
	EvalReasonError EvalReasonKind = "ERROR"
)

type EvaluationDetail

type EvaluationDetail struct {
	// Value is the result of the flag evaluation. This will be either one of the flag's variations or
	// the default value that was passed to the Variation method.
	Value ldvalue.Value
	// VariationIndex is the index of the returned value within the flag's list of variations, e.g.
	// 0 for the first variation. This is an ldvalue.OptionalInt rather than an int, because it is
	// possible for the value to be undefined (there is no variation index if the application default
	// value was returned due to an error in evaluation) which is different from a value of 0. See
	// ldvalue.OptionalInt for more about how to use this type.
	VariationIndex ldvalue.OptionalInt
	// Reason is an EvaluationReason object describing the main factor that influenced the flag
	// evaluation value.
	Reason EvaluationReason
}

EvaluationDetail is an object returned by LDClient.VariationDetail, combining the result of a flag evaluation with an explanation of how it was calculated.

func NewEvaluationDetail

func NewEvaluationDetail(
	value ldvalue.Value,
	variationIndex int,
	reason EvaluationReason,
) EvaluationDetail

NewEvaluationDetail constructs an EvaluationDetail, specifying all fields. This assumes that there is a defined value for variationIndex; if variationIndex is undefined, use NewEvaluationDetailForError or set the struct fields directly.

func NewEvaluationDetailForError

func NewEvaluationDetailForError(errorKind EvalErrorKind, defaultValue ldvalue.Value) EvaluationDetail

NewEvaluationDetailForError constructs an EvaluationDetail for an error condition.

func (EvaluationDetail) IsDefaultValue

func (d EvaluationDetail) IsDefaultValue() bool

IsDefaultValue returns true if the result of the evaluation was the application default value. This means that an error prevented the flag from being evaluated; the Reason field should contain an error value such as NewEvalReasonError(EvalErrorFlagNotFound).

type EvaluationReason

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

EvaluationReason describes the reason that a flag evaluation producted a particular value.

This struct is immutable; its properties can be accessed only via getter methods.

func NewEvalReasonError

func NewEvalReasonError(errorKind EvalErrorKind) EvaluationReason

NewEvalReasonError returns an EvaluationReason whose Kind is EvalReasonError.

func NewEvalReasonFallthrough

func NewEvalReasonFallthrough() EvaluationReason

NewEvalReasonFallthrough returns an EvaluationReason whose Kind is EvalReasonFallthrough.

func NewEvalReasonFallthroughExperiment added in v2.3.0

func NewEvalReasonFallthroughExperiment(inExperiment bool) EvaluationReason

NewEvalReasonFallthroughExperiment returns an EvaluationReason whose Kind is EvalReasonFallthrough. The inExperiment parameter represents whether the evaluation was part of an experiment.

func NewEvalReasonFromReasonWithBigSegmentsStatus added in v2.4.0

func NewEvalReasonFromReasonWithBigSegmentsStatus(
	reason EvaluationReason,
	bigSegmentsStatus BigSegmentsStatus,
) EvaluationReason

NewEvalReasonFromReasonWithBigSegmentsStatus returns a copy of an EvaluationReason with a specific BigSegmentsStatus value added.

func NewEvalReasonOff

func NewEvalReasonOff() EvaluationReason

NewEvalReasonOff returns an EvaluationReason whose Kind is EvalReasonOff.

func NewEvalReasonPrerequisiteFailed

func NewEvalReasonPrerequisiteFailed(prereqKey string) EvaluationReason

NewEvalReasonPrerequisiteFailed returns an EvaluationReason whose Kind is EvalReasonPrerequisiteFailed.

func NewEvalReasonRuleMatch

func NewEvalReasonRuleMatch(ruleIndex int, ruleID string) EvaluationReason

NewEvalReasonRuleMatch returns an EvaluationReason whose Kind is EvalReasonRuleMatch.

func NewEvalReasonRuleMatchExperiment added in v2.3.0

func NewEvalReasonRuleMatchExperiment(ruleIndex int, ruleID string, inExperiment bool) EvaluationReason

NewEvalReasonRuleMatchExperiment returns an EvaluationReason whose Kind is EvalReasonRuleMatch. The inExperiment parameter represents whether the evaluation was part of an experiment.

func NewEvalReasonTargetMatch

func NewEvalReasonTargetMatch() EvaluationReason

NewEvalReasonTargetMatch returns an EvaluationReason whose Kind is EvalReasonTargetMatch.

func (EvaluationReason) GetBigSegmentsStatus added in v2.4.0

func (r EvaluationReason) GetBigSegmentsStatus() BigSegmentsStatus

GetBigSegmentsStatus describes the validity of big segment information, if and only if the flag evaluation required querying at least one big segment. Otherwise it returns an empty string.

"Big segments" are a specific kind of user segments. For more information, read the LaunchDarkly documentation about user segments: https://docs.launchdarkly.com/home/users

func (EvaluationReason) GetErrorKind

func (r EvaluationReason) GetErrorKind() EvalErrorKind

GetErrorKind describes the general category of the error, if the Kind is EvalReasonError. Otherwise it returns an empty string.

func (EvaluationReason) GetKind

func (r EvaluationReason) GetKind() EvalReasonKind

GetKind describes the general category of the reason.

func (EvaluationReason) GetPrerequisiteKey

func (r EvaluationReason) GetPrerequisiteKey() string

GetPrerequisiteKey provides the flag key of the prerequisite that failed, if the Kind is EvalReasonPrerequisiteFailed. Otherwise it returns an empty string.

func (EvaluationReason) GetRuleID

func (r EvaluationReason) GetRuleID() string

GetRuleID provides the unique identifier of the rule that was matched, if the Kind is EvalReasonRuleMatch. Otherwise it returns an empty string. Unlike the rule index, this identifier will not change if other rules are added or deleted.

func (EvaluationReason) GetRuleIndex

func (r EvaluationReason) GetRuleIndex() int

GetRuleIndex provides the index of the rule that was matched (0 being the first), if the Kind is EvalReasonRuleMatch. Otherwise it returns -1.

func (EvaluationReason) IsDefined added in v2.1.0

func (r EvaluationReason) IsDefined() bool

IsDefined returns true if this EvaluationReason has a non-empty GetKind(). It is false for a zero value of EvaluationReason{}.

func (EvaluationReason) IsInExperiment added in v2.3.0

func (r EvaluationReason) IsInExperiment() bool

IsInExperiment describes whether the evaluation was part of an experiment. It returns true if the evaluation resulted in an experiment rollout *and* served one of the variations in the experiment. Otherwise it returns false.

func (EvaluationReason) MarshalJSON

func (r EvaluationReason) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON serialization for EvaluationReason.

func (*EvaluationReason) ReadFromJSONReader added in v2.2.0

func (r *EvaluationReason) ReadFromJSONReader(reader *jreader.Reader)

ReadFromJSONReader provides JSON deserialization for use with the jsonstream API.

This implementation is used by the SDK in cases where it is more efficient than JSON.Unmarshal. See https://github.com/launchdarkly/go-jsonstream for more details.

func (EvaluationReason) String

func (r EvaluationReason) String() string

String returns a concise string representation of the reason. Examples: "OFF", "ERROR(WRONG_TYPE)".

func (*EvaluationReason) UnmarshalJSON

func (r *EvaluationReason) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON deserialization for EvaluationReason.

func (EvaluationReason) WriteToJSONBuffer deprecated

func (r EvaluationReason) WriteToJSONBuffer(j *jsonstream.JSONBuffer)

WriteToJSONBuffer provides JSON serialization for use with the deprecated jsonstream API.

Deprecated: this method is provided for backward compatibility. The LaunchDarkly SDK no longer uses this API; instead it uses the newer https://github.com/launchdarkly/go-jsonstream.

func (EvaluationReason) WriteToJSONWriter added in v2.2.0

func (r EvaluationReason) WriteToJSONWriter(w *jwriter.Writer)

WriteToJSONWriter provides JSON serialization for use with the jsonstream API.

This implementation is used by the SDK in cases where it is more efficient than JSON.Marshal. See https://github.com/launchdarkly/go-jsonstream for more details.

Jump to

Keyboard shortcuts

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