Documentation ¶
Index ¶
- Constants
- Variables
- func NewOtlpMeterProvider(ctx context.Context, log *zap.Logger, c *Config, serviceInstanceID string) (*sdkmetric.MeterProvider, error)
- func NewPrometheusMeterProvider(ctx context.Context, c *Config, serviceInstanceID string) (*sdkmetric.MeterProvider, *prometheus.Registry, error)
- func NewPrometheusServer(logger *zap.Logger, listenAddr string, path string, ...) *http.Server
- type CacheMetricInfo
- type CacheMetrics
- type Config
- type Measurements
- type Metrics
- func (h *Metrics) Flush(ctx context.Context) error
- func (h *Metrics) MeasureInFlight(ctx context.Context, sliceAttr []attribute.KeyValue, opt otelmetric.AddOption) func()
- func (h *Metrics) MeasureLatency(ctx context.Context, latency time.Duration, sliceAttr []attribute.KeyValue, ...)
- func (h *Metrics) MeasureOperationPlanningTime(ctx context.Context, planningTime time.Duration, ...)
- func (h *Metrics) MeasureRequestCount(ctx context.Context, sliceAttr []attribute.KeyValue, opt otelmetric.AddOption)
- func (h *Metrics) MeasureRequestError(ctx context.Context, sliceAttr []attribute.KeyValue, opt otelmetric.AddOption)
- func (h *Metrics) MeasureRequestSize(ctx context.Context, contentLength int64, sliceAttr []attribute.KeyValue, ...)
- func (h *Metrics) MeasureResponseSize(ctx context.Context, size int64, sliceAttr []attribute.KeyValue, ...)
- func (h *Metrics) Shutdown(ctx context.Context) error
- type NoopMetrics
- func (n NoopMetrics) Flush(ctx context.Context) error
- func (n NoopMetrics) MeasureInFlight(ctx context.Context, sliceAttr []attribute.KeyValue, opt otelmetric.AddOption) func()
- func (n NoopMetrics) MeasureLatency(ctx context.Context, latency time.Duration, sliceAttr []attribute.KeyValue, ...)
- func (n NoopMetrics) MeasureOperationPlanningTime(ctx context.Context, planningTime time.Duration, ...)
- func (n NoopMetrics) MeasureRequestCount(ctx context.Context, sliceAttr []attribute.KeyValue, opt otelmetric.AddOption)
- func (n NoopMetrics) MeasureRequestError(ctx context.Context, sliceAttr []attribute.KeyValue, opt otelmetric.AddOption)
- func (n NoopMetrics) MeasureRequestSize(ctx context.Context, contentLength int64, sliceAttr []attribute.KeyValue, ...)
- func (n NoopMetrics) MeasureResponseSize(ctx context.Context, size int64, sliceAttr []attribute.KeyValue, ...)
- func (n NoopMetrics) Shutdown(ctx context.Context) error
- type OpenTelemetry
- type OpenTelemetryExporter
- type Option
- func WithBaseAttributes(baseAttributes []attribute.KeyValue) Option
- func WithCardinalityLimit(cardinalityLimit int) Option
- func WithLogger(logger *zap.Logger) Option
- func WithOtlpMeterProvider(otelMeterProvider *metric.MeterProvider) Option
- func WithProcessStartTime(processStartTime time.Time) Option
- func WithPromMeterProvider(promMeterProvider *metric.MeterProvider) Option
- type OtlpMetricStore
- func (h *OtlpMetricStore) Flush(ctx context.Context) error
- func (h *OtlpMetricStore) MeasureInFlight(ctx context.Context, opts ...otelmetric.AddOption) func()
- func (h *OtlpMetricStore) MeasureLatency(ctx context.Context, latency float64, opts ...otelmetric.RecordOption)
- func (h *OtlpMetricStore) MeasureOperationPlanningTime(ctx context.Context, planningTime float64, opts ...otelmetric.RecordOption)
- func (h *OtlpMetricStore) MeasureRequestCount(ctx context.Context, opts ...otelmetric.AddOption)
- func (h *OtlpMetricStore) MeasureRequestError(ctx context.Context, opts ...otelmetric.AddOption)
- func (h *OtlpMetricStore) MeasureRequestSize(ctx context.Context, contentLength int64, opts ...otelmetric.AddOption)
- func (h *OtlpMetricStore) MeasureResponseSize(ctx context.Context, size int64, opts ...otelmetric.AddOption)
- type PromMetricStore
- func (h *PromMetricStore) Flush(ctx context.Context) error
- func (h *PromMetricStore) MeasureInFlight(ctx context.Context, opts ...otelmetric.AddOption) func()
- func (h *PromMetricStore) MeasureLatency(ctx context.Context, latency float64, opts ...otelmetric.RecordOption)
- func (h *PromMetricStore) MeasureOperationPlanningTime(ctx context.Context, planningTime float64, opts ...otelmetric.RecordOption)
- func (h *PromMetricStore) MeasureRequestCount(ctx context.Context, opts ...otelmetric.AddOption)
- func (h *PromMetricStore) MeasureRequestError(ctx context.Context, opts ...otelmetric.AddOption)
- func (h *PromMetricStore) MeasureRequestSize(ctx context.Context, contentLength int64, opts ...otelmetric.AddOption)
- func (h *PromMetricStore) MeasureResponseSize(ctx context.Context, size int64, opts ...otelmetric.AddOption)
- func (h *PromMetricStore) Shutdown(ctx context.Context) error
- type PrometheusConfig
- type Provider
- type RuntimeMetrics
- type Store
Constants ¶
const ( RequestCounter = "router.http.requests" // Incoming request count total ServerLatencyHistogram = "router.http.request.duration_milliseconds" // Incoming end to end duration, milliseconds RequestContentLengthCounter = "router.http.request.content_length" // Incoming request bytes total ResponseContentLengthCounter = "router.http.response.content_length" // Outgoing response bytes total InFlightRequestsUpDownCounter = "router.http.requests.in_flight" // Number of requests in flight RequestError = "router.http.requests.error" // Total request error count OperationPlanningTime = "router.graphql.operation.planning_time" // Time taken to plan the operation )
Server HTTP metrics.
const ( DefaultMinimumReadMemStatsInterval = 15 * time.Second AttributeGoInfoVersion = attribute.Key("version") )
const DefaultCardinalityLimit = 2000
DefaultCardinalityLimit is the hard limit on the number of metric streams that can be collected for a single instrument.
const DefaultServerName = "cosmo-router"
DefaultServerName Default resource name.
Variables ¶
var ( RequestCounterDescription = "Total number of requests" RequestCounterOptions = []otelmetric.Int64CounterOption{ otelmetric.WithDescription(RequestCounterDescription), } RequestErrorCounterDescription = "Total number of failed requests" RequestErrorCounterOptions = []otelmetric.Int64CounterOption{ otelmetric.WithDescription(RequestErrorCounterDescription), } ServerLatencyHistogramDescription = "Server latency in milliseconds" ServerLatencyHistogramOptions = []otelmetric.Float64HistogramOption{ otelmetric.WithUnit("ms"), otelmetric.WithDescription(ServerLatencyHistogramDescription), } RequestContentLengthCounterDescription = "Total number of request bytes" RequestContentLengthCounterOptions = []otelmetric.Int64CounterOption{ otelmetric.WithUnit("bytes"), otelmetric.WithDescription(RequestContentLengthCounterDescription), } ResponseContentLengthCounterDescription = "Total number of response bytes" ResponseContentLengthCounterOptions = []otelmetric.Int64CounterOption{ otelmetric.WithUnit("bytes"), otelmetric.WithDescription(ResponseContentLengthCounterDescription), } InFlightRequestsUpDownCounterDescription = "Number of requests in flight" InFlightRequestsUpDownCounterOptions = []otelmetric.Int64UpDownCounterOption{ otelmetric.WithDescription(InFlightRequestsUpDownCounterDescription), } OperationPlanningTimeHistogramDescription = "Operation planning time in milliseconds" OperationPlanningTimeHistogramOptions = []otelmetric.Float64HistogramOption{ otelmetric.WithUnit("ms"), otelmetric.WithDescription(OperationPlanningTimeHistogramDescription), } )
Functions ¶
func NewOtlpMeterProvider ¶
func NewPrometheusMeterProvider ¶
func NewPrometheusMeterProvider(ctx context.Context, c *Config, serviceInstanceID string) (*sdkmetric.MeterProvider, *prometheus.Registry, error)
func NewPrometheusServer ¶
Types ¶
type CacheMetricInfo ¶
type CacheMetricInfo struct {
// contains filtered or unexported fields
}
CacheMetricInfo is a struct that aggregates information to provide metrics for a single cache implementation.
func NewCacheMetricInfo ¶
func NewCacheMetricInfo(cacheType string, maxCost int64, cacheMetrics *ristretto.Metrics) CacheMetricInfo
NewCacheMetricInfo creates a new CacheMetricInfo instance.
type CacheMetrics ¶
type CacheMetrics struct {
// contains filtered or unexported fields
}
CacheMetrics is a struct that holds the metrics for various graphql operation caches.
func NewCacheMetrics ¶
func NewCacheMetrics(logger *zap.Logger, baseAttributes []attribute.KeyValue, provider *metric.MeterProvider) (*CacheMetrics, error)
NewCacheMetrics creates a new CacheMetrics instance.
func (*CacheMetrics) RegisterObservers ¶
func (c *CacheMetrics) RegisterObservers( operationCacheMetrics []CacheMetricInfo, ) error
RegisterObservers creates observer callbacks for the OTEL metrics, which will be invoked in intervals.
func (*CacheMetrics) Shutdown ¶
func (c *CacheMetrics) Shutdown() error
type Config ¶
type Config struct { // Name represents the service name for metrics. The default value is cosmo-router. Name string // Version represents the service version for metrics. The default value is dev. Version string // OpenTelemetry includes the OpenTelemetry configuration OpenTelemetry OpenTelemetry // Prometheus includes the Prometheus configuration Prometheus PrometheusConfig // ResourceAttributes added to the global resource attributes for all metrics. ResourceAttributes []attribute.KeyValue Attributes []config.CustomAttribute }
Config represents the configuration for the agent.
func DefaultConfig ¶
DefaultConfig returns the default config.
type Measurements ¶
type Measurements struct {
// contains filtered or unexported fields
}
Measurements holds the metrics for the request.
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
func (*Metrics) MeasureInFlight ¶
func (*Metrics) MeasureLatency ¶
func (h *Metrics) MeasureLatency(ctx context.Context, latency time.Duration, sliceAttr []attribute.KeyValue, opt otelmetric.RecordOption)
func (*Metrics) MeasureOperationPlanningTime ¶
func (h *Metrics) MeasureOperationPlanningTime(ctx context.Context, planningTime time.Duration, sliceAttr []attribute.KeyValue, opt otelmetric.RecordOption)
func (*Metrics) MeasureRequestCount ¶
func (*Metrics) MeasureRequestError ¶
func (*Metrics) MeasureRequestSize ¶
func (*Metrics) MeasureResponseSize ¶
type NoopMetrics ¶
type NoopMetrics struct{}
func (NoopMetrics) MeasureInFlight ¶
func (n NoopMetrics) MeasureInFlight(ctx context.Context, sliceAttr []attribute.KeyValue, opt otelmetric.AddOption) func()
func (NoopMetrics) MeasureLatency ¶
func (n NoopMetrics) MeasureLatency(ctx context.Context, latency time.Duration, sliceAttr []attribute.KeyValue, opt otelmetric.RecordOption)
func (NoopMetrics) MeasureOperationPlanningTime ¶
func (n NoopMetrics) MeasureOperationPlanningTime(ctx context.Context, planningTime time.Duration, sliceAttr []attribute.KeyValue, opt otelmetric.RecordOption)
func (NoopMetrics) MeasureRequestCount ¶
func (n NoopMetrics) MeasureRequestCount(ctx context.Context, sliceAttr []attribute.KeyValue, opt otelmetric.AddOption)
func (NoopMetrics) MeasureRequestError ¶
func (n NoopMetrics) MeasureRequestError(ctx context.Context, sliceAttr []attribute.KeyValue, opt otelmetric.AddOption)
func (NoopMetrics) MeasureRequestSize ¶
func (n NoopMetrics) MeasureRequestSize(ctx context.Context, contentLength int64, sliceAttr []attribute.KeyValue, opt otelmetric.AddOption)
func (NoopMetrics) MeasureResponseSize ¶
func (n NoopMetrics) MeasureResponseSize(ctx context.Context, size int64, sliceAttr []attribute.KeyValue, opt otelmetric.AddOption)
type OpenTelemetry ¶
type OpenTelemetry struct { Enabled bool RouterRuntime bool GraphqlCache bool Exporters []*OpenTelemetryExporter // Metrics to exclude from the OTLP exporter. ExcludeMetrics []*regexp.Regexp // Metric labels to exclude from the OTLP exporter. ExcludeMetricLabels []*regexp.Regexp // TestReader is used for testing purposes. If set, the reader will be used instead of the configured exporters. TestReader sdkmetric.Reader }
type OpenTelemetryExporter ¶
type OpenTelemetryExporter struct { Disabled bool Exporter otelconfig.Exporter Endpoint string // Headers represents the headers for HTTP transport. // For example: // Authorization: 'Bearer <token>' Headers map[string]string // HTTPPath represents the path for OTLP HTTP transport. // For example // /v1/metrics HTTPPath string Temporality otelconfig.ExporterTemporality }
func GetDefaultExporter ¶
func GetDefaultExporter(cfg *Config) *OpenTelemetryExporter
type Option ¶
type Option func(svr *Metrics)
func WithBaseAttributes ¶
func WithCardinalityLimit ¶
func WithLogger ¶
func WithOtlpMeterProvider ¶
func WithOtlpMeterProvider(otelMeterProvider *metric.MeterProvider) Option
func WithProcessStartTime ¶
func WithPromMeterProvider ¶
func WithPromMeterProvider(promMeterProvider *metric.MeterProvider) Option
type OtlpMetricStore ¶
type OtlpMetricStore struct {
// contains filtered or unexported fields
}
func (*OtlpMetricStore) MeasureInFlight ¶
func (h *OtlpMetricStore) MeasureInFlight(ctx context.Context, opts ...otelmetric.AddOption) func()
func (*OtlpMetricStore) MeasureLatency ¶
func (h *OtlpMetricStore) MeasureLatency(ctx context.Context, latency float64, opts ...otelmetric.RecordOption)
func (*OtlpMetricStore) MeasureOperationPlanningTime ¶
func (h *OtlpMetricStore) MeasureOperationPlanningTime(ctx context.Context, planningTime float64, opts ...otelmetric.RecordOption)
func (*OtlpMetricStore) MeasureRequestCount ¶
func (h *OtlpMetricStore) MeasureRequestCount(ctx context.Context, opts ...otelmetric.AddOption)
func (*OtlpMetricStore) MeasureRequestError ¶
func (h *OtlpMetricStore) MeasureRequestError(ctx context.Context, opts ...otelmetric.AddOption)
func (*OtlpMetricStore) MeasureRequestSize ¶
func (h *OtlpMetricStore) MeasureRequestSize(ctx context.Context, contentLength int64, opts ...otelmetric.AddOption)
func (*OtlpMetricStore) MeasureResponseSize ¶
func (h *OtlpMetricStore) MeasureResponseSize(ctx context.Context, size int64, opts ...otelmetric.AddOption)
type PromMetricStore ¶
type PromMetricStore struct {
// contains filtered or unexported fields
}
func (*PromMetricStore) MeasureInFlight ¶
func (h *PromMetricStore) MeasureInFlight(ctx context.Context, opts ...otelmetric.AddOption) func()
func (*PromMetricStore) MeasureLatency ¶
func (h *PromMetricStore) MeasureLatency(ctx context.Context, latency float64, opts ...otelmetric.RecordOption)
func (*PromMetricStore) MeasureOperationPlanningTime ¶
func (h *PromMetricStore) MeasureOperationPlanningTime(ctx context.Context, planningTime float64, opts ...otelmetric.RecordOption)
func (*PromMetricStore) MeasureRequestCount ¶
func (h *PromMetricStore) MeasureRequestCount(ctx context.Context, opts ...otelmetric.AddOption)
func (*PromMetricStore) MeasureRequestError ¶
func (h *PromMetricStore) MeasureRequestError(ctx context.Context, opts ...otelmetric.AddOption)
func (*PromMetricStore) MeasureRequestSize ¶
func (h *PromMetricStore) MeasureRequestSize(ctx context.Context, contentLength int64, opts ...otelmetric.AddOption)
func (*PromMetricStore) MeasureResponseSize ¶
func (h *PromMetricStore) MeasureResponseSize(ctx context.Context, size int64, opts ...otelmetric.AddOption)
type PrometheusConfig ¶
type PrometheusConfig struct { Enabled bool ListenAddr string Path string GraphqlCache bool // Metrics to exclude from Prometheus exporter ExcludeMetrics []*regexp.Regexp // Metric labels to exclude from Prometheus exporter ExcludeMetricLabels []*regexp.Regexp // TestRegistry is used for testing purposes. If set, the registry will be used instead of the default one. TestRegistry *prometheus.Registry }
type Provider ¶
type Provider interface { MeasureInFlight(ctx context.Context, opts ...otelmetric.AddOption) func() MeasureRequestCount(ctx context.Context, opts ...otelmetric.AddOption) MeasureRequestSize(ctx context.Context, contentLength int64, opts ...otelmetric.AddOption) MeasureResponseSize(ctx context.Context, size int64, opts ...otelmetric.AddOption) MeasureLatency(ctx context.Context, latency float64, opts ...otelmetric.RecordOption) MeasureRequestError(ctx context.Context, opts ...otelmetric.AddOption) MeasureOperationPlanningTime(ctx context.Context, planningTime float64, opts ...otelmetric.RecordOption) Flush(ctx context.Context) error }
Provider is the interface that wraps the basic metric methods. We maintain two providers, one for OTEL and one for Prometheus.
func NewOtlpMetricStore ¶
func NewPromMetricStore ¶
type RuntimeMetrics ¶
type RuntimeMetrics struct {
// contains filtered or unexported fields
}
func NewRuntimeMetrics ¶
func NewRuntimeMetrics(logger *zap.Logger, meterProvider *metric.MeterProvider, baseAttributes []attribute.KeyValue, processStartTime time.Time) *RuntimeMetrics
NewRuntimeMetrics creates a new instance of RuntimeMetrics. Runtime metrics are metrics that are collected from the Go and process runtime. These metrics are shared across feature flags.
func (*RuntimeMetrics) Shutdown ¶
func (r *RuntimeMetrics) Shutdown() error
func (*RuntimeMetrics) Start ¶
func (r *RuntimeMetrics) Start() error
type Store ¶
type Store interface { MeasureInFlight(ctx context.Context, sliceAttr []attribute.KeyValue, opt otelmetric.AddOption) func() MeasureRequestCount(ctx context.Context, sliceAttr []attribute.KeyValue, opt otelmetric.AddOption) MeasureRequestSize(ctx context.Context, contentLength int64, sliceAttr []attribute.KeyValue, opt otelmetric.AddOption) MeasureResponseSize(ctx context.Context, size int64, sliceAttr []attribute.KeyValue, opt otelmetric.AddOption) MeasureLatency(ctx context.Context, latency time.Duration, sliceAttr []attribute.KeyValue, opt otelmetric.RecordOption) MeasureRequestError(ctx context.Context, sliceAttr []attribute.KeyValue, opt otelmetric.AddOption) MeasureOperationPlanningTime(ctx context.Context, planningTime time.Duration, sliceAttr []attribute.KeyValue, opt otelmetric.RecordOption) Flush(ctx context.Context) error Shutdown(ctx context.Context) error }
Store is the unified metric interface for OTEL and Prometheus metrics. The interface can vary depending on if additional information is required for the provider e.g. slice attributes.
func NewNoopMetrics ¶
func NewNoopMetrics() Store