usagereporter

package
v0.0.0-...-5c79d48 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	UsagePrometheusCollectors = []prometheus.Collector{
		usageEventsSubmitted, usageBatchesTotal, usageEventsRequeuedTotal,
		usageBatchSubmissionDuration, usageBatchesSubmitted, usageBatchesFailed,
		usageEventsDropped,
	}
)

Functions

This section is empty.

Types

type Options

type Options[T any] struct {
	Log logrus.FieldLogger
	// Submit is a func that submits a batch of usage events.
	Submit SubmitFunc[T]
	// MinBatchSize determines the size at which a batch is sent
	// regardless of elapsed time.
	MinBatchSize int
	// MaxBatchSize is the largest batch size that will be sent to
	// the server; batches larger than this will be split into multiple
	// requests.
	MaxBatchSize int
	// MaxBatchAge is the maximum age a batch may reach before
	// being flushed, regardless of the batch size
	MaxBatchAge time.Duration
	// MaxBufferSize is the maximum size to which the event buffer
	// may grow. Events submitted once this limit is reached will be discarded.
	// Events that were in the submission queue that fail to submit may also be
	// discarded when requeued.
	MaxBufferSize int
	// SubmitDelay is a mandatory delay added to each batch submission
	// to avoid spamming the prehog instance.
	SubmitDelay time.Duration
	// RetryAttempts is the number of attempts that should be made to
	// submit a single event.
	RetryAttempts int
	// Clock is the clock used for the main batching goroutine
	Clock clockwork.Clock
	// SubmitClock is the clock used for the submission goroutine
	SubmitClock clockwork.Clock
}

type SubmitFunc

type SubmitFunc[T any] func(reporter *UsageReporter[T], batch []*SubmittedEvent[T]) ([]*SubmittedEvent[T], error)

SubmitFunc is a func that submits a batch of usage events.

type SubmittedEvent

type SubmittedEvent[T any] struct {
	// Event is the Event to attempt to send
	Event *T
	// contains filtered or unexported fields
}

SubmittedEvent is an event that has been submitted

type UsageReporter

type UsageReporter[T any] struct {
	// Entry is a log entry
	*logrus.Entry
	// contains filtered or unexported fields
}

func NewUsageReporter

func NewUsageReporter[T any](options *Options[T]) *UsageReporter[T]

NewUsageReporter creates a new usage reporter. `Run()` must be executed to process incoming events.

func (*UsageReporter[T]) AddEventsToQueue

func (r *UsageReporter[T]) AddEventsToQueue(events ...*T)

func (*UsageReporter[T]) GracefulStop

func (r *UsageReporter[T]) GracefulStop(ctx context.Context) error

GracefulStop stops receiving new events and schedules the final batch for submission. It blocks until the final batch has been sent, or until the provided context is canceled. Run must be called before GracefulStop is called.

func (*UsageReporter[T]) Run

func (r *UsageReporter[T]) Run(ctx context.Context)

Run begins processing incoming usage events. It should be run in a goroutine.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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