Documentation
¶
Overview ¶
Package exporter defines the data exporter of semaphore
These exporters are usable in your init configuration.
client, err := ffclient.New(&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
- func ComputeFilename(tmpl *template.Template, format string) (string, error)
- func EventSize(event ExportableEvent) int
- func FlushID(ctx context.Context) uint64
- func ParseTemplate(name, templateToParse, defaultTemplate string) *template.Template
- type AsyncManager
- type CommonExporter
- type Config
- type DataExporter
- type DeprecatedExporterV1deprecated
- type DeprecatedExporterV2
- type DroppedEventsCounter
- type EventList
- type EventStore
- type EventStoreItem
- type ExportableEvent
- type Exporter
- type FeatureEvent
- func (f *FeatureEvent) ConvertValueForParquet() (string, error)
- func (f *FeatureEvent) FormatInCSV(csvTemplate *template.Template) ([]byte, error)
- func (f *FeatureEvent) FormatInJSON() ([]byte, error)
- func (f *FeatureEvent) GetCreationDate() int64
- func (f *FeatureEvent) GetKey() string
- func (f *FeatureEvent) GetUserKey() string
- type FeatureEventMetadata
- type Manager
- type TrackingEvent
- type TrackingEventDetails
Constants ¶
const DefaultCsvTemplate = "{{ .Kind}};{{ .ContextKind}};{{ .UserKey}};{{ .CreationDate}};{{ .Key}};{{ .Variation}};" +
"{{ .Value}};{{ .Default}};{{ .Source}}\n"
DefaultCsvTemplate is the template of a CSV line for an evaluation event.
const DefaultExporterCleanQueueInterval = 1 * time.Minute
DefaultExporterCleanQueueInterval is the interval at which the exporter queues are cleaned.
const DefaultFilenameTemplate = "flag-variation-{{ .Hostname}}-{{ .Timestamp}}.{{ .Format}}"
DefaultFilenameTemplate is the template of the file name of an exported file.
const DefaultMinQueuedEvents = 50000
DefaultMinQueuedEvents is the floor of the default limit of queued events.
const DefaultQueuedEventsFactor = 4
DefaultQueuedEventsFactor is the default hard limit of events kept in memory by a manager, expressed as a multiple of the largest MaxEventInMemory of its exporters, with a floor of DefaultMinQueuedEvents so that a small MaxEventInMemory does not make a healthy but slowish exporter (a flush that takes some milliseconds) lose events in a burst. See Config.MaxQueuedEvents.
Variables ¶
This section is empty.
Functions ¶
func ComputeFilename ¶
ComputeFilename is computing the filename to use for the export file.
func EventSize ¶ added in v0.2.0
func EventSize(event ExportableEvent) int
EventSize is the size of an event for the byte limit of an exporter: the length of its JSON form, which ends with the line break that separates two events in a file. An event that cannot be formatted counts as one byte.
func FlushID ¶ added in v0.2.0
FlushID is the number of the flush that a batch belongs to, from the context the event store gives to the exporter: the batches of one flush share it. It is 0 for a call that is not part of a numbered flush.
func ParseTemplate ¶
ParseTemplate is parsing the template given by the config or use the default template.
Types ¶
type AsyncManager ¶
type AsyncManager[T ExportableEvent] interface { QueueEvents(events []T) }
AsyncManager is implemented by the managers that can add events without waiting for the exporters (see managerImpl.QueueEvents).
type CommonExporter ¶
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
}
CommonExporter is the interface shared by the exporters.
type Config ¶
type Config struct {
Exporter CommonExporter
// Now is the clock of the pause after a failed flush (see MaxFlushBackoff); nil is [time.Now]. A test injects it.
Now func() time.Time
FlushInterval time.Duration
MaxEventInMemory int64
// MaxQueuedEvents is the hard limit of events kept in memory while they wait to be exported.
// When it is reached (exporter slow or failing) new events are dropped and counted.
// Default: max(DefaultQueuedEventsFactor x MaxEventInMemory, DefaultMinQueuedEvents).
MaxQueuedEvents int64
// MaxBytes, when above zero, makes the manager flush as soon as the events it holds for the exporter reach
// that size (see EventSize), whatever their count and the flush interval, and hands them over in batches of at
// most that size (an event larger than it goes alone). Zero: no byte limit.
//
// MaxBytes only works with the event store of the manager (NewManager): it needs the batch reading and the size
// of the events (ProcessPendingBatches, SetSizer), which the concrete store has and the EventStore interface does
// not. A store of your own that does not implement them ignores MaxBytes and hands the events over in one batch.
MaxBytes int64
// MaxFlushBackoff is the longest pause between the flushes that the event count triggers while the exporter keeps
// failing: the pause starts at one second, doubles with each failed flush up to this value, and the first
// success resets it. Zero, or a value up to one second, keeps the fixed pause of one second (the default
// outside the relay proxy).
MaxFlushBackoff time.Duration
}
Config is the configuration of an exporter.
type DataExporter ¶
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 }
DataExporter is an exporter that receives the evaluation events of type T.
func NewDataExporter ¶
func NewDataExporter[T ExportableEvent](exporter Config, consumerID string, eventStore EventStore[T], logger *slog.Logger) 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
deprecated
type DeprecatedExporterV1 interface {
CommonExporter
// Export will send the data to the exporter.
Export(ctx context.Context, logger *log.Logger, events []*FeatureEvent) error
}
DeprecatedExporterV1 is an interface to describe how an exporter looks like.
Deprecated: use Exporter instead.
type DeprecatedExporterV2 ¶
type DeprecatedExporterV2 interface {
CommonExporter
Export(ctx context.Context, logger *slog.Logger, events []*FeatureEvent) error
}
DeprecatedExporterV2 is the previous exporter interface, kept for compatibility.
type DroppedEventsCounter ¶
type DroppedEventsCounter interface {
DroppedEvents() int64
}
DroppedEventsCounter is implemented by the managers that can tell how many events they had to drop because their queue was full (see Config.MaxQueuedEvents).
type EventList ¶
type EventList[T ExportableEvent] struct { Events []T InitialOffset int64 NewOffset int64 }
EventList is a list of evaluation events of type T.
type EventStore ¶
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 ¶
func NewEventStore[T ExportableEvent](cleanQueueInterval time.Duration) EventStore[T]
NewEventStore creates an event store without any limit on the number of events it keeps. Prefer NewEventStoreWithLimit for anything that must be memory stable.
func NewEventStoreWithLimit ¶
func NewEventStoreWithLimit[T ExportableEvent]( cleanQueueInterval time.Duration, maxEvents int64, onDrop func(totalDropped int64), ) EventStore[T]
NewEventStoreWithLimit creates an event store that keeps at most maxEvents events (0 means unlimited).
Drop policy: when the store is full the NEW event is dropped (drop-newest). Events already stored are never discarded, so a batch that a consumer is exporting (or retrying) is never invalidated and the order of the events is preserved; the cost of a drop is O(1) and does not touch the consumers' offsets. Every drop is counted (see DroppedEvents) and reported to onDrop. A store only fills up when a consumer is not able to keep up (exporter slow or failing): the events lost are the ones that arrive while the exporter is unavailable, which is also what would be lost with a drop-oldest policy, only the time range differs.
type EventStoreItem ¶
type EventStoreItem[T ExportableEvent] struct { Data T Offset int64 // Cum is the size of the events stored up to this one, this one included, since the store was created; Size is // the size of this one (see SetSizer). Both are zero when the store has no sizer. Cum int64 Size int }
EventStoreItem is an item of the event store that wraps one event of type T.
type ExportableEvent ¶
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)
}
ExportableEvent is an event that can be sent to the exporters.
type Exporter ¶
type Exporter interface {
CommonExporter
Export(ctx context.Context, logger *slog.Logger, events []ExportableEvent) error
}
Exporter sends evaluation events to a destination.
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 `example:"feature" json:"kind" 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 `example:"user" json:"contextKind,omitempty" 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 `example:"94a25909-20d8-40cc-8500-fee99b569345" json:"userKey" parquet:"name=userKey, type=BYTE_ARRAY, convertedtype=UTF8"`
// CreationDate When the feature flag was requested at Unix epoch time in milliseconds.
CreationDate int64 `example:"1680246000011" json:"creationDate" parquet:"name=creationDate, type=INT64"`
// Key of the feature flag requested.
Key string `example:"my-feature-flag" json:"key" 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 `example:"admin-variation" json:"variation" parquet:"name=variation, type=BYTE_ARRAY, convertedtype=UTF8"`
// Value of the feature flag returned by feature flag evaluation.
Value any `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 `example:"false" json:"default" 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 `example:"v1.0.0" json:"version" 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 `example:"SERVER" json:"source" 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
func NewFeatureEvent ¶
func NewFeatureEvent( ctx ffcontext.Context, flagKey string, value any, variation string, failed bool, version, source string, metadata FeatureEventMetadata, ) *FeatureEvent
NewFeatureEvent returns a feature event for an evaluation of a flag.
func (*FeatureEvent) ConvertValueForParquet ¶
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 ¶
func (f *FeatureEvent) FormatInCSV(csvTemplate *template.Template) ([]byte, error)
FormatInCSV returns the feature event formatted as a CSV line using csvTemplate.
func (*FeatureEvent) FormatInJSON ¶
func (f *FeatureEvent) FormatInJSON() ([]byte, error)
FormatInJSON returns the feature event formatted as JSON.
func (*FeatureEvent) GetCreationDate ¶
func (f *FeatureEvent) GetCreationDate() int64
GetCreationDate returns the creationDate of the event.
func (*FeatureEvent) GetKey ¶
func (f *FeatureEvent) GetKey() string
GetKey returns the key of the event.
func (*FeatureEvent) GetUserKey ¶
func (f *FeatureEvent) GetUserKey() string
GetUserKey returns the user key of the event.
type FeatureEventMetadata ¶
FeatureEventMetadata holds the metadata attached to a feature event.
type Manager ¶
type Manager[T ExportableEvent] interface { AddEvent(event T) Start() Stop() }
Manager collects evaluation events and sends them to the exporters.
func NewManager ¶
func NewManager[T ExportableEvent](exporters []Config, exporterCleanQueueInterval time.Duration, logger *slog.Logger, ) Manager[T]
NewManager returns a manager that sends evaluation events to the exporters.
type TrackingEvent ¶
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 `example:"feature" json:"kind" 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 `example:"user" json:"contextKind,omitempty" 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 `example:"94a25909-20d8-40cc-8500-fee99b569345" json:"userKey" parquet:"name=userKey, type=BYTE_ARRAY, convertedtype=UTF8"`
// CreationDate When the feature flag was requested at Unix epoch time in milliseconds.
CreationDate int64 `example:"1680246000011" json:"creationDate" parquet:"name=creationDate, type=INT64"`
// Key of the event.
Key string `example:"my-feature-flag" json:"key" 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
func (*TrackingEvent) FormatInCSV ¶
func (f *TrackingEvent) FormatInCSV(csvTemplate *template.Template) ([]byte, error)
FormatInCSV returns the tracking event formatted as a CSV line using csvTemplate.
func (*TrackingEvent) FormatInJSON ¶
func (f *TrackingEvent) FormatInJSON() ([]byte, error)
FormatInJSON returns the tracking event formatted as JSON.
func (*TrackingEvent) GetCreationDate ¶
func (f *TrackingEvent) GetCreationDate() int64
GetCreationDate returns the creationDate of the event.
func (*TrackingEvent) GetKey ¶
func (f *TrackingEvent) GetKey() string
GetKey returns the key of the tracking event.
func (*TrackingEvent) GetUserKey ¶
func (f *TrackingEvent) GetUserKey() string
GetUserKey returns the user key of the event.
type TrackingEventDetails ¶
TrackingEventDetails holds the details attached to a tracking event.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package azureexporter implements the exporter that sends evaluation events to Azure Blob Storage.
|
Package azureexporter implements the exporter that sends evaluation events to Azure Blob Storage. |
|
Package bigqueryexporter implements the exporter that writes evaluation events to BigQuery.
|
Package bigqueryexporter implements the exporter that writes evaluation events to BigQuery. |
|
Package fileexporter implements the exporter that writes evaluation events to local files.
|
Package fileexporter implements the exporter that writes evaluation events to local files. |
|
Package gcstorageexporter implements the exporter that writes evaluation events to Google Cloud Storage.
|
Package gcstorageexporter implements the exporter that writes evaluation events to Google Cloud Storage. |
|
Package kafkaexporter implements the exporter that publishes evaluation events to Kafka.
|
Package kafkaexporter implements the exporter that publishes evaluation events to Kafka. |
|
Package kinesisexporter implements the exporter that sends evaluation events to Amazon Kinesis.
|
Package kinesisexporter implements the exporter that sends evaluation events to Amazon Kinesis. |
|
Package logsexporter implements the exporter that writes evaluation events to the logs.
|
Package logsexporter implements the exporter that writes evaluation events to the logs. |
|
Package opentelemetryexporter implements the exporter that sends evaluation events as OpenTelemetry logs.
|
Package opentelemetryexporter implements the exporter that sends evaluation events as OpenTelemetry logs. |
|
Package pubsubexporter implements the exporter that publishes evaluation events to Google Pub/Sub.
|
Package pubsubexporter implements the exporter that publishes evaluation events to Google Pub/Sub. |
|
Package pubsubexporterv2 implements the exporter that publishes evaluation events to Google Pub/Sub, v2 client.
|
Package pubsubexporterv2 implements the exporter that publishes evaluation events to Google Pub/Sub, v2 client. |
|
Package redshiftexporter implements the exporter that loads evaluation events into Amazon Redshift.
|
Package redshiftexporter implements the exporter that loads evaluation events into Amazon Redshift. |
|
Package s3exporterv2 implements the exporter that uploads evaluation events to Amazon S3.
|
Package s3exporterv2 implements the exporter that uploads evaluation events to Amazon S3. |
|
Package sqsexporter implements the exporter that sends evaluation events to Amazon SQS.
|
Package sqsexporter implements the exporter that sends evaluation events to Amazon SQS. |
|
Package webhookexporter implements the exporter that posts evaluation events to a webhook.
|
Package webhookexporter implements the exporter that posts evaluation events to a webhook. |