exporter

package
v1.44.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2025 License: MIT Imports: 16 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,
   Exporter: &s3exporterv2.Exporter{
		Format:    "json",
		Bucket:    "my-test-bucket",
		S3Path:    "/go-feature-flag/variations/",
		Filename:  "flag-variation-{{ .Timestamp}}.{{ .Format}}",
		AwsConfig: &awsConfig,
	},
 },
 //...
})

Index

Constants

View Source
const DefaultCsvTemplate = "{{ .Kind}};{{ .ContextKind}};{{ .UserKey}};{{ .CreationDate}};{{ .Key}};{{ .Variation}};" +
	"{{ .Value}};{{ .Default}};{{ .Source}}\n"
View Source
const DefaultExporterCleanQueueInterval = 1 * time.Minute
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 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 Config added in v1.42.0

type Config struct {
	Exporter         CommonExporter
	FlushInterval    time.Duration
	MaxEventInMemory int64
}

type DataExporter added in v1.42.0

type DataExporter[T ExportableEvent] interface {
	// Start is launching the ticker to periodically flush the data
	Start()
	// Stop is stopping the ticker
	Stop()
	// Flush is sending the data to the exporter
	Flush()
	// IsBulk return false if we should directly send the data as soon as it is produce
	IsBulk() bool
	// GetConsumerID return the consumer ID used in the event store
	GetConsumerID() string
	// GetMaxEventInMemory return the maximum number of event you keep in the cache before calling Flush()
	GetMaxEventInMemory() int64
}

func NewDataExporter added in v1.42.0

func NewDataExporter[T ExportableEvent](ctx context.Context, exporter Config, consumerID string,
	eventStore *EventStore[T], logger *fflog.FFLogger) DataExporter[T]

NewDataExporter create a new DataExporter with the given exporter and his consumer information to consume the data from the shared event store.

type DeprecatedExporterV1 added in v1.44.0

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

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

type DeprecatedExporterV2 added in v1.44.0

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

type EventList added in v1.42.0

type EventList[T ExportableEvent] struct {
	Events        []T
	InitialOffset int64
	NewOffset     int64
}

type EventStore added in v1.42.0

type EventStore[T ExportableEvent] interface {
	// AddConsumer is adding a new consumer to the Event store.
	// note that you can't add a consumer after the Event store has been started.
	AddConsumer(consumerID string)

	// Add is adding item of type T in the Event store.
	Add(data T)

	// GetPendingEventCount is returning the number items available in the Event store for this consumer.
	GetPendingEventCount(consumerID string) (int64, error)

	// GetTotalEventCount returns the total number of events in the store.
	GetTotalEventCount() int64

	// ProcessPendingEvents is processing all the available item in the Event store for this consumer
	// with the process events function in parameter,
	ProcessPendingEvents(
		consumerID string,
		processEventsFunc func(context.Context, []T) error,
	) error

	// Stop is closing the Event store and stop the periodic cleaning.
	Stop()
}

EventStore is the interface to store events and consume them. It is a simple implementation of a queue with offsets.

func NewEventStore added in v1.42.0

func NewEventStore[T ExportableEvent](cleanQueueInterval time.Duration) EventStore[T]

type EventStoreItem added in v1.44.0

type EventStoreItem[T ExportableEvent] struct {
	Offset int64
	Data   T
}

type ExportableEvent added in v1.44.0

type ExportableEvent interface {
	// GetUserKey returns the unique key for the event.
	GetUserKey() string
	// GetKey returns the unique key for the event.
	GetKey() string
	// GetCreationDate returns the creationDate of the event.
	GetCreationDate() int64
	// FormatInCSV FormatEventInCSV returns the event in CSV format.
	FormatInCSV(csvTemplate *template.Template) ([]byte, error)
	// FormatInJSON FormatEventInJSON returns the event in JSON format.
	FormatInJSON() ([]byte, error)
}

type Exporter added in v1.9.1

type Exporter interface {
	CommonExporter
	Export(context.Context, *fflog.FFLogger, []ExportableEvent) 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"`

	// Metadata are static information added in the providers to give context about the events generated.
	Metadata FeatureEventMetadata `` /* 149-byte string literal not displayed */
}

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,
	metadata FeatureEventMetadata,
) FeatureEvent

func (FeatureEvent) ConvertValueForParquet added in v1.44.0

func (f FeatureEvent) ConvertValueForParquet() (string, error)

ConvertValueForParquet converts the value of the event to a string to be stored in a parquet file.

func (FeatureEvent) FormatInCSV added in v1.44.0

func (f FeatureEvent) FormatInCSV(csvTemplate *template.Template) ([]byte, error)

func (FeatureEvent) FormatInJSON added in v1.44.0

func (f FeatureEvent) FormatInJSON() ([]byte, error)

func (FeatureEvent) GetCreationDate added in v1.44.0

func (f FeatureEvent) GetCreationDate() int64

GetCreationDate returns the creationDate of the event.

func (FeatureEvent) GetKey added in v1.44.0

func (f FeatureEvent) GetKey() string

GetKey returns the key of the event

func (FeatureEvent) GetUserKey added in v1.44.0

func (f FeatureEvent) GetUserKey() string

GetUserKey returns the user key of the event

type FeatureEventMetadata added in v1.41.0

type FeatureEventMetadata = map[string]interface{}

type Manager added in v1.42.0

type Manager[T ExportableEvent] interface {
	AddEvent(event T)
	Start()
	Stop()
}

func NewManager added in v1.42.0

func NewManager[T ExportableEvent](ctx context.Context, exporters []Config,
	exporterCleanQueueInterval time.Duration, logger *fflog.FFLogger) Manager[T]

type TrackingEvent added in v1.44.0

type TrackingEvent 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 event.
	Key string `json:"key" example:"my-feature-flag" parquet:"name=key, type=BYTE_ARRAY, convertedtype=UTF8"`

	// EvaluationContext contains the evaluation context used for the tracking
	EvaluationContext map[string]any `` /* 157-byte string literal not displayed */

	// TrackingDetails contains the details of the tracking event
	TrackingDetails TrackingEventDetails `` /* 163-byte string literal not displayed */
}

TrackingEvent represent an Event that we store in the data storage nolint:lll

func (TrackingEvent) FormatInCSV added in v1.44.0

func (f TrackingEvent) FormatInCSV(csvTemplate *template.Template) ([]byte, error)

func (TrackingEvent) FormatInJSON added in v1.44.0

func (f TrackingEvent) FormatInJSON() ([]byte, error)

func (TrackingEvent) GetCreationDate added in v1.44.0

func (f TrackingEvent) GetCreationDate() int64

GetCreationDate returns the creationDate of the event.

func (TrackingEvent) GetKey added in v1.44.0

func (f TrackingEvent) GetKey() string

func (TrackingEvent) GetUserKey added in v1.44.0

func (f TrackingEvent) GetUserKey() string

GetUserKey returns the user key of the event

type TrackingEventDetails added in v1.44.0

type TrackingEventDetails = map[string]interface{}

Jump to

Keyboard shortcuts

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