Documentation
¶
Overview ¶
Package red provides types for RED (Rate, Errors, Duration) metrics.
RED metrics are request-oriented metrics popularized by the Prometheus ecosystem:
- Rate: Request throughput (requests/sec)
- Errors: Failed request count
- Duration: Request latency distribution
These map to the Traffic, Errors, and Latency Golden Signals.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultBuckets ¶
func DefaultBuckets() []float64
DefaultBuckets returns default histogram buckets for latency in milliseconds.
Types ¶
type Attribute ¶
type Attribute struct {
// Key is the attribute key.
Key string `json:"key"`
// Description explains the attribute.
Description string `json:"description,omitempty"`
// Required indicates the attribute must be present.
Required bool `json:"required,omitempty"`
}
Attribute defines a metric attribute.
type Definition ¶
type Definition struct {
// Name is the metric name prefix (e.g., "http.server.request").
Name string `json:"name"`
// Description explains what this metric measures.
Description string `json:"description,omitempty"`
// Rate configures the rate metric.
Rate RateConfig `json:"rate"`
// Errors configures the error metric.
Errors ErrorsConfig `json:"errors"`
// Duration configures the duration metric.
Duration DurationConfig `json:"duration"`
// Attributes are common attributes for all metrics.
Attributes []Attribute `json:"attributes,omitempty"`
}
Definition describes a RED metric set for a service endpoint.
func GRPCServerDefinition ¶
func GRPCServerDefinition() Definition
GRPCServerDefinition returns a standard RED definition for gRPC servers.
func HTTPServerDefinition ¶
func HTTPServerDefinition() Definition
HTTPServerDefinition returns a standard RED definition for HTTP servers.
type DurationConfig ¶
type DurationConfig struct {
// Metric is the OTel metric name (default: {name}.duration).
Metric string `json:"metric,omitempty"`
// Unit is the metric unit (default: "ms").
Unit string `json:"unit,omitempty"`
// Buckets are histogram bucket boundaries in milliseconds.
Buckets []float64 `json:"buckets,omitempty"`
// Aggregation specifies how to aggregate (p50, p95, p99).
Aggregation string `json:"aggregation,omitempty"`
// SLICandidate indicates this can be used as an SLI.
SLICandidate bool `json:"sli_candidate,omitempty"`
// GoldenSignal maps to "latency".
GoldenSignal string `json:"golden_signal,omitempty"`
}
DurationConfig configures latency/duration metrics.
type ErrorsConfig ¶
type ErrorsConfig struct {
// Metric is the OTel metric name (default: {name}.errors).
Metric string `json:"metric,omitempty"`
// Filter defines what constitutes an error (e.g., "http.status_code >= 500").
Filter string `json:"filter,omitempty"`
// SLICandidate indicates this can be used as an SLI.
SLICandidate bool `json:"sli_candidate,omitempty"`
// GoldenSignal maps to "errors".
GoldenSignal string `json:"golden_signal,omitempty"`
}
ErrorsConfig configures error metrics.
type MetricType ¶
type MetricType string
MetricType identifies a RED metric category.
const ( // MetricRate represents request rate (traffic). MetricRate MetricType = "rate" // MetricErrors represents error count. MetricErrors MetricType = "errors" // MetricDuration represents request latency. MetricDuration MetricType = "duration" )
type Observation ¶
type Observation struct {
// Duration of the request.
Duration time.Duration
// Error if the request failed.
Error error
// StatusCode is the HTTP status code (if applicable).
StatusCode int
// Attributes for this observation.
Attributes map[string]string
}
Observation captures a single RED observation.
func (Observation) IsError ¶
func (o Observation) IsError() bool
IsError returns true if the observation represents an error.
type RateConfig ¶
type RateConfig struct {
// Metric is the OTel metric name (default: {name}.count).
Metric string `json:"metric,omitempty"`
// Unit is the metric unit (default: "{requests}").
Unit string `json:"unit,omitempty"`
// GoldenSignal maps to "traffic".
GoldenSignal string `json:"golden_signal,omitempty"`
}
RateConfig configures rate (request count) metrics.