ldreason

package
v3.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: Apache-2.0 Imports: 4 Imported by: 23

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" evaluation methods that allow you to determine whether the result of a flag evaluation was due to, for instance, context key targeting or a specific flag rule, such as github.com/launchdarkly/go-server-sdk/v6.LDClient.BoolVariationDetail.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BigSegmentsStatus

type BigSegmentsStatus string

BigSegmentsStatus defines the possible values of EvaluationReason.GetBigSegmentsStatus.

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

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 an invalid or uninitialized
	// context. The name and value of this constant refer to "user" rather than "context" only for
	// backward compatibility with older SDKs that used the term "user".
	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 context key was specifically targeted for this flag.
	EvalReasonTargetMatch EvalReasonKind = "TARGET_MATCH"
	// EvalReasonRuleMatch indicates that the context 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 context 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 evaluation 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 the SDK's "detail" evaluation methods, such as github.com/launchdarkly/go-server-sdk/v6.LDClient.BoolVariationDetail, 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

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

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

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

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 segments. For more information, read the LaunchDarkly documentation: https://docs.launchdarkly.com/home/contexts/big-segments

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

func (r EvaluationReason) IsDefined() bool

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

func (EvaluationReason) IsInExperiment

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

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 encoding/json.Unmarshal. See github.com/launchdarkly/go-jsonstream/v3 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)".

This value is intended only for convenience in logging or debugging. Application code should not rely on its specific format.

func (*EvaluationReason) UnmarshalJSON

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

UnmarshalJSON implements custom JSON deserialization for EvaluationReason.

func (EvaluationReason) WriteToJSONWriter

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 encoding/json.Marshal. See github.com/launchdarkly/go-jsonstream/v3 for more details.

Jump to

Keyboard shortcuts

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