bucketeer

package
Version: v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2021 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterMetrics added in v1.2.0

func RegisterMetrics() error

RegisterMetrics begins collecting data for the OpenCensus views.

NOTE: Currently, we only support OpenCensus to provide metrics, but we would support other libraries if there is a demand. In that time, we will add a breaking change to support them.

Types

type Option

type Option func(*options)

Option is the functional options type (Functional Options Pattern) to set sdk options.

func WithAPIKey

func WithAPIKey(apiKey string) Option

WithAPIKey sets apiKey to use Bucketeer service. (Default: "")

func WithEnableDebugLog

func WithEnableDebugLog(enableDebugLog bool) Option

WithEnableDebugLog sets if outpus debug logs or not. (Default: false)

Debug logs are for Bucketeer SDK developers.

func WithErrorLogger

func WithErrorLogger(errorLogger log.BaseLogger) Option

WithErrorLogger sets a looger to output error logs. (Default: log.DefaultErrorLogger)

Error logs are for Bucketeer SDK users.

func WithEventFlushInterval

func WithEventFlushInterval(eventFlushInterval time.Duration) Option

WithEventFlushInterval sets a interval of flushing events. (Default: 1 min)

Each worker sends the events to Bucketeer service every time eventFlushInterval elapses or its buffer exceeds eventFlushSize.

func WithEventFlushSize

func WithEventFlushSize(eventFlushSize int) Option

WithEventFlushSize sets a size of the buffer for each worker. (Default: 100)

Each worker sends the events to Bucketeer service every time eventFlushInterval elapses or its buffer exceeds eventFlushSize.

func WithEventQueueCapacity

func WithEventQueueCapacity(eventQueueCapacity int) Option

WithEventQueueCapacity sets a capacity of the event queue. (Default: 100_000)

The SDK buffers events up to the capacity in memory before processing. If the capacity is exceeded, events will be discarded.

func WithHost

func WithHost(host string) Option

WithHost sets host name for the Bucketeer service. (Default: "")

func WithNumEventFlushWorkers

func WithNumEventFlushWorkers(numEventFlushWorkers int) Option

WithNumEventFlushWorkers sets a number of workers to flush events. (Default: 50)

func WithPort

func WithPort(port int) Option

WithPort sets port for the Bucketeer service. (Default: 443)

func WithTag

func WithTag(tag string) Option

WithTag sets tag specified in getting evaluation. (Default: "")

type SDK

type SDK interface {
	// BoolVariation returns the value of a feature flag (whose variations are booleans) for the given user.
	//
	// BoolVariation returns defaultValue if an error occurs.
	BoolVariation(ctx context.Context, user *User, featureID string, defaultValue bool) bool

	// IntVariation returns the value of a feature flag (whose variations are ints) for the given user.
	//
	// IntVariation returns defaultValue if an error occurs.
	IntVariation(ctx context.Context, user *User, featureID string, defaultValue int) int

	// Int64Variation returns the value of a feature flag (whose variations are int64s) for the given user.
	//
	// Int64Variation returns defaultValue if an error occurs.
	Int64Variation(ctx context.Context, user *User, featureID string, defaultValue int64) int64

	// Float64Variation returns the value of a feature flag (whose variations are float64s) for the given user.
	//
	// Float64Variation returns defaultValue if an error occurs.
	Float64Variation(ctx context.Context, user *User, featureID string, defaultValue float64) float64

	// StringVariation returns the value of a feature flag (whose variations are strings) for the given user.
	//
	// StringVariation returns defaultValue if an error occurs.
	StringVariation(ctx context.Context, user *User, featureID, defaultValue string) string

	// JSONVariation parses the value of a feature flag (whose variations are jsons) for the given user,
	// and stores the result in dst.
	JSONVariation(ctx context.Context, user *User, featureID string, dst interface{})

	// Track reports that a user has performed a goal event.
	//
	// TODO: Track doesn't work correctly until Bucketeer service implements the new goal tracking architecture.
	Track(ctx context.Context, user *User, goalID string)

	// TrackValue reports that a user has performed a goal event, and associates it with a custom value.
	//
	// TODO: TrackValue doesn't work correctly until Bucketeer service implements the new goal tracking architecture.
	TrackValue(ctx context.Context, user *User, goalID string, value float64)

	// Close tears down all SDK activities and resources, after ensuring that all events have been delivered.
	//
	// After calling this, the SDK should no longer be used.
	Close(ctx context.Context) error
}

SDK is the Bucketeer SDK.

SDK represents the ability to get the value of a feature flag and to track goal events by communicating with the Bucketeer service.

A user application should instantiate a single SDK instance for the lifetime of the application and share it. SDK is safe for concurrent use by multiple goroutines.

func NewNopSDK added in v1.1.0

func NewNopSDK() SDK

NewNopSDK creates a new no-op Bucketeer SDK.

It never requests to Bucketeer Service, and just returns default value when XXXVariation methods called.

func NewSDK

func NewSDK(ctx context.Context, opts ...Option) (SDK, error)

NewSDK creates a new Bucketeer SDK.

type User

type User struct {
	*protouser.User
}

User is the Bucketeer user.

User contains a mandatory user id and optional attributes (Data) for the user targeting and the analysis.

func NewUser

func NewUser(id string, attributes map[string]string) *User

NewUser creates a new User.

id is mandatory and attributes is optional.

func (*User) Valid added in v1.0.2

func (u *User) Valid() bool

Valid returns true if valid user, otherwise returns false.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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