exporter

package
v1.39.1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2024 License: MIT Imports: 13 Imported by: 11

Documentation

Overview

Package exporter defines the data exporter of go-feature-flag

These exporters are usable in your init configuration.

ffclient.Init(ffclient.Config{
  //...
  DataExporter: ffclient.DataExporter{
   FlushInterval:   10 * time.Second,
   MaxEventInMemory: 1000,
   DeprecatedExporter: &fileexporter.DeprecatedExporter{
     OutputDir: "/output-data/",
   },
 },
 //...
})

Index

Constants

View Source
const DefaultCsvTemplate = "{{ .Kind}};{{ .ContextKind}};{{ .UserKey}};{{ .CreationDate}};{{ .Key}};{{ .Variation}};" +
	"{{ .Value}};{{ .Default}};{{ .Source}}\n"
View Source
const DefaultFilenameTemplate = "flag-variation-{{ .Hostname}}-{{ .Timestamp}}.{{ .Format}}"

Variables

This section is empty.

Functions

func ComputeFilename

func ComputeFilename(template *template.Template, format string) (string, error)

ComputeFilename is computing the filename to use for the export file

func FormatEventInCSV

func FormatEventInCSV(csvTemplate *template.Template, event FeatureEvent) ([]byte, error)

func FormatEventInJSON

func FormatEventInJSON(event FeatureEvent) ([]byte, error)

func ParseTemplate

func ParseTemplate(name string, templateToParse string, defaultTemplate string) *template.Template

ParseTemplate is parsing the template given by the config or use the default template

Types

type CommonExporter added in v1.31.0

type CommonExporter interface {
	// IsBulk return false if we should directly send the data as soon as it is produce
	// and true if we collect the data to send them in bulk.
	IsBulk() bool
}

type DeprecatedExporter added in v1.31.0

type DeprecatedExporter interface {
	CommonExporter
	// Export will send the data to the exporter.
	Export(context.Context, *log.Logger, []FeatureEvent) error
}

DeprecatedExporter is an interface to describe how an exporter looks like. Deprecated: use Exporter instead.

type Exporter added in v1.9.1

type Exporter interface {
	CommonExporter
	Export(context.Context, *fflog.FFLogger, []FeatureEvent) error
}

type FeatureEvent

type FeatureEvent struct {
	// Kind for a feature event is feature.
	// A feature event will only be generated if the trackEvents attribute of the flag is set to true.
	Kind string `json:"kind" example:"feature" parquet:"name=kind, type=BYTE_ARRAY, convertedtype=UTF8"`

	// ContextKind is the kind of context which generated an event. This will only be "anonymousUser" for events generated
	// on behalf of an anonymous user or the reserved word "user" for events generated on behalf of a non-anonymous user
	ContextKind string `json:"contextKind,omitempty" example:"user" parquet:"name=contextKind, type=BYTE_ARRAY, convertedtype=UTF8"`

	// UserKey The key of the user object used in a feature flag evaluation. Details for the user object used in a feature
	// flag evaluation as reported by the "feature" event are transmitted periodically with a separate index event.
	UserKey string `json:"userKey" example:"94a25909-20d8-40cc-8500-fee99b569345" parquet:"name=userKey, type=BYTE_ARRAY, convertedtype=UTF8"`

	// CreationDate When the feature flag was requested at Unix epoch time in milliseconds.
	CreationDate int64 `json:"creationDate" example:"1680246000011" parquet:"name=creationDate, type=INT64"`

	// Key of the feature flag requested.
	Key string `json:"key" example:"my-feature-flag" parquet:"name=key, type=BYTE_ARRAY, convertedtype=UTF8"`

	// Variation  of the flag requested. Flag variation values can be "True", "False", "Default" or "SdkDefault"
	// depending on which value was taken during flag evaluation. "SdkDefault" is used when an error is detected and the
	// default value passed during the call to your variation is used.
	Variation string `json:"variation" example:"admin-variation" parquet:"name=variation, type=BYTE_ARRAY, convertedtype=UTF8"`

	// Value of the feature flag returned by feature flag evaluation.
	Value interface{} `json:"value" parquet:"name=value, type=BYTE_ARRAY, convertedtype=UTF8"`

	// Default value is set to true if feature flag evaluation failed, in which case the value returned was the default
	// value passed to variation. If the default field is omitted, it is assumed to be false.
	Default bool `json:"default" example:"false" parquet:"name=default, type=BOOLEAN"`

	// Version contains the version of the flag. If the field is omitted for the flag in the configuration file
	// the default version will be 0.
	Version string `json:"version" example:"v1.0.0" parquet:"name=version, type=BYTE_ARRAY, convertedtype=UTF8"`

	// Source indicates where the event was generated.
	// This is set to SERVER when the event was evaluated in the relay-proxy and PROVIDER_CACHE when it is evaluated from the cache.
	Source string `json:"source" example:"SERVER" parquet:"name=source, type=BYTE_ARRAY, convertedtype=UTF8"`
}

FeatureEvent represent an event that we store in the data storage nolint:lll

func NewFeatureEvent

func NewFeatureEvent(
	ctx ffcontext.Context,
	flagKey string,
	value interface{},
	variation string,
	failed bool,
	version string,
	source string,
) FeatureEvent

func (*FeatureEvent) MarshalInterface added in v1.8.0

func (f *FeatureEvent) MarshalInterface() error

MarshalInterface marshals all interface type fields in FeatureEvent into JSON-encoded string.

type Scheduler added in v1.9.1

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

Scheduler is the struct that handle the data collection.

func NewScheduler added in v1.9.1

func NewScheduler(ctx context.Context, flushInterval time.Duration, maxEventInMemory int64,
	exp CommonExporter, logger *fflog.FFLogger,
) *Scheduler

NewScheduler allows creating a new instance of Scheduler ready to be used to export data.

func (*Scheduler) AddEvent added in v1.9.1

func (dc *Scheduler) AddEvent(event FeatureEvent)

AddEvent allow adding an event to the local cache and to call the exporter if we reach the maximum number of events that can be present in the cache.

func (*Scheduler) Close added in v1.9.1

func (dc *Scheduler) Close()

Close will stop the daemon and send the data still in the cache

func (*Scheduler) GetLogger added in v1.30.0

func (dc *Scheduler) GetLogger(level slog.Level) *log.Logger

GetLogger will return the logger used by the scheduler

func (*Scheduler) StartDaemon added in v1.9.1

func (dc *Scheduler) StartDaemon()

StartDaemon will start a goroutine to check every X seconds if we should send the data. The daemon is started only if we have a bulk exporter.

Jump to

Keyboard shortcuts

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