Documentation
¶
Index ¶
- func AutoMigrateModels(db *gorm.DB, driver string) error
- func NewDatabase(driver, dsn string) (*gorm.DB, error)
- type CompressedText
- type DashboardStats
- type LatencyPoint
- type Log
- type LogFilter
- type MetricBucket
- type Repository
- func (r *Repository) BatchCreateLogs(logs []Log) error
- func (r *Repository) BatchCreateMetrics(buckets []MetricBucket) error
- func (r *Repository) BatchCreateSpans(spans []Span) error
- func (r *Repository) BatchCreateTraces(traces []Trace) error
- func (r *Repository) CreateTrace(trace Trace) error
- func (r *Repository) DB() *gorm.DB
- func (r *Repository) GetDashboardStats(start, end time.Time, serviceNames []string) (*DashboardStats, error)
- func (r *Repository) GetLatencyHeatmap(start, end time.Time, serviceNames []string) ([]LatencyPoint, error)
- func (r *Repository) GetLog(id uint) (*Log, error)
- func (r *Repository) GetLogContext(targetTime time.Time) ([]Log, error)
- func (r *Repository) GetLogsV2(filter LogFilter) ([]Log, int64, error)
- func (r *Repository) GetMetricBuckets(start, end time.Time, serviceName string, metricName string) ([]MetricBucket, error)
- func (r *Repository) GetMetricNames(serviceName string) ([]string, error)
- func (r *Repository) GetRecentLogs(limit int) ([]Log, error)
- func (r *Repository) GetServiceMapMetrics(start, end time.Time) (*ServiceMapMetrics, error)
- func (r *Repository) GetServices() ([]string, error)
- func (r *Repository) GetStats() (map[string]interface{}, error)
- func (r *Repository) GetTrace(traceID string) (*Trace, error)
- func (r *Repository) GetTracesFiltered(start, end time.Time, serviceNames []string, status, search string, ...) (*TracesResponse, error)
- func (r *Repository) GetTrafficMetrics(start, end time.Time, serviceNames []string) ([]TrafficPoint, error)
- func (r *Repository) PurgeLogs(olderThan time.Time) (int64, error)
- func (r *Repository) PurgeTraces(olderThan time.Time) (int64, error)
- func (r *Repository) UpdateLogInsight(logID uint, insight string) error
- func (r *Repository) VacuumDB() error
- type ServiceError
- type ServiceMapEdge
- type ServiceMapMetrics
- type ServiceMapNode
- type Span
- type Trace
- type TracesResponse
- type TrafficPoint
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AutoMigrateModels ¶
AutoMigrateModels runs GORM auto-migration for all Argus models.
Types ¶
type CompressedText ¶
type CompressedText string
CompressedText is a string type that is transparently compressed using zstd before being stored in the database. It implements sql.Scanner and driver.Valuer for GORM.
func (*CompressedText) Scan ¶
func (ct *CompressedText) Scan(value interface{}) error
type DashboardStats ¶
type DashboardStats struct {
TotalTraces int64 `json:"total_traces"`
TotalLogs int64 `json:"total_logs"`
TotalErrors int64 `json:"total_errors"`
AvgLatencyMs float64 `json:"avg_latency_ms"`
ErrorRate float64 `json:"error_rate"`
ActiveServices int64 `json:"active_services"`
P99Latency int64 `json:"p99_latency"`
TopFailingServices []ServiceError `json:"top_failing_services"`
}
DashboardStats represents aggregated metrics for the dashboard.
type LatencyPoint ¶
type LatencyPoint struct {
Timestamp time.Time `json:"timestamp"`
Duration int64 `json:"duration"` // Microseconds
}
LatencyPoint represents a data point for the latency heatmap.
type Log ¶
type Log struct {
ID uint `gorm:"primaryKey" json:"id"`
TraceID string `gorm:"index;size:32" json:"trace_id"`
SpanID string `gorm:"size:16" json:"span_id"`
Severity string `gorm:"size:50;index" json:"severity"`
Body CompressedText `gorm:"type:blob" json:"body"`
ServiceName string `gorm:"size:255;index" json:"service_name"`
AttributesJSON CompressedText `gorm:"type:blob" json:"attributes_json"`
AIInsight CompressedText `gorm:"type:blob" json:"ai_insight"` // Populated by AI analysis
Timestamp time.Time `gorm:"index" json:"timestamp"`
}
Log represents a log entry associated with a trace.
type LogFilter ¶
type LogFilter struct {
ServiceName string
Severity string
Search string
StartTime time.Time
EndTime time.Time
Limit int
Offset int
}
LogFilter defines criteria for searching logs.
type MetricBucket ¶
type MetricBucket struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"size:255;index;not null" json:"name"`
ServiceName string `gorm:"size:255;index;not null" json:"service_name"`
TimeBucket time.Time `gorm:"index;not null" json:"time_bucket"`
Min float64 `json:"min"`
Max float64 `json:"max"`
Sum float64 `json:"sum"`
Count int64 `json:"count"`
AttributesJSON CompressedText `gorm:"type:blob" json:"attributes_json"` // Grouped attributes
}
MetricBucket represents aggregated metric data over a time window (e.g., 10s).
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository wraps the GORM database handle for all data access operations.
func NewRepository ¶
func NewRepository(metrics *telemetry.Metrics) (*Repository, error)
NewRepository initializes the database connection using environment variables and migrates the schema.
func (*Repository) BatchCreateLogs ¶
func (r *Repository) BatchCreateLogs(logs []Log) error
BatchCreateLogs inserts multiple logs in batches.
func (*Repository) BatchCreateMetrics ¶
func (r *Repository) BatchCreateMetrics(buckets []MetricBucket) error
BatchCreateMetrics inserts aggregated metrics in batches.
func (*Repository) BatchCreateSpans ¶
func (r *Repository) BatchCreateSpans(spans []Span) error
BatchCreateSpans inserts multiple spans in batches.
func (*Repository) BatchCreateTraces ¶
func (r *Repository) BatchCreateTraces(traces []Trace) error
BatchCreateTraces inserts traces, skipping duplicates.
func (*Repository) CreateTrace ¶
func (r *Repository) CreateTrace(trace Trace) error
CreateTrace inserts a new trace, skipping if it already exists.
func (*Repository) DB ¶
func (r *Repository) DB() *gorm.DB
DB returns the underlying gorm.DB for advanced queries.
func (*Repository) GetDashboardStats ¶
func (r *Repository) GetDashboardStats(start, end time.Time, serviceNames []string) (*DashboardStats, error)
GetDashboardStats calculates high-level metrics for the dashboard.
func (*Repository) GetLatencyHeatmap ¶
func (r *Repository) GetLatencyHeatmap(start, end time.Time, serviceNames []string) ([]LatencyPoint, error)
GetLatencyHeatmap returns trace duration and timestamps for heatmap rendering.
func (*Repository) GetLog ¶
func (r *Repository) GetLog(id uint) (*Log, error)
GetLog returns a single log by ID.
func (*Repository) GetLogContext ¶
func (r *Repository) GetLogContext(targetTime time.Time) ([]Log, error)
GetLogContext returns logs surrounding a specific timestamp (+/- 1 minute).
func (*Repository) GetLogsV2 ¶
func (r *Repository) GetLogsV2(filter LogFilter) ([]Log, int64, error)
GetLogsV2 performs advanced filtering and search on logs.
func (*Repository) GetMetricBuckets ¶
func (r *Repository) GetMetricBuckets(start, end time.Time, serviceName string, metricName string) ([]MetricBucket, error)
GetMetricBuckets returns aggregated metrics for a specific time range and service.
func (*Repository) GetMetricNames ¶
func (r *Repository) GetMetricNames(serviceName string) ([]string, error)
GetMetricNames returns a list of distinct metric names, optionally filtered by service.
func (*Repository) GetRecentLogs ¶
func (r *Repository) GetRecentLogs(limit int) ([]Log, error)
GetRecentLogs returns the most recent logs.
func (*Repository) GetServiceMapMetrics ¶
func (r *Repository) GetServiceMapMetrics(start, end time.Time) (*ServiceMapMetrics, error)
GetServiceMapMetrics computes topology metrics from spans.
func (*Repository) GetServices ¶
func (r *Repository) GetServices() ([]string, error)
GetServices returns a list of all distinct service names seen in traces.
func (*Repository) GetStats ¶
func (r *Repository) GetStats() (map[string]interface{}, error)
GetStats returns high-level database stats.
func (*Repository) GetTrace ¶
func (r *Repository) GetTrace(traceID string) (*Trace, error)
GetTrace returns a trace by ID with its spans and logs.
func (*Repository) GetTracesFiltered ¶
func (r *Repository) GetTracesFiltered(start, end time.Time, serviceNames []string, status, search string, limit, offset int, sortBy, orderBy string) (*TracesResponse, error)
GetTracesFiltered retrieves traces with filtering and pagination
func (*Repository) GetTrafficMetrics ¶
func (r *Repository) GetTrafficMetrics(start, end time.Time, serviceNames []string) ([]TrafficPoint, error)
GetTrafficMetrics returns request counts bucketed by minute, including error counts.
func (*Repository) PurgeLogs ¶
func (r *Repository) PurgeLogs(olderThan time.Time) (int64, error)
PurgeLogs deletes logs older than the given timestamp.
func (*Repository) PurgeTraces ¶
func (r *Repository) PurgeTraces(olderThan time.Time) (int64, error)
PurgeTraces deletes traces older than the given timestamp.
func (*Repository) UpdateLogInsight ¶
func (r *Repository) UpdateLogInsight(logID uint, insight string) error
UpdateLogInsight updates the AI insight for a specific log.
func (*Repository) VacuumDB ¶
func (r *Repository) VacuumDB() error
VacuumDB runs VACUUM on the database (SQLite only, no-op for others).
type ServiceError ¶
type ServiceError struct {
ServiceName string `json:"service_name"`
ErrorCount int64 `json:"error_count"`
TotalCount int64 `json:"total_count"`
ErrorRate float64 `json:"error_rate"`
}
ServiceError represents error counts per service.
type ServiceMapEdge ¶
type ServiceMapEdge struct {
Source string `json:"source"`
Target string `json:"target"`
CallCount int64 `json:"call_count"`
AvgLatencyMs float64 `json:"avg_latency_ms"`
ErrorRate float64 `json:"error_rate"`
}
ServiceMapEdge represents a connection between two services.
type ServiceMapMetrics ¶
type ServiceMapMetrics struct {
Nodes []ServiceMapNode `json:"nodes"`
Edges []ServiceMapEdge `json:"edges"`
}
ServiceMapMetrics holds the complete service topology with metrics.
type ServiceMapNode ¶
type ServiceMapNode struct {
Name string `json:"name"`
TotalTraces int64 `json:"total_traces"`
ErrorCount int64 `json:"error_count"`
AvgLatencyMs float64 `json:"avg_latency_ms"`
}
ServiceMapNode represents a single service node on the service map.
type Span ¶
type Span struct {
ID uint `gorm:"primaryKey" json:"id"`
TraceID string `gorm:"index;size:32;not null" json:"trace_id"`
SpanID string `gorm:"size:16;not null" json:"span_id"`
ParentSpanID string `gorm:"size:16" json:"parent_span_id"`
OperationName string `gorm:"size:255;index" json:"operation_name"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Duration int64 `json:"duration"` // Microseconds
ServiceName string `gorm:"size:255;index" json:"service_name"` // Originating service
AttributesJSON CompressedText `gorm:"type:blob" json:"attributes_json"` // Compressed JSON string
}
Span represents a single operation within a trace.
type Trace ¶
type Trace struct {
ID uint `gorm:"primaryKey" json:"id"`
TraceID string `gorm:"uniqueIndex;size:32;not null" json:"trace_id"`
ServiceName string `gorm:"size:255;index" json:"service_name"`
Duration int64 `gorm:"index" json:"duration"` // Microseconds
DurationMs float64 `gorm:"-" json:"duration_ms"`
SpanCount int `gorm:"-" json:"span_count"`
Operation string `gorm:"-" json:"operation"`
Status string `gorm:"size:50" json:"status"`
Timestamp time.Time `gorm:"index" json:"timestamp"`
Spans []Span `gorm:"foreignKey:TraceID;references:TraceID;constraint:false" json:"spans,omitempty"`
Logs []Log `gorm:"foreignKey:TraceID;references:TraceID;constraint:false" json:"logs,omitempty"`
CreatedAt time.Time `json:"-"`
UpdatedAt time.Time `json:"-"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
Trace represents a complete distributed trace.