driver

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
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 EnrichMeasuresForRates added in v0.15.0

func EnrichMeasuresForRates(measures []string) []string

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 ValidateMetricsRequest added in v0.15.0

func ValidateMetricsRequest(req MetricsRequest) error

ValidateMetricsRequest checks that the metrics request is well-formed.

Types

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
	// Dimensions
	TenantID      *string
	DestinationID *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 EventMetricsDataPoint added in v0.15.0

type EventMetricsDataPoint struct {
	TimeBucket *time.Time
	// Measures
	Count *int
	Rate  *float64
	// Dimensions
	TenantID      *string
	Topic         *string
	DestinationID *string
}

type EventMetricsResponse added in v0.15.0

type EventMetricsResponse struct {
	Data     []EventMetricsDataPoint
	Metadata MetricsMetadata
}

type Granularity added in v0.15.0

type Granularity struct {
	Value int
	Unit  string // s, m, h, d, w, M
}

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 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
	Status         string     // optional: "success", "failed"
	Topics         []string   // optional
	SortOrder      string     // optional: "asc", "desc" (default: "desc")
}

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 ListEventResponse struct {
	Data []*models.Event
	Next string
	Prev string
}

type LogStore

type LogStore interface {
	Records
	Metrics
}

LogStore is the combined interface that all driver implementations must satisfy.

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 MetricsMetadata struct {
	QueryTimeMs int64
	RowCount    int
	RowLimit    int
	Truncated   bool
}

type MetricsRequest added in v0.15.0

type MetricsRequest struct {
	TimeRange   TimeRange
	Granularity *Granularity
	Measures    []string
	Dimensions  []string
	Filters     map[string][]string
}

type Records added in v0.15.0

type Records interface {
	ListEvent(context.Context, ListEventRequest) (ListEventResponse, error)
	ListAttempt(context.Context, ListAttemptRequest) (ListAttemptResponse, 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 RetrieveAttemptRequest struct {
	TenantID  string // optional - filter by tenant (if empty, searches all tenants)
	AttemptID string // required
}

type RetrieveEventRequest added in v0.13.0

type RetrieveEventRequest struct {
	TenantID string // optional - filter by tenant (if empty, searches all tenants)
	EventID  string // required
}

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.

type TimeRange added in v0.15.0

type TimeRange struct {
	Start time.Time
	End   time.Time
}

Jump to

Keyboard shortcuts

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