Documentation ¶
Index ¶
- Constants
- func Aggregate(schemaUsageInfos []*graphqlmetricsv12.SchemaUsageInfo) []*graphqlmetricsv12.SchemaUsageInfo
- type Attributes
- type BatchQueue
- type BatchQueueOptions
- type Exporter
- type ExporterSettings
- type NoopExporter
- type QueueItem
- type QueueWork
- type RetryOptions
- type SchemaUsageExporter
- type SchemaUsageInfo
Constants ¶
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 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) Record ¶
func (e *Exporter) Record(item *graphqlmetricsv12.SchemaUsageInfo) bool
Record records the items as potential metrics to be exported.
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 (e *NoopExporter) Record(_ *graphqlmetricsv12.SchemaUsageInfo) bool
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.
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 SchemaUsageExporter ¶
type SchemaUsageExporter interface { Record(item *graphqlmetricsv12.SchemaUsageInfo) bool ForceFlush(ctx context.Context) error Shutdown(ctx context.Context) error }
func NewExporter ¶
func NewExporter(logger *zap.Logger, client graphqlmetricsv1connect.GraphQLMetricsServiceClient, apiToken string, settings *ExporterSettings) (SchemaUsageExporter, error)
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 ¶
func (e *SchemaUsageInfo) Item() *graphqlmetricsv12.SchemaUsageInfo