metrics

package module
v0.0.0-...-0c27e45 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: Apache-2.0 Imports: 18 Imported by: 3

README

Metrics Client Library

This library provides a gRPC-based metrics ingestion client. It allows you to define custom metric types, serialize them using Avro, and send them to a backend service using a streaming gRPC API. It handles automatic batching, chunking, retries, and error handling.

Documentation

Index

Constants

View Source
const (
	MaxAllowedChunkSize = 20 * 1024 * 1024 // 20MB
)

Variables

This section is empty.

Functions

func NewAPI

func NewAPI(apiAddr, clusterID, token string, isInsecure bool) (*grpc.ClientConn, pb.IngestionAPIClient, error)

Types

type ClientOption

type ClientOption func(*metricClient)

func WithDrainTimeout

func WithDrainTimeout(timeout time.Duration) ClientOption

func WithFlushInterval

func WithFlushInterval(interval time.Duration) ClientOption

func WithMaxRetryTimeout

func WithMaxRetryTimeout(timeout time.Duration) ClientOption

type Config

type Config struct {
	APIAddr   string
	APIToken  string
	ClusterID string
	Insecure  bool
}

type Metric

type Metric[T any] interface {
	Write(datapoints ...T) error
}

func NewMetric

func NewMetric[T any](client MetricClient, opts ...MetricOption[T]) (Metric[T], error)

type MetricClient

type MetricClient interface {
	Start(ctx context.Context) error
	// contains filtered or unexported methods
}

func NewMetricClient

func NewMetricClient(
	cfg Config,
	logger *logging.Logger,
	options ...ClientOption,
) (MetricClient, error)

NewMetricClient creates a new MetricClient instance which is responsible for sending metrics to the ingestion service. It validates the provided configuration, sets up gRPC connection, and initializes the client. The returned client can then be started with the Start method to begin periodic metric flushing.

Parameters:

  • cfg: Configuration struct containing API address, token, cluster ID, and other optional settings.
  • logger: Logger instance for diagnostic and error messages.

Returns:

  • MetricClient: an initialized metrics client ready to start flushing metrics.
  • error: if required parameters are missing or if the gRPC client cannot be created.

type MetricOption

type MetricOption[T any] func(*metric[T]) error

func WithAvroSchema

func WithAvroSchema[T any](schema avro.Schema) MetricOption[T]

func WithCollectionName

func WithCollectionName[T any](name string) MetricOption[T]

func WithMaxChunkSize

func WithMaxChunkSize[T any](size int) MetricOption[T]

func WithSchema

func WithSchema[T any](schema string) MetricOption[T]

func WithSkipTimestamp

func WithSkipTimestamp[T any]() MetricOption[T]

Directories

Path Synopsis
api

Jump to

Keyboard shortcuts

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