handler

package
v0.0.0-...-18a1446 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2019 License: Apache-2.0 Imports: 45 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GetEvalCache = func() *EvalCache {
	singletonEvalCacheOnce.Do(func() {
		ec := &EvalCache{
			mapCache:        make(map[string]*entity.Flag),
			refreshTimeout:  config.Config.EvalCacheRefreshTimeout,
			refreshInterval: config.Config.EvalCacheRefreshInterval,
		}
		singletonEvalCache = ec
	})
	return singletonEvalCache
}

GetEvalCache gets the EvalCache

View Source
var NewKafkaRecorder = func() DataRecorder {
	cfg := sarama.NewConfig()
	tlscfg := createTLSConfiguration(
		config.Config.RecorderKafkaCertFile,
		config.Config.RecorderKafkaKeyFile,
		config.Config.RecorderKafkaCAFile,
		config.Config.RecorderKafkaVerifySSL,
	)
	if tlscfg != nil {
		cfg.Net.TLS.Enable = true
		cfg.Net.TLS.Config = tlscfg
	}
	cfg.Producer.RequiredAcks = sarama.WaitForLocal
	cfg.Producer.Retry.Max = config.Config.RecorderKafkaRetryMax
	cfg.Producer.Flush.Frequency = config.Config.RecorderKafkaFlushFrequency
	cfg.Version = mustParseKafkaVersion(config.Config.RecorderKafkaVersion)

	brokerList := strings.Split(config.Config.RecorderKafkaBrokers, ",")
	producer, err := saramaNewAsyncProducer(brokerList, cfg)
	if err != nil {
		logrus.WithField("kafka_error", err).Fatal("Failed to start Sarama producer:")
	}

	if producer != nil {
		go func() {
			for err := range producer.Errors() {
				logrus.WithField("kafka_error", err).Error("failed to write access log entry")
			}
		}()
	}

	return &kafkaRecorder{
		producer: producer,
		topic:    config.Config.RecorderKafkaTopic,
		enabled:  config.Config.RecorderEnabled,
	}
}

NewKafkaRecorder creates a new Kafka recorder

View Source
var NewKinesisRecorder = func() DataRecorder {
	client := kinesis.New(session.New(aws.NewConfig()))

	p := newKinesisProducer(&producer.Config{
		StreamName:          config.Config.RecorderKinesisStreamName,
		Client:              client,
		BacklogCount:        config.Config.RecorderKinesisBacklogCount,
		MaxConnections:      config.Config.RecorderKinesisMaxConnections,
		FlushInterval:       config.Config.RecorderKinesisFlushInterval,
		BatchSize:           config.Config.RecorderKinesisBatchSize,
		BatchCount:          config.Config.RecorderKinesisBatchCount,
		AggregateBatchCount: config.Config.RecorderKinesisAggregateBatchCount,
		AggregateBatchSize:  config.Config.RecorderKinesisAggregateBatchSize,
		Verbose:             config.Config.RecorderKinesisVerbose,
		Logger:              logrus.WithField("producer", "kinesis"),
	})

	p.Start()

	go func() {
		for err := range p.NotifyFailures() {
			logrus.WithField("kinesis_error", err).Error("error pushing to kinesis")
		}
	}()

	return &kinesisRecorder{
		producer: p,
		enabled:  config.Config.RecorderEnabled,
	}
}

NewKinesisRecorder creates a new Kinesis recorder

View Source
var NewPubsubRecorder = func() DataRecorder {
	client, err := pubsubClient()
	if err != nil {
		logrus.WithField("pubsub_error", err).Fatal("error getting pubsub client")
	}

	return &pubsubRecorder{
		producer: client,
		topic:    client.Topic(config.Config.RecorderPubsubTopicName),
	}
}

NewPubsubRecorder creates a new Pubsub recorder

Functions

func BlankResult

func BlankResult(f *entity.Flag, evalContext models.EvalContext, msg string) *models.EvalResult

BlankResult creates a blank result

func ErrorMessage

func ErrorMessage(s string, data ...interface{}) *models.Error

ErrorMessage generates error messages

func Setup

func Setup(api *operations.FlagrAPI)

Setup initialize all the handler functions

Types

type CRUD

type CRUD interface {
	// Flags
	FindFlags(flag.FindFlagsParams) middleware.Responder
	CreateFlag(flag.CreateFlagParams) middleware.Responder
	GetFlag(flag.GetFlagParams) middleware.Responder
	PutFlag(flag.PutFlagParams) middleware.Responder
	DeleteFlag(flag.DeleteFlagParams) middleware.Responder
	SetFlagEnabledState(flag.SetFlagEnabledParams) middleware.Responder
	GetFlagSnapshots(params flag.GetFlagSnapshotsParams) middleware.Responder
	GetFlagEntityTypes(params flag.GetFlagEntityTypesParams) middleware.Responder

	// Segments
	CreateSegment(segment.CreateSegmentParams) middleware.Responder
	FindSegments(segment.FindSegmentsParams) middleware.Responder
	PutSegment(segment.PutSegmentParams) middleware.Responder
	DeleteSegment(segment.DeleteSegmentParams) middleware.Responder
	PutSegmentsReorder(segment.PutSegmentsReorderParams) middleware.Responder

	// Constraints
	CreateConstraint(constraint.CreateConstraintParams) middleware.Responder
	FindConstraints(constraint.FindConstraintsParams) middleware.Responder
	PutConstraint(params constraint.PutConstraintParams) middleware.Responder
	DeleteConstraint(params constraint.DeleteConstraintParams) middleware.Responder

	// Distributions
	FindDistributions(distribution.FindDistributionsParams) middleware.Responder
	PutDistributions(distribution.PutDistributionsParams) middleware.Responder

	// Variants
	CreateVariant(variant.CreateVariantParams) middleware.Responder
	FindVariants(variant.FindVariantsParams) middleware.Responder
	PutVariant(variant.PutVariantParams) middleware.Responder
	DeleteVariant(variant.DeleteVariantParams) middleware.Responder
}

CRUD is the CRUD interface

func NewCRUD

func NewCRUD() CRUD

NewCRUD creates a new CRUD instance

type DataRecorder

type DataRecorder interface {
	AsyncRecord(*models.EvalResult)
}

DataRecorder can record and produce the evaluation result

func GetDataRecorder

func GetDataRecorder() DataRecorder

GetDataRecorder gets the data recorder

type Error

type Error struct {
	StatusCode int
	Message    string
	Values     []interface{}
}

Error is the handler error

func NewError

func NewError(statusCode int, msg string, values ...interface{}) *Error

NewError creates Error

func (*Error) Error

func (e *Error) Error() string

type Eval

type Eval interface {
	PostEvaluation(evaluation.PostEvaluationParams) middleware.Responder
	PostEvaluationBatch(evaluation.PostEvaluationBatchParams) middleware.Responder
}

Eval is the Eval interface

func NewEval

func NewEval() Eval

NewEval creates a new Eval instance

type EvalCache

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

EvalCache is the in-memory cache just for evaluation

func GenFixtureEvalCache

func GenFixtureEvalCache() *EvalCache

GenFixtureEvalCache generates a fixture

func (*EvalCache) GetByFlagKeyOrID

func (ec *EvalCache) GetByFlagKeyOrID(keyOrID interface{}) *entity.Flag

GetByFlagKeyOrID gets the flag by Key or ID

func (*EvalCache) Start

func (ec *EvalCache) Start()

Start starts the polling of EvalCache

Jump to

Keyboard shortcuts

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