Documentation
¶
Index ¶
- Constants
- Variables
- func BatchSize(batch LogBatch) int64
- func DeliverySettingDefinitions() map[string]DeliverySettingDefinition
- type CoreSettingsFinder
- type DatabaseConnector
- type DatabaseConnectorFunc
- type DeliveryMetrics
- type DeliverySettingDefinition
- type DeliverySettings
- type DeliveryStatus
- type HistoricalAggregateBatch
- type HistoricalRequestBatchWriter
- func (w *HistoricalRequestBatchWriter) MergeAggregates(ctx context.Context, batch HistoricalAggregateBatch) error
- func (w *HistoricalRequestBatchWriter) ReplaceAggregates(ctx context.Context, batch HistoricalAggregateBatch) error
- func (w *HistoricalRequestBatchWriter) WriteHistory(ctx context.Context, requests []models.RequestLog, ...) error
- func (w *HistoricalRequestBatchWriter) WriteRequests(ctx context.Context, cursorKey string, lastSourceID uint, ...) error
- func (w *HistoricalRequestBatchWriter) WriteTraces(ctx context.Context, cursorKey string, lastSourceID uint, ...) error
- type LogBatch
- type LogBatchWriter
- type LogDeliveryWorker
- func (w *LogDeliveryWorker) ClearBacklog() (deliveryqueue.ClearResult, error)
- func (w *LogDeliveryWorker) Enqueue(batch LogBatch) deliveryqueue.EnqueueResult
- func (w *LogDeliveryWorker) Queue() *deliveryqueue.Queue[LogBatch]
- func (w *LogDeliveryWorker) RetryNow()
- func (w *LogDeliveryWorker) SchemaReady() bool
- func (w *LogDeliveryWorker) Start(parent context.Context) error
- func (w *LogDeliveryWorker) Status() DeliveryStatus
- func (w *LogDeliveryWorker) Stop(ctx context.Context) error
- type SQLiteLogConnector
- type SettingsFinder
- type WorkerOptions
Constants ¶
View Source
const ( QueueMaxEntriesKey = "log.delivery_queue_max_entries" QueueMaxBytesKey = "log.delivery_queue_max_bytes" DeliveryBatchSizeKey = "log.delivery_batch_size" BackoffMaxSecondsKey = "log.delivery_backoff_max_seconds" DefaultQueueMaxEntries = 10000 DefaultQueueMaxBytes = int64(128 << 20) DefaultDeliveryBatchSize = 100 DefaultBackoffMaxSeconds = 60 MinQueueEntries = 100 MaxQueueEntries = 1_000_000 MinQueueBytes = int64(1 << 20) MaxQueueBytes = int64(8 << 30) MinBatchSize = 1 MaxBatchSize = 1000 MinBackoffSecs = 1 MaxBackoffSecs = 3600 )
Variables ¶
View Source
var ( ErrInvalidLogBatch = errors.New("invalid log batch") ErrLogPersistenceFailed = errors.New("log persistence failed") )
Functions ¶
func DeliverySettingDefinitions ¶
func DeliverySettingDefinitions() map[string]DeliverySettingDefinition
Types ¶
type CoreSettingsFinder ¶
type CoreSettingsFinder struct {
// contains filtered or unexported fields
}
func NewCoreSettingsFinder ¶
func NewCoreSettingsFinder(dbFinder func() *gorm.DB, onError func(error)) *CoreSettingsFinder
func (*CoreSettingsFinder) Find ¶
func (f *CoreSettingsFinder) Find(ctx context.Context) DeliverySettings
type DatabaseConnector ¶
type DatabaseConnectorFunc ¶
type DeliveryMetrics ¶
type DeliveryMetrics interface {
Observe(deliveryqueue.Stats, bool)
BacklogCleared(uint64, uint64)
WriteFailure()
SnapshotFailure()
}
type DeliverySettings ¶
type DeliverySettings struct {
QueueMaxEntries int
QueueMaxBytes int64
DeliveryBatchSize int
BackoffMaxSeconds int
}
func DefaultDeliverySettings ¶
func DefaultDeliverySettings() DeliverySettings
type DeliveryStatus ¶
type DeliveryStatus struct {
Queue deliveryqueue.Stats
SchemaReady bool
LastError string
}
type HistoricalAggregateBatch ¶
type HistoricalAggregateBatch struct {
Hourly []models.UsageHourlyBucket
Duration []models.UsageDurationHistogram
TTFT []models.UsageTTFTHistogram
TPS []models.UsageTPSHistogram
UserTTFT []models.UsageUserTTFTHistogram
UserTPS []models.UsageUserTPSHistogram
}
type HistoricalRequestBatchWriter ¶
func (*HistoricalRequestBatchWriter) MergeAggregates ¶
func (w *HistoricalRequestBatchWriter) MergeAggregates(ctx context.Context, batch HistoricalAggregateBatch) error
func (*HistoricalRequestBatchWriter) ReplaceAggregates ¶
func (w *HistoricalRequestBatchWriter) ReplaceAggregates(ctx context.Context, batch HistoricalAggregateBatch) error
func (*HistoricalRequestBatchWriter) WriteHistory ¶
func (w *HistoricalRequestBatchWriter) WriteHistory(ctx context.Context, requests []models.RequestLog, traces []models.RequestTrace) error
func (*HistoricalRequestBatchWriter) WriteRequests ¶
func (w *HistoricalRequestBatchWriter) WriteRequests( ctx context.Context, cursorKey string, lastSourceID uint, rows []models.RequestLog, ) error
func (*HistoricalRequestBatchWriter) WriteTraces ¶
func (w *HistoricalRequestBatchWriter) WriteTraces( ctx context.Context, cursorKey string, lastSourceID uint, rows []models.RequestTrace, ) error
type LogBatch ¶
type LogBatch struct {
Request models.RequestLog `json:"request"`
Traces []models.RequestTrace `json:"traces,omitempty"`
TokenDaily []models.TokenDailyBilling `json:"token_daily,omitempty"`
ChannelDaily []models.ChannelDailyBilling `json:"channel_daily,omitempty"`
Hourly []models.UsageHourlyBucket `json:"hourly,omitempty"`
Duration []models.UsageDurationHistogram `json:"duration,omitempty"`
TTFT []models.UsageTTFTHistogram `json:"ttft,omitempty"`
TPS []models.UsageTPSHistogram `json:"tps,omitempty"`
UserTTFT []models.UsageUserTTFTHistogram `json:"user_ttft,omitempty"`
UserTPS []models.UsageUserTPSHistogram `json:"user_tps,omitempty"`
APIRequest *models.APIRequestLog `json:"api_request,omitempty"`
APITraces []models.APIRequestTrace `json:"api_traces,omitempty"`
}
LogBatch is the complete non-billing write unit for one request. The request_id unique key makes replay safe; aggregate deltas are applied only when the request row is new.
func BuildRequestAggregateBatch ¶
BuildRequestAggregateBatch returns the request row and every aggregate delta derived from it. Trace rows remain the caller's responsibility.
type LogBatchWriter ¶
type LogDeliveryWorker ¶
type LogDeliveryWorker struct {
// contains filtered or unexported fields
}
func NewLogDeliveryWorker ¶
func NewLogDeliveryWorker(options WorkerOptions) *LogDeliveryWorker
func (*LogDeliveryWorker) ClearBacklog ¶
func (w *LogDeliveryWorker) ClearBacklog() (deliveryqueue.ClearResult, error)
func (*LogDeliveryWorker) Enqueue ¶
func (w *LogDeliveryWorker) Enqueue(batch LogBatch) deliveryqueue.EnqueueResult
func (*LogDeliveryWorker) Queue ¶
func (w *LogDeliveryWorker) Queue() *deliveryqueue.Queue[LogBatch]
func (*LogDeliveryWorker) RetryNow ¶
func (w *LogDeliveryWorker) RetryNow()
func (*LogDeliveryWorker) SchemaReady ¶
func (w *LogDeliveryWorker) SchemaReady() bool
func (*LogDeliveryWorker) Status ¶
func (w *LogDeliveryWorker) Status() DeliveryStatus
type SQLiteLogConnector ¶
type SQLiteLogConnector struct {
Path string
Connector *masterdatabase.Connector
}
type SettingsFinder ¶
type SettingsFinder interface {
Find(context.Context) DeliverySettings
}
type WorkerOptions ¶
type WorkerOptions struct {
Queue *deliveryqueue.Queue[LogBatch]
Writer *LogBatchWriter
Settings SettingsFinder
Connector DatabaseConnector
Handoff func(*gorm.DB) *gorm.DB
Metrics DeliveryMetrics
SnapshotPath string
PollInterval time.Duration
SettingsInterval time.Duration
SnapshotInterval time.Duration
FlushTimeout time.Duration
RetryBase time.Duration
RetryMax time.Duration
OnError func(error)
}
Click to show internal directories.
Click to hide internal directories.