graphqlmetrics

package
v0.0.0-...-da53dd4 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// HTTPStatusCodeAttribute is the attribute name for the HTTP status code
	HTTPStatusCodeAttribute = "http.status_code"
)

Variables

This section is empty.

Functions

func Aggregate

func Aggregate(schemaUsageInfos []*graphqlmetricsv12.SchemaUsageInfo) []*graphqlmetricsv12.SchemaUsageInfo

Types

type Attributes

type Attributes = map[string]string

type BatchQueue

type BatchQueue[T any] struct {
	OutQueue chan []QueueWork[T]
	// contains filtered or unexported fields
}

BatchQueue coordinates dispatching of queue items by time intervals or immediately after the batching limit is met. Items are enqueued without blocking and all items are buffered unless the queue is stopped forcefully with the stop() context.

func NewBatchQueue

func NewBatchQueue[T any](config *BatchQueueOptions) *BatchQueue[T]

NewBatchQueue returns an initialized instance of BatchQueue. Items are enqueued without blocking. The queue is dispatched by time intervals or immediately after the batching limit is met. Batches can be read from the OutQueue channel.

func (*BatchQueue[T]) Enqueue

func (b *BatchQueue[T]) Enqueue(item QueueWork[T]) bool

Enqueue adds an item to the queue. Returns false if the queue is stopped or not ready to accept items

func (*BatchQueue[T]) Start

func (b *BatchQueue[T]) Start()

Start begins item dispatching. Should be called only once from a single goroutine. The queue can be stopped by calling Stop().

func (*BatchQueue[T]) Stop

func (b *BatchQueue[T]) Stop()

Stop stops the internal dispatch and listen scheduler.

type BatchQueueOptions

type BatchQueueOptions struct {
	Interval      time.Duration // wait time when batch quantity is insufficient
	MaxBatchItems int           // maximum items per batch
	MaxQueueSize  int           // maximum queue size
}

BatchQueueOptions configure time interval and set a batch limit.

type Exporter

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

func (*Exporter) ForceFlush

func (e *Exporter) ForceFlush(ctx context.Context) error

func (*Exporter) Record

Record records the items as potential metrics to be exported.

func (*Exporter) Shutdown

func (e *Exporter) Shutdown(ctx context.Context) error

Shutdown the exporter but waits until all export jobs has been finished or timeout. If the context is canceled, the exporter will be shutdown immediately.

type ExporterSettings

type ExporterSettings struct {
	// NumConsumers is the number of consumers from the queue.
	NumConsumers int
	// BatchSize is the maximum number of items to be sent in a single batch.
	BatchSize int
	// QueueSize is the maximum number of batches allowed in queue at a given time.
	QueueSize int
	// Interval is the interval at which the queue is flushed.
	Interval time.Duration
	// Retry is the retry options for the exporter.
	Retry RetryOptions
	// ExportTimeout is the timeout for the export request.
	ExportTimeout time.Duration
}

func NewDefaultExporterSettings

func NewDefaultExporterSettings() *ExporterSettings

type NoopExporter

type NoopExporter struct{}

func NewNoopExporter

func NewNoopExporter() *NoopExporter

func (*NoopExporter) ForceFlush

func (e *NoopExporter) ForceFlush(_ context.Context) error

func (*NoopExporter) Record

func (*NoopExporter) Shutdown

func (e *NoopExporter) Shutdown(_ context.Context) error

type QueueItem

type QueueItem[T any] struct {
	// contains filtered or unexported fields
}

QueueItem is the base type for queue items. It implements the QueueWork interface.

func (*QueueItem[T]) Flush

func (e *QueueItem[T]) Flush() chan struct{}

Flush returns a channel that marks a batch as ready to be dispatched once the item is received. On the consumer side this channel can be closed and used as a signal that all prior items were dispatched. We use it in the graphqlmetrics exporter to implement flushing.

func (*QueueItem[T]) Item

func (e *QueueItem[T]) Item() T

type QueueWork

type QueueWork[T any] interface {
	Item() T
	Flush() chan struct{}
}

QueueWork The interface that any item in the queue must implement.

type RetryOptions

type RetryOptions struct {
	Enabled     bool
	MaxDuration time.Duration
	Interval    time.Duration
	MaxRetry    int
}

type SchemaUsageExporter

type SchemaUsageExporter interface {
	Record(item *graphqlmetricsv12.SchemaUsageInfo) bool
	ForceFlush(ctx context.Context) error
	Shutdown(ctx context.Context) error
}

func NewExporter

NewExporter creates a new GraphQL metrics exporter. The collectorEndpoint is the endpoint to which the metrics are sent. The apiToken is the token used to authenticate with the collector. The collector supports Brotli compression and retries on failure. Underling queue implementation sends batches of metrics at the specified interval and batch size.

type SchemaUsageInfo

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

func (*SchemaUsageInfo) Flush

func (e *SchemaUsageInfo) Flush() chan struct{}

func (*SchemaUsageInfo) Item

Jump to

Keyboard shortcuts

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