Documentation
¶
Overview ¶
Package logstore provides a logs store for Bifrost.
Index ¶
- Constants
- Variables
- type AsyncJob
- type AsyncJobCleaner
- type AsyncJobExecutor
- type AsyncOperation
- type CleanerConfig
- type Config
- type CostHistogramBucket
- type CostHistogramResult
- type GovernanceStore
- type HistogramBucket
- type HistogramResult
- type KeyPairResult
- type LatencyHistogramBucket
- type LatencyHistogramResult
- type Log
- type LogRetentionManager
- type LogStore
- type LogStoreType
- type LogsCleaner
- type MCPCostHistogramBucket
- type MCPCostHistogramResult
- type MCPHistogramBucket
- type MCPHistogramResult
- type MCPToolLog
- type MCPToolLogSearchFilters
- type MCPToolLogSearchResult
- type MCPToolLogStats
- type MCPTopToolResult
- type MCPTopToolsResult
- type ModelHistogramBucket
- type ModelHistogramResult
- type ModelRankingEntry
- type ModelRankingResult
- type ModelRankingTrend
- type ModelRankingWithTrend
- type ModelUsageStats
- type PaginationOptions
- type PostgresConfig
- type ProviderCostHistogramBucket
- type ProviderCostHistogramResult
- type ProviderLatencyHistogramBucket
- type ProviderLatencyHistogramResult
- type ProviderLatencyStats
- type ProviderTokenHistogramBucket
- type ProviderTokenHistogramResult
- type ProviderTokenStats
- type RDBLogStore
- func (s *RDBLogStore) BatchCreateIfNotExists(ctx context.Context, entries []*Log) error
- func (s *RDBLogStore) BulkUpdateCost(ctx context.Context, updates map[string]float64) error
- func (s *RDBLogStore) Close(ctx context.Context) error
- func (s *RDBLogStore) Create(ctx context.Context, entry *Log) error
- func (s *RDBLogStore) CreateAsyncJob(ctx context.Context, job *AsyncJob) error
- func (s *RDBLogStore) CreateIfNotExists(ctx context.Context, entry *Log) error
- func (s *RDBLogStore) CreateMCPToolLog(ctx context.Context, entry *MCPToolLog) error
- func (s *RDBLogStore) DeleteExpiredAsyncJobs(ctx context.Context) (int64, error)
- func (s *RDBLogStore) DeleteLog(ctx context.Context, id string) error
- func (s *RDBLogStore) DeleteLogs(ctx context.Context, ids []string) error
- func (s *RDBLogStore) DeleteLogsBatch(ctx context.Context, cutoff time.Time, batchSize int) (deletedCount int64, err error)
- func (s *RDBLogStore) DeleteMCPToolLogs(ctx context.Context, ids []string) error
- func (s *RDBLogStore) DeleteStaleAsyncJobs(ctx context.Context, staleSince time.Time) (int64, error)
- func (s *RDBLogStore) FindAll(ctx context.Context, query any, fields ...string) ([]*Log, error)
- func (s *RDBLogStore) FindAllDistinct(ctx context.Context, query any, fields ...string) ([]*Log, error)
- func (s *RDBLogStore) FindAsyncJobByID(ctx context.Context, id string) (*AsyncJob, error)
- func (s *RDBLogStore) FindByID(ctx context.Context, id string) (*Log, error)
- func (s *RDBLogStore) FindFirst(ctx context.Context, query any, fields ...string) (*Log, error)
- func (s *RDBLogStore) FindMCPToolLog(ctx context.Context, id string) (*MCPToolLog, error)
- func (s *RDBLogStore) Flush(ctx context.Context, since time.Time) error
- func (s *RDBLogStore) FlushMCPToolLogs(ctx context.Context, since time.Time) error
- func (s *RDBLogStore) GetAvailableMCPVirtualKeys(ctx context.Context) ([]MCPToolLog, error)
- func (s *RDBLogStore) GetAvailableServerLabels(ctx context.Context) ([]string, error)
- func (s *RDBLogStore) GetAvailableToolNames(ctx context.Context) ([]string, error)
- func (s *RDBLogStore) GetCostHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*CostHistogramResult, error)
- func (s *RDBLogStore) GetDistinctKeyPairs(ctx context.Context, idCol, nameCol string) ([]KeyPairResult, error)
- func (s *RDBLogStore) GetDistinctMetadataKeys(ctx context.Context) (map[string][]string, error)
- func (s *RDBLogStore) GetDistinctModels(ctx context.Context) ([]string, error)
- func (s *RDBLogStore) GetDistinctRoutingEngines(ctx context.Context) ([]string, error)
- func (s *RDBLogStore) GetHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*HistogramResult, error)
- func (s *RDBLogStore) GetLatencyHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*LatencyHistogramResult, error)
- func (s *RDBLogStore) GetMCPCostHistogram(ctx context.Context, filters MCPToolLogSearchFilters, bucketSizeSeconds int64) (*MCPCostHistogramResult, error)
- func (s *RDBLogStore) GetMCPHistogram(ctx context.Context, filters MCPToolLogSearchFilters, bucketSizeSeconds int64) (*MCPHistogramResult, error)
- func (s *RDBLogStore) GetMCPToolLogStats(ctx context.Context, filters MCPToolLogSearchFilters) (*MCPToolLogStats, error)
- func (s *RDBLogStore) GetMCPTopTools(ctx context.Context, filters MCPToolLogSearchFilters, limit int) (*MCPTopToolsResult, error)
- func (s *RDBLogStore) GetModelHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*ModelHistogramResult, error)
- func (s *RDBLogStore) GetModelRankings(ctx context.Context, filters SearchFilters) (*ModelRankingResult, error)
- func (s *RDBLogStore) GetProviderCostHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*ProviderCostHistogramResult, error)
- func (s *RDBLogStore) GetProviderLatencyHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*ProviderLatencyHistogramResult, error)
- func (s *RDBLogStore) GetProviderTokenHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*ProviderTokenHistogramResult, error)
- func (s *RDBLogStore) GetStats(ctx context.Context, filters SearchFilters) (*SearchStats, error)
- func (s *RDBLogStore) GetTokenHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*TokenHistogramResult, error)
- func (s *RDBLogStore) HasLogs(ctx context.Context) (bool, error)
- func (s *RDBLogStore) HasMCPToolLogs(ctx context.Context) (bool, error)
- func (s *RDBLogStore) Ping(ctx context.Context) error
- func (s *RDBLogStore) SearchLogs(ctx context.Context, filters SearchFilters, pagination PaginationOptions) (*SearchResult, error)
- func (s *RDBLogStore) SearchMCPToolLogs(ctx context.Context, filters MCPToolLogSearchFilters, ...) (*MCPToolLogSearchResult, error)
- func (s *RDBLogStore) Update(ctx context.Context, id string, entry any) error
- func (s *RDBLogStore) UpdateAsyncJob(ctx context.Context, id string, updates map[string]interface{}) error
- func (s *RDBLogStore) UpdateMCPToolLog(ctx context.Context, id string, entry any) error
- type SQLiteConfig
- type SearchFilters
- type SearchResult
- type SearchStats
- type SortBy
- type SortOrder
- type TokenHistogramBucket
- type TokenHistogramResult
Constants ¶
const (
// DefaultAsyncJobResultTTL is the default TTL for async job results in seconds (1 hour).
DefaultAsyncJobResultTTL = 3600
)
Variables ¶
var (
ErrNotFound = fmt.Errorf("log not found")
)
Functions ¶
This section is empty.
Types ¶
type AsyncJob ¶ added in v1.2.22
type AsyncJob struct {
ID string `gorm:"primaryKey;type:varchar(255)" json:"id"`
Status schemas.AsyncJobStatus `gorm:"type:varchar(50);index:idx_async_jobs_status;not null" json:"status"`
RequestType schemas.RequestType `gorm:"type:varchar(50);index:idx_async_jobs_request_type;not null" json:"request_type"`
Response string `gorm:"type:text" json:"response"`
StatusCode int `gorm:"default:0" json:"status_code,omitempty"`
Error string `gorm:"type:text" json:"error,omitempty"`
VirtualKeyID *string `gorm:"type:varchar(255);index:idx_async_jobs_vk_id" json:"virtual_key_id,omitempty"`
ResultTTL int `gorm:"default:3600" json:"-"` // TTL in seconds, used to calculate ExpiresAt on completion
ExpiresAt *time.Time `gorm:"index:idx_async_jobs_expires_at" json:"expires_at,omitempty"`
CreatedAt time.Time `gorm:"index;not null" json:"created_at"`
CompletedAt *time.Time `json:"completed_at,omitempty"`
}
AsyncJob represents an asynchronous job record in the database. Jobs are created when requests are submitted to async endpoints and updated when the background operation completes or fails.
func (*AsyncJob) ToResponse ¶ added in v1.2.22
func (j *AsyncJob) ToResponse() *schemas.AsyncJobResponse
ToResponse converts an AsyncJob database record to an AsyncJobResponse for JSON output.
type AsyncJobCleaner ¶ added in v1.2.22
type AsyncJobCleaner struct {
// contains filtered or unexported fields
}
AsyncJobCleaner manages the cleanup of expired async jobs.
func NewAsyncJobCleaner ¶ added in v1.2.22
func NewAsyncJobCleaner(store LogStore, logger schemas.Logger) *AsyncJobCleaner
NewAsyncJobCleaner creates a new AsyncJobCleaner instance.
func (*AsyncJobCleaner) StartCleanupRoutine ¶ added in v1.2.22
func (c *AsyncJobCleaner) StartCleanupRoutine()
StartCleanupRoutine starts a goroutine that periodically cleans up expired async jobs.
func (*AsyncJobCleaner) StopCleanupRoutine ¶ added in v1.2.22
func (c *AsyncJobCleaner) StopCleanupRoutine()
StopCleanupRoutine gracefully stops the cleanup goroutine.
type AsyncJobExecutor ¶ added in v1.2.22
type AsyncJobExecutor struct {
// contains filtered or unexported fields
}
AsyncJobExecutor manages async job creation and background execution.
func NewAsyncJobExecutor ¶ added in v1.2.22
func NewAsyncJobExecutor(logstore LogStore, governanceStore GovernanceStore, logger schemas.Logger) *AsyncJobExecutor
NewAsyncJobExecutor creates a new AsyncJobExecutor.
func (*AsyncJobExecutor) RetrieveJob ¶ added in v1.2.22
func (e *AsyncJobExecutor) RetrieveJob(ctx context.Context, jobID string, vkValue *string, operationType schemas.RequestType) (*AsyncJob, error)
RetrieveJob retrieves a job by its ID.
func (*AsyncJobExecutor) SubmitJob ¶ added in v1.2.22
func (e *AsyncJobExecutor) SubmitJob(bifrostCtx *schemas.BifrostContext, resultTTL int, operation AsyncOperation, operationType schemas.RequestType) (*AsyncJob, error)
SubmitJob creates a pending job, starts background execution, and returns the job record.
type AsyncOperation ¶ added in v1.2.22
type AsyncOperation func(ctx *schemas.BifrostContext) (interface{}, *schemas.BifrostError)
AsyncOperation represents a function that can be executed asynchronously. It returns the response and an optional BifrostError.
type CleanerConfig ¶ added in v1.1.36
type CleanerConfig struct {
RetentionDays int
}
CleanerConfig holds configuration for the log cleaner
type Config ¶
type Config struct {
Enabled bool `json:"enabled"`
Type LogStoreType `json:"type"`
RetentionDays int `json:"retention_days"`
Config any `json:"config"`
}
Config represents the configuration for the logs store.
func (*Config) UnmarshalJSON ¶
UnmarshalJSON is the custom unmarshal logic for Config
type CostHistogramBucket ¶ added in v1.2.13
type CostHistogramBucket struct {
Timestamp time.Time `json:"timestamp"`
TotalCost float64 `json:"total_cost"`
ByModel map[string]float64 `json:"by_model"`
}
CostHistogramBucket represents a single time bucket for cost data
type CostHistogramResult ¶ added in v1.2.13
type CostHistogramResult struct {
Buckets []CostHistogramBucket `json:"buckets"`
BucketSizeSeconds int64 `json:"bucket_size_seconds"`
Models []string `json:"models"`
}
CostHistogramResult represents the cost histogram query result
type GovernanceStore ¶ added in v1.2.22
type GovernanceStore interface {
GetVirtualKey(vkValue string) (*configstoreTables.TableVirtualKey, bool)
}
GovernanceStore is an interface that provides access to the governance store.
type HistogramBucket ¶ added in v1.2.13
type HistogramBucket struct {
Timestamp time.Time `json:"timestamp"`
Count int64 `json:"count"`
Success int64 `json:"success"`
Error int64 `json:"error"`
}
HistogramBucket represents a single time bucket in the histogram
type HistogramResult ¶ added in v1.2.13
type HistogramResult struct {
Buckets []HistogramBucket `json:"buckets"`
BucketSizeSeconds int64 `json:"bucket_size_seconds"`
}
HistogramResult represents the histogram query result
type KeyPairResult ¶ added in v1.2.22
KeyPairResult represents an ID-Name pair returned from DISTINCT queries
type LatencyHistogramBucket ¶ added in v1.2.24
type LatencyHistogramBucket struct {
Timestamp time.Time `json:"timestamp"`
AvgLatency float64 `json:"avg_latency"`
P90Latency float64 `json:"p90_latency"`
P95Latency float64 `json:"p95_latency"`
P99Latency float64 `json:"p99_latency"`
TotalRequests int64 `json:"total_requests"`
}
LatencyHistogramBucket represents a single time bucket for latency data
type LatencyHistogramResult ¶ added in v1.2.24
type LatencyHistogramResult struct {
Buckets []LatencyHistogramBucket `json:"buckets"`
BucketSizeSeconds int64 `json:"bucket_size_seconds"`
}
LatencyHistogramResult represents the latency histogram query result
type Log ¶
type Log struct {
ID string `gorm:"primaryKey;type:varchar(255)" json:"id"`
ParentRequestID *string `gorm:"type:varchar(255)" json:"parent_request_id"`
Timestamp time.Time `gorm:"index;index:idx_logs_ts_provider_status,priority:1;not null" json:"timestamp"`
Object string `gorm:"type:varchar(255);index;not null;column:object_type" json:"object"` // text.completion, chat.completion, or embedding
Provider string `gorm:"type:varchar(255);index;index:idx_logs_ts_provider_status,priority:2;not null" json:"provider"`
Model string `gorm:"type:varchar(255);index;not null" json:"model"`
NumberOfRetries int `gorm:"default:0" json:"number_of_retries"`
FallbackIndex int `gorm:"default:0" json:"fallback_index"`
SelectedKeyID string `gorm:"type:varchar(255);index:idx_logs_selected_key_id" json:"selected_key_id"`
SelectedKeyName string `gorm:"type:varchar(255)" json:"selected_key_name"`
VirtualKeyID *string `gorm:"type:varchar(255);index:idx_logs_virtual_key_id" json:"virtual_key_id"`
VirtualKeyName *string `gorm:"type:varchar(255)" json:"virtual_key_name"`
RoutingEnginesUsedStr *string `gorm:"type:varchar(255);column:routing_engines_used" json:"-"` // Comma-separated routing engines
RoutingRuleID *string `gorm:"type:varchar(255);index:idx_logs_routing_rule_id" json:"routing_rule_id"`
RoutingRuleName *string `gorm:"type:varchar(255)" json:"routing_rule_name"`
InputHistory string `gorm:"type:text" json:"-"` // JSON serialized []schemas.ChatMessage
ResponsesInputHistory string `gorm:"type:text" json:"-"` // JSON serialized []schemas.ResponsesMessage
OutputMessage string `gorm:"type:text" json:"-"` // JSON serialized *schemas.ChatMessage
ResponsesOutput string `gorm:"type:text" json:"-"` // JSON serialized *schemas.ResponsesMessage
EmbeddingOutput string `gorm:"type:text" json:"-"` // JSON serialized embedding response data
RerankOutput string `gorm:"type:text" json:"-"` // JSON serialized []schemas.RerankResult
OCROutput string `gorm:"type:text" json:"-"` // JSON serialized *schemas.BifrostOCRResponse
Params string `gorm:"type:text" json:"-"` // JSON serialized *schemas.ModelParameters
Tools string `gorm:"type:text" json:"-"` // JSON serialized []schemas.Tool
ToolCalls string `gorm:"type:text" json:"-"` // JSON serialized []schemas.ToolCall (For backward compatibility, tool calls are now in the content)
SpeechInput string `gorm:"type:text" json:"-"` // JSON serialized *schemas.SpeechInput
TranscriptionInput string `gorm:"type:text" json:"-"` // JSON serialized *schemas.TranscriptionInput
ImageGenerationInput string `gorm:"type:text" json:"-"` // JSON serialized *schemas.ImageGenerationInput
VideoGenerationInput string `gorm:"type:text" json:"-"` // JSON serialized *schemas.VideoGenerationInput
SpeechOutput string `gorm:"type:text" json:"-"` // JSON serialized *schemas.BifrostSpeech
TranscriptionOutput string `gorm:"type:text" json:"-"` // JSON serialized *schemas.BifrostTranscribe
ImageGenerationOutput string `gorm:"type:text" json:"-"` // JSON serialized *schemas.BifrostImageGenerationResponse
ListModelsOutput string `gorm:"type:text" json:"-"` // JSON serialized []schemas.Model
VideoGenerationOutput string `gorm:"type:text" json:"-"` // JSON serialized *schemas.BifrostVideoGenerationResponse
VideoRetrieveOutput string `gorm:"type:text" json:"-"` // JSON serialized *schemas.BifrostVideoRetrieveResponse
VideoDownloadOutput string `gorm:"type:text" json:"-"` // JSON serialized *schemas.BifrostVideoDownloadResponse
VideoListOutput string `gorm:"type:text" json:"-"` // JSON serialized *schemas.BifrostVideoListResponse
VideoDeleteOutput string `gorm:"type:text" json:"-"` // JSON serialized *schemas.BifrostVideoDeleteResponse
CacheDebug string `gorm:"type:text" json:"-"` // JSON serialized *schemas.BifrostCacheDebug
Latency *float64 `gorm:"index:idx_logs_latency" json:"latency,omitempty"`
TokenUsage string `gorm:"type:text" json:"-"` // JSON serialized *schemas.LLMUsage
Cost *float64 `gorm:"index" json:"cost,omitempty"` // Cost in dollars (total cost of the request - includes cache lookup cost)
Status string `gorm:"type:varchar(50);index;index:idx_logs_ts_provider_status,priority:3;not null" json:"status"` // "processing", "success", or "error"
ErrorDetails string `gorm:"type:text" json:"-"` // JSON serialized *schemas.BifrostError
Stream bool `gorm:"default:false" json:"stream"` // true if this was a streaming response
ContentSummary string `gorm:"type:text" json:"-"`
RawRequest string `gorm:"type:text" json:"raw_request"` // Populated when `send-back-raw-request` is on
RawResponse string `gorm:"type:text" json:"raw_response"` // Populated when `send-back-raw-response` is on
PassthroughRequestBody string `gorm:"type:text" json:"passthrough_request_body,omitempty"` // Raw body for passthrough requests (UTF-8)
PassthroughResponseBody string `gorm:"type:text" json:"passthrough_response_body,omitempty"` // Raw body for passthrough responses (UTF-8)
RoutingEngineLogs string `gorm:"type:text" json:"routing_engine_logs,omitempty"` // Formatted routing engine decision logs
Metadata *string `gorm:"type:text" json:"-"` // JSON serialized map[string]interface{}
IsLargePayloadRequest bool `gorm:"default:false" json:"is_large_payload_request"`
IsLargePayloadResponse bool `gorm:"default:false" json:"is_large_payload_response"`
// Denormalized token fields for easier querying
PromptTokens int `gorm:"default:0" json:"-"`
CompletionTokens int `gorm:"default:0" json:"-"`
TotalTokens int `gorm:"index:idx_logs_total_tokens;default:0" json:"-"`
CachedReadTokens int `gorm:"default:0" json:"-"`
CreatedAt time.Time `gorm:"index;not null" json:"created_at"`
// Virtual fields for JSON output - these will be populated when needed
RoutingEnginesUsed []string `gorm:"-" json:"routing_engines_used,omitempty"` // Virtual field deserialized from JSON
InputHistoryParsed []schemas.ChatMessage `gorm:"-" json:"input_history,omitempty"`
ResponsesInputHistoryParsed []schemas.ResponsesMessage `gorm:"-" json:"responses_input_history,omitempty"`
OutputMessageParsed *schemas.ChatMessage `gorm:"-" json:"output_message,omitempty"`
ResponsesOutputParsed []schemas.ResponsesMessage `gorm:"-" json:"responses_output,omitempty"`
EmbeddingOutputParsed []schemas.EmbeddingData `gorm:"-" json:"embedding_output,omitempty"`
RerankOutputParsed []schemas.RerankResult `gorm:"-" json:"rerank_output,omitempty"`
OCROutputParsed *schemas.BifrostOCRResponse `gorm:"-" json:"ocr_output,omitempty"`
ParamsParsed interface{} `gorm:"-" json:"params,omitempty"`
ToolsParsed []schemas.ChatTool `gorm:"-" json:"tools,omitempty"`
ToolCallsParsed []schemas.ChatAssistantMessageToolCall `gorm:"-" json:"tool_calls,omitempty"` // For backward compatibility, tool calls are now in the content
TokenUsageParsed *schemas.BifrostLLMUsage `gorm:"-" json:"token_usage,omitempty"`
ErrorDetailsParsed *schemas.BifrostError `gorm:"-" json:"error_details,omitempty"`
SpeechInputParsed *schemas.SpeechInput `gorm:"-" json:"speech_input,omitempty"`
TranscriptionInputParsed *schemas.TranscriptionInput `gorm:"-" json:"transcription_input,omitempty"`
ImageGenerationInputParsed *schemas.ImageGenerationInput `gorm:"-" json:"image_generation_input,omitempty"`
SpeechOutputParsed *schemas.BifrostSpeechResponse `gorm:"-" json:"speech_output,omitempty"`
TranscriptionOutputParsed *schemas.BifrostTranscriptionResponse `gorm:"-" json:"transcription_output,omitempty"`
ImageGenerationOutputParsed *schemas.BifrostImageGenerationResponse `gorm:"-" json:"image_generation_output,omitempty"`
CacheDebugParsed *schemas.BifrostCacheDebug `gorm:"-" json:"cache_debug,omitempty"`
ListModelsOutputParsed []schemas.Model `gorm:"-" json:"list_models_output,omitempty"`
MetadataParsed map[string]interface{} `gorm:"-" json:"metadata,omitempty"`
VideoGenerationInputParsed *schemas.VideoGenerationInput `gorm:"-" json:"video_generation_input,omitempty"`
VideoGenerationOutputParsed *schemas.BifrostVideoGenerationResponse `gorm:"-" json:"video_generation_output,omitempty"`
VideoRetrieveOutputParsed *schemas.BifrostVideoGenerationResponse `gorm:"-" json:"video_retrieve_output,omitempty"`
VideoDownloadOutputParsed *schemas.BifrostVideoDownloadResponse `gorm:"-" json:"video_download_output,omitempty"`
VideoListOutputParsed *schemas.BifrostVideoListResponse `gorm:"-" json:"video_list_output,omitempty"`
VideoDeleteOutputParsed *schemas.BifrostVideoDeleteResponse `gorm:"-" json:"video_delete_output,omitempty"`
// Populated in handlers after find using the virtual key id and key id
VirtualKey *tables.TableVirtualKey `gorm:"-" json:"virtual_key,omitempty"` // redacted
SelectedKey *schemas.Key `gorm:"-" json:"selected_key,omitempty"` // redacted
RoutingRule *tables.TableRoutingRule `gorm:"-" json:"routing_rule,omitempty"` // redacted
}
Log represents a complete log entry for a request/response cycle This is the GORM model with appropriate tags
func NewLogEntryFromMap ¶ added in v1.2.9
NewLogEntryFromMap creates a new Log from a map[string]interface{}
func (*Log) BeforeCreate ¶
BeforeCreate GORM hook to set created_at and serialize JSON fields
func (*Log) BuildContentSummary ¶
BuildContentSummary creates a searchable text summary
func (*Log) DeserializeFields ¶
DeserializeFields converts JSON strings back to Go structs
func (*Log) SerializeFields ¶
SerializeFields converts Go structs to JSON strings for storage
type LogRetentionManager ¶ added in v1.1.36
type LogRetentionManager interface {
DeleteLogsBatch(ctx context.Context, cutoff time.Time, batchSize int) (deletedCount int64, err error)
}
LogRetentionManager defines the interface for managing log retention and deletion
type LogStore ¶
type LogStore interface {
Ping(ctx context.Context) error
Create(ctx context.Context, entry *Log) error
CreateIfNotExists(ctx context.Context, entry *Log) error
BatchCreateIfNotExists(ctx context.Context, entries []*Log) error
FindByID(ctx context.Context, id string) (*Log, error)
FindFirst(ctx context.Context, query any, fields ...string) (*Log, error)
FindAll(ctx context.Context, query any, fields ...string) ([]*Log, error)
FindAllDistinct(ctx context.Context, query any, fields ...string) ([]*Log, error)
HasLogs(ctx context.Context) (bool, error)
SearchLogs(ctx context.Context, filters SearchFilters, pagination PaginationOptions) (*SearchResult, error)
GetStats(ctx context.Context, filters SearchFilters) (*SearchStats, error)
GetHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*HistogramResult, error)
GetTokenHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*TokenHistogramResult, error)
GetCostHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*CostHistogramResult, error)
GetModelHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*ModelHistogramResult, error)
GetLatencyHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*LatencyHistogramResult, error)
GetProviderCostHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*ProviderCostHistogramResult, error)
GetProviderTokenHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*ProviderTokenHistogramResult, error)
GetProviderLatencyHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*ProviderLatencyHistogramResult, error)
GetModelRankings(ctx context.Context, filters SearchFilters) (*ModelRankingResult, error)
Update(ctx context.Context, id string, entry any) error
BulkUpdateCost(ctx context.Context, updates map[string]float64) error
Flush(ctx context.Context, since time.Time) error
Close(ctx context.Context) error
DeleteLog(ctx context.Context, id string) error
DeleteLogs(ctx context.Context, ids []string) error
DeleteLogsBatch(ctx context.Context, cutoff time.Time, batchSize int) (deletedCount int64, err error)
// Distinct value methods for filter data
GetDistinctModels(ctx context.Context) ([]string, error)
GetDistinctKeyPairs(ctx context.Context, idCol, nameCol string) ([]KeyPairResult, error)
GetDistinctRoutingEngines(ctx context.Context) ([]string, error)
GetDistinctMetadataKeys(ctx context.Context) (map[string][]string, error)
// MCP Tool Log histogram methods
GetMCPHistogram(ctx context.Context, filters MCPToolLogSearchFilters, bucketSizeSeconds int64) (*MCPHistogramResult, error)
GetMCPCostHistogram(ctx context.Context, filters MCPToolLogSearchFilters, bucketSizeSeconds int64) (*MCPCostHistogramResult, error)
GetMCPTopTools(ctx context.Context, filters MCPToolLogSearchFilters, limit int) (*MCPTopToolsResult, error)
// MCP Tool Log methods
CreateMCPToolLog(ctx context.Context, entry *MCPToolLog) error
FindMCPToolLog(ctx context.Context, id string) (*MCPToolLog, error)
UpdateMCPToolLog(ctx context.Context, id string, entry any) error
SearchMCPToolLogs(ctx context.Context, filters MCPToolLogSearchFilters, pagination PaginationOptions) (*MCPToolLogSearchResult, error)
GetMCPToolLogStats(ctx context.Context, filters MCPToolLogSearchFilters) (*MCPToolLogStats, error)
HasMCPToolLogs(ctx context.Context) (bool, error)
DeleteMCPToolLogs(ctx context.Context, ids []string) error
FlushMCPToolLogs(ctx context.Context, since time.Time) error
GetAvailableToolNames(ctx context.Context) ([]string, error)
GetAvailableServerLabels(ctx context.Context) ([]string, error)
GetAvailableMCPVirtualKeys(ctx context.Context) ([]MCPToolLog, error)
// Async Job methods
CreateAsyncJob(ctx context.Context, job *AsyncJob) error
FindAsyncJobByID(ctx context.Context, id string) (*AsyncJob, error)
UpdateAsyncJob(ctx context.Context, id string, updates map[string]interface{}) error
DeleteExpiredAsyncJobs(ctx context.Context) (int64, error)
DeleteStaleAsyncJobs(ctx context.Context, staleSince time.Time) (int64, error)
}
LogStore is the interface for the log store.
type LogStoreType ¶
type LogStoreType string
LogStoreType represents the type of log store.
const ( LogStoreTypeSQLite LogStoreType = "sqlite" LogStoreTypePostgres LogStoreType = "postgres" )
LogStoreTypeSQLite is the type of log store for SQLite.
type LogsCleaner ¶ added in v1.1.36
type LogsCleaner struct {
// contains filtered or unexported fields
}
LogsCleaner manages the cleanup of old logs
func NewLogsCleaner ¶ added in v1.1.36
func NewLogsCleaner(manager LogRetentionManager, config CleanerConfig, logger schemas.Logger) *LogsCleaner
NewLogsCleaner creates a new LogsCleaner instance
func (*LogsCleaner) StartCleanupRoutine ¶ added in v1.1.36
func (c *LogsCleaner) StartCleanupRoutine()
StartCleanupRoutine starts a goroutine that periodically cleans up old logs
func (*LogsCleaner) StopCleanupRoutine ¶ added in v1.1.36
func (c *LogsCleaner) StopCleanupRoutine()
StopCleanupRoutine gracefully stops the cleanup goroutine
type MCPCostHistogramBucket ¶ added in v1.2.31
type MCPCostHistogramBucket struct {
Timestamp time.Time `json:"timestamp"`
TotalCost float64 `json:"total_cost"`
}
MCPCostHistogramBucket represents a single time bucket for MCP cost data
type MCPCostHistogramResult ¶ added in v1.2.31
type MCPCostHistogramResult struct {
Buckets []MCPCostHistogramBucket `json:"buckets"`
BucketSizeSeconds int64 `json:"bucket_size_seconds"`
}
MCPCostHistogramResult represents the MCP cost histogram query result
type MCPHistogramBucket ¶ added in v1.2.31
type MCPHistogramBucket struct {
Timestamp time.Time `json:"timestamp"`
Count int64 `json:"count"`
Success int64 `json:"success"`
Error int64 `json:"error"`
}
MCPHistogramBucket represents a single time bucket for MCP tool call volume
type MCPHistogramResult ¶ added in v1.2.31
type MCPHistogramResult struct {
Buckets []MCPHistogramBucket `json:"buckets"`
BucketSizeSeconds int64 `json:"bucket_size_seconds"`
}
MCPHistogramResult represents the MCP tool call volume histogram query result
type MCPToolLog ¶ added in v1.2.17
type MCPToolLog struct {
ID string `gorm:"primaryKey;type:varchar(255)" json:"id"`
RequestID string `gorm:"type:varchar(255);column:request_id;index:idx_mcp_logs_request_id" json:"request_id,omitempty"` // The original request ID from context
LLMRequestID *string `gorm:"type:varchar(255);column:llm_request_id;index:idx_mcp_logs_llm_request_id" json:"llm_request_id,omitempty"` // Links to the LLM request that triggered this tool call
Timestamp time.Time `gorm:"index;not null" json:"timestamp"`
ToolName string `gorm:"type:varchar(255);index:idx_mcp_logs_tool_name;not null" json:"tool_name"`
ServerLabel string `gorm:"type:varchar(255);index:idx_mcp_logs_server_label" json:"server_label,omitempty"` // MCP server that provided the tool
VirtualKeyID *string `gorm:"type:varchar(255);index:idx_mcp_logs_virtual_key_id" json:"virtual_key_id"`
VirtualKeyName *string `gorm:"type:varchar(255)" json:"virtual_key_name"`
Arguments string `gorm:"type:text" json:"-"` // JSON serialized tool arguments
Result string `gorm:"type:text" json:"-"` // JSON serialized tool result
ErrorDetails string `gorm:"type:text" json:"-"` // JSON serialized *schemas.BifrostError
Latency *float64 `gorm:"index:idx_mcp_logs_latency" json:"latency,omitempty"` // Execution time in milliseconds
Cost *float64 `gorm:"index:idx_mcp_logs_cost" json:"cost,omitempty"` // Cost in dollars (per execution cost)
Status string `gorm:"type:varchar(50);index:idx_mcp_logs_status;not null" json:"status"` // "processing", "success", or "error"
Metadata string `gorm:"type:text" json:"-"` // JSON serialized map[string]interface{}
CreatedAt time.Time `gorm:"index;not null" json:"created_at"`
// Virtual fields for JSON output - populated when needed
ArgumentsParsed interface{} `gorm:"-" json:"arguments,omitempty"`
ResultParsed interface{} `gorm:"-" json:"result,omitempty"`
ErrorDetailsParsed *schemas.BifrostError `gorm:"-" json:"error_details,omitempty"`
MetadataParsed map[string]interface{} `gorm:"-" json:"metadata,omitempty"`
VirtualKey *tables.TableVirtualKey `gorm:"-" json:"virtual_key,omitempty"`
}
MCPToolLog represents a log entry for MCP tool executions This is separate from the main Log table since MCP tool calls have different fields
func (*MCPToolLog) AfterFind ¶ added in v1.2.17
func (l *MCPToolLog) AfterFind(tx *gorm.DB) error
AfterFind GORM hook to deserialize JSON fields
func (*MCPToolLog) BeforeCreate ¶ added in v1.2.17
func (l *MCPToolLog) BeforeCreate(tx *gorm.DB) error
BeforeCreate GORM hook to set created_at and serialize JSON fields
func (*MCPToolLog) DeserializeFields ¶ added in v1.2.17
func (l *MCPToolLog) DeserializeFields() error
DeserializeFields converts JSON strings back to Go structs
func (*MCPToolLog) SerializeFields ¶ added in v1.2.17
func (l *MCPToolLog) SerializeFields() error
SerializeFields converts Go structs to JSON strings for storage
func (MCPToolLog) TableName ¶ added in v1.2.17
func (MCPToolLog) TableName() string
TableName sets the table name for GORM
type MCPToolLogSearchFilters ¶ added in v1.2.17
type MCPToolLogSearchFilters struct {
ToolNames []string `json:"tool_names,omitempty"`
ServerLabels []string `json:"server_labels,omitempty"`
Status []string `json:"status,omitempty"`
VirtualKeyIDs []string `json:"virtual_key_ids,omitempty"`
LLMRequestIDs []string `json:"llm_request_ids,omitempty"`
StartTime *time.Time `json:"start_time,omitempty"`
EndTime *time.Time `json:"end_time,omitempty"`
MinLatency *float64 `json:"min_latency,omitempty"`
MaxLatency *float64 `json:"max_latency,omitempty"`
ContentSearch string `json:"content_search,omitempty"`
}
MCPToolLogSearchFilters represents the available filters for MCP tool log searches
type MCPToolLogSearchResult ¶ added in v1.2.17
type MCPToolLogSearchResult struct {
Logs []MCPToolLog `json:"logs"`
Pagination PaginationOptions `json:"pagination"`
Stats MCPToolLogStats `json:"stats"`
HasLogs bool `json:"has_logs"`
}
MCPToolLogSearchResult represents the result of an MCP tool log search
type MCPToolLogStats ¶ added in v1.2.17
type MCPToolLogStats struct {
TotalExecutions int64 `json:"total_executions"`
SuccessRate float64 `json:"success_rate"`
AverageLatency float64 `json:"average_latency"`
TotalCost float64 `json:"total_cost"` // Total cost in dollars
}
MCPToolLogStats represents statistics for MCP tool log searches
type MCPTopToolResult ¶ added in v1.2.31
type MCPTopToolResult struct {
ToolName string `json:"tool_name"`
Count int64 `json:"count"`
Cost float64 `json:"cost"`
}
MCPTopToolResult represents a single tool's aggregated stats
type MCPTopToolsResult ¶ added in v1.2.31
type MCPTopToolsResult struct {
Tools []MCPTopToolResult `json:"tools"`
}
MCPTopToolsResult represents the top N MCP tools by call count
type ModelHistogramBucket ¶ added in v1.2.13
type ModelHistogramBucket struct {
Timestamp time.Time `json:"timestamp"`
ByModel map[string]ModelUsageStats `json:"by_model"`
}
ModelHistogramBucket represents a single time bucket for model usage
type ModelHistogramResult ¶ added in v1.2.13
type ModelHistogramResult struct {
Buckets []ModelHistogramBucket `json:"buckets"`
BucketSizeSeconds int64 `json:"bucket_size_seconds"`
Models []string `json:"models"`
}
ModelHistogramResult represents the model histogram query result
type ModelRankingEntry ¶ added in v1.2.31
type ModelRankingEntry struct {
Model string `json:"model"`
Provider string `json:"provider"`
TotalRequests int64 `json:"total_requests"`
SuccessCount int64 `json:"success_count"`
SuccessRate float64 `json:"success_rate"`
TotalTokens int64 `json:"total_tokens"`
TotalCost float64 `json:"total_cost"`
AvgLatency float64 `json:"avg_latency"`
}
ModelRankingEntry represents aggregated stats for a single model over a time period.
type ModelRankingResult ¶ added in v1.2.31
type ModelRankingResult struct {
Rankings []ModelRankingWithTrend `json:"rankings"`
}
ModelRankingResult is the response for the model rankings endpoint.
type ModelRankingTrend ¶ added in v1.2.31
type ModelRankingTrend struct {
HasPreviousPeriod bool `json:"has_previous_period"`
RequestsTrend float64 `json:"requests_trend"`
TokensTrend float64 `json:"tokens_trend"`
CostTrend float64 `json:"cost_trend"`
LatencyTrend float64 `json:"latency_trend"`
}
ModelRankingTrend represents the percentage change compared to the previous period.
type ModelRankingWithTrend ¶ added in v1.2.31
type ModelRankingWithTrend struct {
ModelRankingEntry
Trend ModelRankingTrend `json:"trend"`
}
ModelRankingWithTrend combines ranking entry with trend data.
type ModelUsageStats ¶ added in v1.2.13
type ModelUsageStats struct {
Total int64 `json:"total"`
Success int64 `json:"success"`
Error int64 `json:"error"`
}
ModelUsageStats represents usage statistics for a single model
type PaginationOptions ¶
type PaginationOptions struct {
Limit int `json:"limit"`
Offset int `json:"offset"`
SortBy string `json:"sort_by"` // "timestamp", "latency", "tokens", "cost"
Order string `json:"order"` // "asc", "desc"
TotalCount int64 `json:"total_count"` // Total number of items matching the query
}
PaginationOptions represents pagination parameters
type PostgresConfig ¶ added in v1.1.0
type PostgresConfig struct {
Host *schemas.EnvVar `json:"host"`
Port *schemas.EnvVar `json:"port"`
User *schemas.EnvVar `json:"user"`
Password *schemas.EnvVar `json:"password"`
DBName *schemas.EnvVar `json:"db_name"`
SSLMode *schemas.EnvVar `json:"ssl_mode"`
MaxIdleConns int `json:"max_idle_conns"`
MaxOpenConns int `json:"max_open_conns"`
}
PostgresConfig represents the configuration for a Postgres database.
type ProviderCostHistogramBucket ¶ added in v1.2.25
type ProviderCostHistogramBucket struct {
Timestamp time.Time `json:"timestamp"`
TotalCost float64 `json:"total_cost"`
ByProvider map[string]float64 `json:"by_provider"`
}
ProviderCostHistogramBucket represents a single time bucket for provider cost data
type ProviderCostHistogramResult ¶ added in v1.2.25
type ProviderCostHistogramResult struct {
Buckets []ProviderCostHistogramBucket `json:"buckets"`
BucketSizeSeconds int64 `json:"bucket_size_seconds"`
Providers []string `json:"providers"`
}
ProviderCostHistogramResult represents the provider cost histogram query result
type ProviderLatencyHistogramBucket ¶ added in v1.2.25
type ProviderLatencyHistogramBucket struct {
Timestamp time.Time `json:"timestamp"`
ByProvider map[string]ProviderLatencyStats `json:"by_provider"`
}
ProviderLatencyHistogramBucket represents a single time bucket for provider latency data
type ProviderLatencyHistogramResult ¶ added in v1.2.25
type ProviderLatencyHistogramResult struct {
Buckets []ProviderLatencyHistogramBucket `json:"buckets"`
BucketSizeSeconds int64 `json:"bucket_size_seconds"`
Providers []string `json:"providers"`
}
ProviderLatencyHistogramResult represents the provider latency histogram query result
type ProviderLatencyStats ¶ added in v1.2.25
type ProviderLatencyStats struct {
AvgLatency float64 `json:"avg_latency"`
P90Latency float64 `json:"p90_latency"`
P95Latency float64 `json:"p95_latency"`
P99Latency float64 `json:"p99_latency"`
TotalRequests int64 `json:"total_requests"`
}
ProviderLatencyStats represents latency statistics for a single provider
type ProviderTokenHistogramBucket ¶ added in v1.2.25
type ProviderTokenHistogramBucket struct {
Timestamp time.Time `json:"timestamp"`
ByProvider map[string]ProviderTokenStats `json:"by_provider"`
}
ProviderTokenHistogramBucket represents a single time bucket for provider token data
type ProviderTokenHistogramResult ¶ added in v1.2.25
type ProviderTokenHistogramResult struct {
Buckets []ProviderTokenHistogramBucket `json:"buckets"`
BucketSizeSeconds int64 `json:"bucket_size_seconds"`
Providers []string `json:"providers"`
}
ProviderTokenHistogramResult represents the provider token histogram query result
type ProviderTokenStats ¶ added in v1.2.25
type ProviderTokenStats struct {
PromptTokens int64 `json:"prompt_tokens"`
CompletionTokens int64 `json:"completion_tokens"`
TotalTokens int64 `json:"total_tokens"`
}
ProviderTokenStats represents token statistics for a single provider
type RDBLogStore ¶ added in v1.1.0
type RDBLogStore struct {
// contains filtered or unexported fields
}
RDBLogStore represents a log store that uses a SQLite database.
func (*RDBLogStore) BatchCreateIfNotExists ¶ added in v1.2.24
func (s *RDBLogStore) BatchCreateIfNotExists(ctx context.Context, entries []*Log) error
BatchCreateIfNotExists inserts multiple log entries in a single transaction. Uses ON CONFLICT DO NOTHING for idempotency.
func (*RDBLogStore) BulkUpdateCost ¶ added in v1.1.49
BulkUpdateCost updates log costs in bulk, using a PostgreSQL-specific batched VALUES update when available and per-row updates for other dialects.
func (*RDBLogStore) Close ¶ added in v1.1.0
func (s *RDBLogStore) Close(ctx context.Context) error
Close closes the log store.
func (*RDBLogStore) Create ¶ added in v1.1.0
func (s *RDBLogStore) Create(ctx context.Context, entry *Log) error
Create inserts a new log entry into the database.
func (*RDBLogStore) CreateAsyncJob ¶ added in v1.2.22
func (s *RDBLogStore) CreateAsyncJob(ctx context.Context, job *AsyncJob) error
CreateAsyncJob creates a new async job record in the database.
func (*RDBLogStore) CreateIfNotExists ¶ added in v1.1.40
func (s *RDBLogStore) CreateIfNotExists(ctx context.Context, entry *Log) error
CreateIfNotExists inserts a new log entry only if it doesn't already exist. Uses ON CONFLICT DO NOTHING to handle duplicate key errors gracefully.
func (*RDBLogStore) CreateMCPToolLog ¶ added in v1.2.17
func (s *RDBLogStore) CreateMCPToolLog(ctx context.Context, entry *MCPToolLog) error
CreateMCPToolLog inserts a new MCP tool log entry into the database.
func (*RDBLogStore) DeleteExpiredAsyncJobs ¶ added in v1.2.22
func (s *RDBLogStore) DeleteExpiredAsyncJobs(ctx context.Context) (int64, error)
DeleteExpiredAsyncJobs deletes async jobs whose expires_at has passed. Only deletes jobs that have a non-null expires_at (i.e., completed or failed jobs). Deletes in batches to avoid long-running transactions that hold row locks.
func (*RDBLogStore) DeleteLog ¶ added in v1.1.36
func (s *RDBLogStore) DeleteLog(ctx context.Context, id string) error
DeleteLog deletes a log entry from the database by its ID.
func (*RDBLogStore) DeleteLogs ¶ added in v1.1.36
func (s *RDBLogStore) DeleteLogs(ctx context.Context, ids []string) error
DeleteLogs deletes multiple log entries from the database by their IDs.
func (*RDBLogStore) DeleteLogsBatch ¶ added in v1.1.36
func (s *RDBLogStore) DeleteLogsBatch(ctx context.Context, cutoff time.Time, batchSize int) (deletedCount int64, err error)
DeleteLogsBatch deletes logs older than the cutoff time in batches.
func (*RDBLogStore) DeleteMCPToolLogs ¶ added in v1.2.17
func (s *RDBLogStore) DeleteMCPToolLogs(ctx context.Context, ids []string) error
DeleteMCPToolLogs deletes multiple MCP tool log entries from the database by their IDs.
func (*RDBLogStore) DeleteStaleAsyncJobs ¶ added in v1.2.22
func (s *RDBLogStore) DeleteStaleAsyncJobs(ctx context.Context, staleSince time.Time) (int64, error)
DeleteStaleAsyncJobs deletes async jobs stuck in "processing" status since before the given time. This handles edge cases like marshal failures or server crashes that leave jobs permanently stuck.
func (*RDBLogStore) FindAllDistinct ¶ added in v1.2.24
func (s *RDBLogStore) FindAllDistinct(ctx context.Context, query any, fields ...string) ([]*Log, error)
FindAllDistinct finds all distinct log entries for the given fields. Uses SQL DISTINCT to return only unique combinations, avoiding loading all rows when only unique values are needed (e.g., for filter dropdowns).
func (*RDBLogStore) FindAsyncJobByID ¶ added in v1.2.22
FindAsyncJobByID retrieves an async job by its ID.
func (*RDBLogStore) FindByID ¶ added in v1.2.9
FindByID gets a log entry from the database by its ID.
func (*RDBLogStore) FindMCPToolLog ¶ added in v1.2.17
func (s *RDBLogStore) FindMCPToolLog(ctx context.Context, id string) (*MCPToolLog, error)
FindMCPToolLog retrieves a single MCP tool log entry by its ID.
func (*RDBLogStore) FlushMCPToolLogs ¶ added in v1.2.17
FlushMCPToolLogs deletes old processing MCP tool log entries from the database.
func (*RDBLogStore) GetAvailableMCPVirtualKeys ¶ added in v1.2.17
func (s *RDBLogStore) GetAvailableMCPVirtualKeys(ctx context.Context) ([]MCPToolLog, error)
GetAvailableMCPVirtualKeys returns all unique virtual key ID-Name pairs from MCP tool logs. Scoped to recent data to avoid full table scans.
func (*RDBLogStore) GetAvailableServerLabels ¶ added in v1.2.17
func (s *RDBLogStore) GetAvailableServerLabels(ctx context.Context) ([]string, error)
GetAvailableServerLabels returns all unique server labels from the MCP tool logs. Scoped to recent data to avoid full table scans.
func (*RDBLogStore) GetAvailableToolNames ¶ added in v1.2.17
func (s *RDBLogStore) GetAvailableToolNames(ctx context.Context) ([]string, error)
GetAvailableToolNames returns all unique tool names from the MCP tool logs. Scoped to recent data to avoid full table scans.
func (*RDBLogStore) GetCostHistogram ¶ added in v1.2.13
func (s *RDBLogStore) GetCostHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*CostHistogramResult, error)
GetCostHistogram returns time-bucketed cost data with model breakdown for the given filters.
func (*RDBLogStore) GetDistinctKeyPairs ¶ added in v1.2.22
func (s *RDBLogStore) GetDistinctKeyPairs(ctx context.Context, idCol, nameCol string) ([]KeyPairResult, error)
GetDistinctKeyPairs returns unique non-empty ID-Name pairs for the given columns using SELECT DISTINCT. idCol and nameCol must be valid column names (e.g., "selected_key_id", "selected_key_name").
func (*RDBLogStore) GetDistinctMetadataKeys ¶ added in v1.2.28
GetDistinctMetadataKeys returns unique metadata keys and their distinct values from recent logs. It scans a bounded number of recent rows to avoid memory bloat on large tables.
func (*RDBLogStore) GetDistinctModels ¶ added in v1.2.22
func (s *RDBLogStore) GetDistinctModels(ctx context.Context) ([]string, error)
GetDistinctModels returns all unique non-empty model values using SELECT DISTINCT. Scoped to recent data to avoid full table scans.
func (*RDBLogStore) GetDistinctRoutingEngines ¶ added in v1.2.22
func (s *RDBLogStore) GetDistinctRoutingEngines(ctx context.Context) ([]string, error)
GetDistinctRoutingEngines returns all unique routing engine values from the comma-separated column. Scoped to recent data to avoid full table scans.
func (*RDBLogStore) GetHistogram ¶ added in v1.2.13
func (s *RDBLogStore) GetHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*HistogramResult, error)
GetHistogram returns time-bucketed request counts for the given filters.
func (*RDBLogStore) GetLatencyHistogram ¶ added in v1.2.24
func (s *RDBLogStore) GetLatencyHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*LatencyHistogramResult, error)
GetLatencyHistogram returns time-bucketed latency percentiles (avg, p90, p95, p99) for the given filters. PostgreSQL uses database-level percentile_cont aggregation (returns 1 row per bucket). MySQL and SQLite fall back to Go-based percentile computation (loads individual latency values).
func (*RDBLogStore) GetMCPCostHistogram ¶ added in v1.2.31
func (s *RDBLogStore) GetMCPCostHistogram(ctx context.Context, filters MCPToolLogSearchFilters, bucketSizeSeconds int64) (*MCPCostHistogramResult, error)
GetMCPCostHistogram returns time-bucketed MCP cost data for the given filters.
func (*RDBLogStore) GetMCPHistogram ¶ added in v1.2.31
func (s *RDBLogStore) GetMCPHistogram(ctx context.Context, filters MCPToolLogSearchFilters, bucketSizeSeconds int64) (*MCPHistogramResult, error)
GetMCPHistogram returns time-bucketed MCP tool call volume for the given filters.
func (*RDBLogStore) GetMCPToolLogStats ¶ added in v1.2.17
func (s *RDBLogStore) GetMCPToolLogStats(ctx context.Context, filters MCPToolLogSearchFilters) (*MCPToolLogStats, error)
GetMCPToolLogStats calculates statistics for MCP tool logs matching the given filters.
func (*RDBLogStore) GetMCPTopTools ¶ added in v1.2.31
func (s *RDBLogStore) GetMCPTopTools(ctx context.Context, filters MCPToolLogSearchFilters, limit int) (*MCPTopToolsResult, error)
GetMCPTopTools returns the top N MCP tools by call count for the given filters.
func (*RDBLogStore) GetModelHistogram ¶ added in v1.2.13
func (s *RDBLogStore) GetModelHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*ModelHistogramResult, error)
GetModelHistogram returns time-bucketed model usage with success/error breakdown for the given filters.
func (*RDBLogStore) GetModelRankings ¶ added in v1.2.31
func (s *RDBLogStore) GetModelRankings(ctx context.Context, filters SearchFilters) (*ModelRankingResult, error)
GetModelRankings returns models ranked by usage with trend comparison to the previous period.
func (*RDBLogStore) GetProviderCostHistogram ¶ added in v1.2.25
func (s *RDBLogStore) GetProviderCostHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*ProviderCostHistogramResult, error)
GetProviderCostHistogram returns time-bucketed cost data with provider breakdown for the given filters.
func (*RDBLogStore) GetProviderLatencyHistogram ¶ added in v1.2.25
func (s *RDBLogStore) GetProviderLatencyHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*ProviderLatencyHistogramResult, error)
GetProviderLatencyHistogram returns time-bucketed latency percentiles with provider breakdown for the given filters. PostgreSQL uses database-level percentile_cont aggregation. MySQL and SQLite fall back to Go-based percentile computation.
func (*RDBLogStore) GetProviderTokenHistogram ¶ added in v1.2.25
func (s *RDBLogStore) GetProviderTokenHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*ProviderTokenHistogramResult, error)
GetProviderTokenHistogram returns time-bucketed token usage with provider breakdown for the given filters.
func (*RDBLogStore) GetStats ¶ added in v1.1.31
func (s *RDBLogStore) GetStats(ctx context.Context, filters SearchFilters) (*SearchStats, error)
GetStats calculates statistics for logs matching the given filters.
func (*RDBLogStore) GetTokenHistogram ¶ added in v1.2.13
func (s *RDBLogStore) GetTokenHistogram(ctx context.Context, filters SearchFilters, bucketSizeSeconds int64) (*TokenHistogramResult, error)
GetTokenHistogram returns time-bucketed token usage for the given filters.
func (*RDBLogStore) HasLogs ¶ added in v1.1.36
func (s *RDBLogStore) HasLogs(ctx context.Context) (bool, error)
HasLogs checks if there are any logs in the database.
func (*RDBLogStore) HasMCPToolLogs ¶ added in v1.2.17
func (s *RDBLogStore) HasMCPToolLogs(ctx context.Context) (bool, error)
HasMCPToolLogs checks if there are any MCP tool logs in the database.
func (*RDBLogStore) Ping ¶ added in v1.1.8
func (s *RDBLogStore) Ping(ctx context.Context) error
Ping checks if the database is reachable.
func (*RDBLogStore) SearchLogs ¶ added in v1.1.0
func (s *RDBLogStore) SearchLogs(ctx context.Context, filters SearchFilters, pagination PaginationOptions) (*SearchResult, error)
SearchLogs searches for logs in the database without calculating statistics.
func (*RDBLogStore) SearchMCPToolLogs ¶ added in v1.2.17
func (s *RDBLogStore) SearchMCPToolLogs(ctx context.Context, filters MCPToolLogSearchFilters, pagination PaginationOptions) (*MCPToolLogSearchResult, error)
SearchMCPToolLogs searches for MCP tool logs in the database.
func (*RDBLogStore) UpdateAsyncJob ¶ added in v1.2.22
func (s *RDBLogStore) UpdateAsyncJob(ctx context.Context, id string, updates map[string]interface{}) error
UpdateAsyncJob updates an async job record with the provided fields.
func (*RDBLogStore) UpdateMCPToolLog ¶ added in v1.2.17
UpdateMCPToolLog updates an MCP tool log entry in the database.
type SQLiteConfig ¶
type SQLiteConfig struct {
Path string `json:"path"`
}
SQLiteConfig represents the configuration for a SQLite database.
type SearchFilters ¶
type SearchFilters struct {
Providers []string `json:"providers,omitempty"`
Models []string `json:"models,omitempty"`
Status []string `json:"status,omitempty"`
Objects []string `json:"objects,omitempty"` // For filtering by request type (chat.completion, text.completion, embedding)
SelectedKeyIDs []string `json:"selected_key_ids,omitempty"`
VirtualKeyIDs []string `json:"virtual_key_ids,omitempty"`
RoutingRuleIDs []string `json:"routing_rule_ids,omitempty"`
RoutingEngineUsed []string `json:"routing_engine_used,omitempty"` // For filtering by routing engine (routing-rule, governance, loadbalancing)
StartTime *time.Time `json:"start_time,omitempty"`
EndTime *time.Time `json:"end_time,omitempty"`
MinLatency *float64 `json:"min_latency,omitempty"`
MaxLatency *float64 `json:"max_latency,omitempty"`
MinTokens *int `json:"min_tokens,omitempty"`
MaxTokens *int `json:"max_tokens,omitempty"`
MinCost *float64 `json:"min_cost,omitempty"`
MaxCost *float64 `json:"max_cost,omitempty"`
MissingCostOnly bool `json:"missing_cost_only,omitempty"`
ContentSearch string `json:"content_search,omitempty"`
MetadataFilters map[string]string `json:"metadata_filters,omitempty"` // key=metadataKey, value=metadataValue for filtering by metadata
}
SearchFilters represents the available filters for log searches
type SearchResult ¶
type SearchResult struct {
Logs []Log `json:"logs"`
Pagination PaginationOptions `json:"pagination"`
Stats SearchStats `json:"stats"`
HasLogs bool `json:"has_logs"`
}
SearchResult represents the result of a log search
type SearchStats ¶
type SearchStats struct {
TotalRequests int64 `json:"total_requests"`
SuccessRate float64 `json:"success_rate"` // Percentage of successful requests
AverageLatency float64 `json:"average_latency"` // Average latency in milliseconds
TotalTokens int64 `json:"total_tokens"` // Total tokens used
TotalCost float64 `json:"total_cost"` // Total cost in dollars
}
type TokenHistogramBucket ¶ added in v1.2.13
type TokenHistogramBucket struct {
Timestamp time.Time `json:"timestamp"`
PromptTokens int64 `json:"prompt_tokens"`
CompletionTokens int64 `json:"completion_tokens"`
TotalTokens int64 `json:"total_tokens"`
CachedReadTokens int64 `json:"cached_read_tokens"`
}
TokenHistogramBucket represents a single time bucket for token usage
type TokenHistogramResult ¶ added in v1.2.13
type TokenHistogramResult struct {
Buckets []TokenHistogramBucket `json:"buckets"`
BucketSizeSeconds int64 `json:"bucket_size_seconds"`
}
TokenHistogramResult represents the token histogram query result