events

package
v6.9.1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package events contains the internal implementation of event forwarding.

This is an internal package; application code for specific Relay distributions should not need to reference it directly, only the core code.

Index

Constants

View Source
const (
	// SummaryEventsSchemaVersion is the minimum event schema that supports summary events.
	SummaryEventsSchemaVersion = 3

	// EventSchemaHeader is an HTTP header that describes the schema version for event requests.
	EventSchemaHeader = "X-LaunchDarkly-Event-Schema"

	// TagsHeader is an HTTP header that may be sent by SDKs that support application metadata.
	// We copy the value of this header when proxying events.
	TagsHeader = "X-LaunchDarkly-Tags"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type EventDispatcher

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

EventDispatcher relays events to LaunchDarkly for an environment

func NewEventDispatcher

func NewEventDispatcher(
	sdkKey c.SDKKey,
	mobileKey c.MobileKey,
	envID c.EnvironmentID,
	loggers ldlog.Loggers,
	config c.EventsConfig,
	httpConfig httpconfig.HTTPConfig,
	storeAdapter *store.SSERelayDataStoreAdapter,
	eventQueueCleanupInterval time.Duration,
) *EventDispatcher

NewEventDispatcher creates a handler for relaying events to LaunchDarkly for an environment

func (*EventDispatcher) Close

func (r *EventDispatcher) Close()

Close shuts down any goroutines/channels being used by the EventDispatcher.

func (*EventDispatcher) GetHandler

func (r *EventDispatcher) GetHandler(sdkKind basictypes.SDKKind, eventsKind ldevents.EventDataKind) func(w http.ResponseWriter, req *http.Request)

GetHandler returns the HTTP handler for an endpoint, or nil if none is defined

func (*EventDispatcher) ReplaceCredential

func (r *EventDispatcher) ReplaceCredential(newCredential c.SDKCredential)

ReplaceCredential changes the authorization credentail that is used when forwarding events to any endpoints that use that type of credential. For instance, if newCredential is a MobileKey, this affects only endpoints that use a mobile key.

type EventPayloadMetadata added in v6.7.0

type EventPayloadMetadata struct {
	// SchemaVersion is the numeric value of the X-LaunchDarkly-Event-Schema header, or 1 if unknown
	// (in version 1, this header was not used).
	SchemaVersion int
	// Tags is the value of the X-LaunchDarkly-Tags header, or "" if none.
	Tags string
}

EventPayloadMetadata represents HTTP header metadata that may be included in an event post from an SDK, which Relay should copy when it forwards the events to LaunchDarkly.

func GetEventPayloadMetadata added in v6.7.0

func GetEventPayloadMetadata(req *http.Request) EventPayloadMetadata

GetEventPayloadMetadata parses EventPayloadMetadata values from an HTTP request.

type EventPublisher

type EventPublisher interface {
	// Publish adds any number of JSON elements to the queue.
	//
	// The EventPayloadMetadata value provides a way to distinguish between batches of events that have
	// different header metadata. If no such distinction is needed, it can simply be an empty
	// EventPayloadMetadata{}. Otherwise, each distinct value of EventPayloadMetadata gets its own event
	// queue, all of which will be flushed at the same time but delivered in separate HTTP posts.
	Publish(EventPayloadMetadata, ...json.RawMessage)

	// Flush attempts to deliver all queued events.
	Flush()

	// ReplaceCredential changes the authorization credential used when sending events, if the previous
	// credential was of the same type.
	ReplaceCredential(config.SDKCredential)

	// Close releases all resources used by this object.
	Close()
}

EventPublisher is the interface for the component that buffers events and delivers them to LaunchDarkly. Events are treated as raw JSON data; the component does not do any parsing or transformation of them.

A single instance of the component exists for each environment, associated with a single credential (such as an SDK key). However, it can maintain multiple buffers if it is necessary to deliver events in separate batches due to SDKs providing different header metadata, as represented by EventPublisherContext.

The only implementation of this in Relay is HTTPEventPublisher. It is an interface only so that it can be mocked in test code.

type HTTPEventPublisher

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

HTTPEventPublisher is the standard implementation of EventPublisher.

func NewHTTPEventPublisher

func NewHTTPEventPublisher(authKey config.SDKCredential, httpConfig httpconfig.HTTPConfig, loggers ldlog.Loggers, options ...OptionType) (*HTTPEventPublisher, error)

NewHTTPEventPublisher creates a new HTTPEventPublisher.

func (*HTTPEventPublisher) Close

func (p *HTTPEventPublisher) Close()

func (*HTTPEventPublisher) Flush

func (p *HTTPEventPublisher) Flush()

func (*HTTPEventPublisher) Publish

func (p *HTTPEventPublisher) Publish(metadata EventPayloadMetadata, events ...json.RawMessage)

func (*HTTPEventPublisher) ReplaceCredential

func (p *HTTPEventPublisher) ReplaceCredential(newCredential config.SDKCredential)

type OptionCapacity

type OptionCapacity int

OptionCapacity specifies the event queue capacity.

type OptionEndpointURI

type OptionEndpointURI string

OptionEndpointURI specifies a complete custom URI for the events service (not a base URI).

type OptionFlushInterval

type OptionFlushInterval time.Duration

OptionFlushInterval specifies the interval for automatic flushes.

type OptionType

type OptionType interface {
	// contains filtered or unexported methods
}

OptionType defines optional parameters for NewHTTPEventPublisher.

type OptionURI

type OptionURI string

OptionURI specifies a custom base URI for the events service.

Jump to

Keyboard shortcuts

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