Documentation
¶
Index ¶
- Variables
- func ComputeAttemptRates(data []AttemptMetricsDataPoint, req MetricsRequest)
- func ComputeEventRates(data []EventMetricsDataPoint, req MetricsRequest)
- func CursorPosition(t time.Time, id string) string
- func DedupeEntriesByAttemptID(entries []*models.LogEntry) []*models.LogEntry
- func EnrichMeasuresForRates(measures []string) []string
- func ParseCursorPosition(position string) (t time.Time, id string, err error)
- func ValidateMetricsRequest(req MetricsRequest) error
- type AttemptKey
- type AttemptMetricsDataPoint
- type AttemptMetricsResponse
- type AttemptRecord
- type Cursor
- type CursorFormat
- type EventMetricsDataPoint
- type EventMetricsResponse
- type Field
- type Granularity
- type KeyErrors
- type LatestAttemptLookup
- type ListAttemptRequest
- type ListAttemptResponse
- type ListEventRequest
- type ListEventResponse
- type LogStore
- type Metrics
- type MetricsMetadata
- type MetricsRequest
- type Records
- type RetrieveAttemptRequest
- type RetrieveEventRequest
- type TimeFilter
- type TimeRange
Constants ¶
This section is empty.
Variables ¶
var AllFields = []Field{FieldEventData, FieldEventMetadata, FieldResponseData}
AllFields reads the full record.
var ErrInvalidTimeRange = errors.New("invalid time range: start must be before end")
ErrInvalidTimeRange is returned when the time range is invalid (e.g. start >= end). Callers should surface this as a 400.
var ErrResourceLimit = errors.New("metrics query exceeded resource limits")
ErrResourceLimit is returned when a metrics query exceeds server-side resource limits (e.g. too many GROUP BY rows, query timeout). Callers should surface this as a 400 rather than a 500.
Functions ¶
func ComputeAttemptRates ¶ added in v0.15.0
func ComputeAttemptRates(data []AttemptMetricsDataPoint, req MetricsRequest)
ComputeAttemptRates populates Rate, SuccessfulRate, and FailedRate fields on attempt data points from their corresponding count fields and the bucket duration.
func ComputeEventRates ¶ added in v0.15.0
func ComputeEventRates(data []EventMetricsDataPoint, req MetricsRequest)
ComputeEventRates populates Rate fields on event data points from their corresponding count fields and the bucket duration.
func CursorPosition ¶ added in v1.10.0
CursorPosition returns the position of a record in a list ordered by time and id. It is the same for every cursor format: "{unix microseconds}::{id}".
func DedupeEntriesByAttemptID ¶ added in v1.0.5
DedupeEntriesByAttemptID collapses intra-batch duplicates (same Attempt.ID) to a single entry. Duplicates arise from MQ redelivery and producer re-publish, so they can carry different MQ message IDs; copies are byte-identical, so the last occurrence wins at the first occurrence's position. InsertMany implementations must tolerate intra-batch duplicates regardless of caller — e.g. PostgreSQL rejects the same conflict key twice in one INSERT ... ON CONFLICT DO UPDATE statement (SQLSTATE 21000).
func EnrichMeasuresForRates ¶ added in v0.15.0
EnrichMeasuresForRates returns a new measures slice with any missing rate dependencies appended. For example, if "rate" is requested but "count" is not, "count" is added so the SQL query computes it.
func ParseCursorPosition ¶ added in v1.6.0
ParseCursorPosition reads a position written by CursorPosition. The error wraps cursor.ErrInvalidCursor when the position cannot be read.
func ValidateMetricsRequest ¶ added in v0.15.0
func ValidateMetricsRequest(req MetricsRequest) error
ValidateMetricsRequest checks that the metrics request is well-formed.
Types ¶
type AttemptKey ¶ added in v1.7.0
AttemptKey identifies the attempts of one event delivered to one destination.
type AttemptMetricsDataPoint ¶ added in v0.15.0
type AttemptMetricsDataPoint struct {
TimeBucket *time.Time
// Measures
Count *int
SuccessfulCount *int
FailedCount *int
ErrorRate *float64
// NOTE: The following three measures are equivalent to using "count" with
// the corresponding filters (attempt_number=1 AND manual=false, attempt_number>1,
// manual=true). They exist for composability — callers can request multiple
// measures in a single query instead of issuing separate filtered queries.
// Consider whether they're worth the added surface area or if callers should
// use count+filters.
FirstAttemptCount *int
RetryCount *int
ManualRetryCount *int
AvgAttemptNumber *float64
Rate *float64
SuccessfulRate *float64
FailedRate *float64
// Latency measures ignore attempts with a nil LatencyMs and are nil, not
// zero, when a group has none (including zero-filled empty buckets).
AvgLatency *float64
P50Latency *float64
P95Latency *float64
P99Latency *float64
// Dimensions
TenantID *string
DestinationID *string
DestinationType *string
Topic *string
Status *string
Code *string
Manual *bool
AttemptNumber *int
}
type AttemptMetricsResponse ¶ added in v0.15.0
type AttemptMetricsResponse struct {
Data []AttemptMetricsDataPoint
Metadata MetricsMetadata
}
type AttemptRecord ¶ added in v0.13.0
type AttemptRecord struct {
Attempt *models.Attempt
Event *models.Event // optionally populated for query results
}
AttemptRecord represents an attempt query result with optional Event population.
type Cursor ¶ added in v1.10.0
type Cursor struct {
// contains filtered or unexported fields
}
Cursor encodes and decodes the cursors of one log list.
func NewCursor ¶ added in v1.10.0
func NewCursor(resource string, format CursorFormat) Cursor
NewCursor returns the cursors of a list: resource names the list and format is the one the store issues.
type CursorFormat ¶ added in v1.10.0
type CursorFormat int
CursorFormat is how a log list cursor writes the position of the record it points at. The value is the version number the cursor carries.
The time and id formats write "{unix time}::{id}", the order of the lists, and differ in the precision of the time. A log store issues the one that matches the precision it orders by: a coarser one skips or repeats records that are closer together.
const ( // CursorFormatTimeIDMillis writes "{unix milliseconds}::{id}". CursorFormatTimeIDMillis CursorFormat = 1 // CursorFormatTimeIDMicros writes "{unix microseconds}::{id}". CursorFormatTimeIDMicros CursorFormat = 2 )
type EventMetricsDataPoint ¶ added in v0.15.0
type EventMetricsResponse ¶ added in v0.15.0
type EventMetricsResponse struct {
Data []EventMetricsDataPoint
Metadata MetricsMetadata
}
type Granularity ¶ added in v0.15.0
Granularity defines the time-bucketing interval for metrics queries. For sub-day units (s, m, h), Value controls both step size and alignment (e.g. 5m → buckets at :00, :05, :10, …). For calendar units with Value=1, alignment is to the natural period start (start of day, Sunday-based week, or first of month). For calendar units with Value>1, alignment uses epoch-anchored intervals (d/w from 1970-01-01/1970-01-04, M from Jan 1970) so that multi-day, multi-week, and multi-month granularities aggregate data correctly.
type KeyErrors ¶ added in v1.7.0
type KeyErrors map[AttemptKey]error
KeyErrors holds the error of each key whose attempt couldn't be read.
type LatestAttemptLookup ¶ added in v1.7.0
type LatestAttemptLookup struct {
Key AttemptKey
NotBefore time.Time
}
LatestAttemptLookup asks for the latest attempt of Key. A zero NotBefore means no lower bound on the attempt time.
type ListAttemptRequest ¶ added in v0.13.0
type ListAttemptRequest struct {
Next string
Prev string
Limit int
TimeFilter TimeFilter // optional - filter attempts by time
TenantIDs []string // optional - filter by tenant (if empty, returns all tenants)
EventIDs []string // optional - filter by event ID
DestinationIDs []string // optional
DestinationTypes []string // optional - filter by destination type
Status string // optional: "success", "failed"
Topics []string // optional
SortOrder string // optional: "asc", "desc" (default: "desc")
Include []Field // optional - payload fields to read; nil reads none of them, so callers that need event data/metadata or response data must ask
}
type ListAttemptResponse ¶ added in v0.13.0
type ListAttemptResponse struct {
Data []*AttemptRecord
Next string
Prev string
}
type ListEventRequest ¶
type ListEventRequest struct {
Next string
Prev string
Limit int
TimeFilter TimeFilter // optional - filter events by time
TenantIDs []string // optional - filter by tenant (if empty, returns all tenants)
EventIDs []string // optional - filter by event ID
DestinationIDs []string // optional
Topics []string // optional
SortOrder string // optional: "asc", "desc" (default: "desc")
}
type ListEventResponse ¶
type Metrics ¶ added in v0.15.0
type Metrics interface {
QueryEventMetrics(ctx context.Context, req MetricsRequest) (*EventMetricsResponse, error)
QueryAttemptMetrics(ctx context.Context, req MetricsRequest) (*AttemptMetricsResponse, error)
}
type MetricsMetadata ¶ added in v0.15.0
type MetricsRequest ¶ added in v0.15.0
type Records ¶ added in v0.15.0
type Records interface {
ListEvent(context.Context, ListEventRequest) (ListEventResponse, error)
ListAttempt(context.Context, ListAttemptRequest) (ListAttemptResponse, error)
// ListLatestAttempts returns the latest attempt of each key, not older than the
// key's NotBefore. Keys without a match are absent from the result. When some
// keys' attempts can't be read, it returns the other keys' results with a
// KeyErrors error.
ListLatestAttempts(context.Context, []LatestAttemptLookup) (map[AttemptKey]*AttemptRecord, error)
RetrieveEvent(ctx context.Context, request RetrieveEventRequest) (*models.Event, error)
RetrieveAttempt(ctx context.Context, request RetrieveAttemptRequest) (*AttemptRecord, error)
InsertMany(context.Context, []*models.LogEntry) error
}
type RetrieveAttemptRequest ¶ added in v0.13.0
type RetrieveEventRequest ¶ added in v0.13.0
type TimeFilter ¶ added in v0.13.0
type TimeFilter struct {
GTE *time.Time // Greater than or equal (>=)
LTE *time.Time // Less than or equal (<=)
GT *time.Time // Greater than (>)
LT *time.Time // Less than (<)
}
TimeFilter represents time-based filter criteria with support for both inclusive (GTE/LTE) and exclusive (GT/LT) comparisons.