Documentation
¶
Overview ¶
Package ui provides HTTP handlers for the Loki UI and cluster management interface.
Index ¶
- Variables
- type BuildInfo
- type Cluster
- type ComparisonOutcome
- type Config
- type GoldfishAPIResponse
- type GoldfishConfig
- type GoldfishMetrics
- func (m *GoldfishMetrics) IncrementDBConnectionErrors(errorType string)
- func (m *GoldfishMetrics) IncrementErrors(errorType string)
- func (m *GoldfishMetrics) IncrementRequests(status string)
- func (m *GoldfishMetrics) RecordDBConnectionWait(pool string, duration float64)
- func (m *GoldfishMetrics) RecordQueryDuration(queryType, status string, duration float64)
- func (m *GoldfishMetrics) RecordQueryRows(queryType string, rows float64)
- func (m *GoldfishMetrics) SetDBConnections(state string, count float64)
- type Member
- type NodeDetails
- type ReadyResponse
- type SampledQuery
- type Service
- func (s *Service) GenerateLogsExploreURL(traceID, namespace string, sampledAt time.Time) string
- func (s *Service) GenerateTraceExploreURL(traceID, spanID string, sampledAt time.Time) string
- func (s *Service) GetSampledQueries(page, pageSize int, filter goldfish.QueryFilter) (*GoldfishAPIResponse, error)
- func (s *Service) GetSampledQueriesWithContext(ctx context.Context, page, pageSize int, filter goldfish.QueryFilter) (*GoldfishAPIResponse, error)
- func (s *Service) RegisterHandler()
- type ServiceState
Constants ¶
This section is empty.
Variables ¶
var ErrGoldfishDisabled = sql.ErrNoRows
ErrGoldfishDisabled is returned when goldfish feature is disabled
var ErrGoldfishNotConfigured = sql.ErrConnDone
ErrGoldfishNotConfigured is returned when goldfish database is not configured
Functions ¶
This section is empty.
Types ¶
type BuildInfo ¶
type BuildInfo struct {
Version string `json:"version"`
Revision string `json:"revision"`
Branch string `json:"branch"`
BuildUser string `json:"buildUser"`
BuildDate string `json:"buildDate"`
GoVersion string `json:"goVersion"`
}
BuildInfo contains version and build information about a member.
type ComparisonOutcome ¶ added in v3.6.0
type ComparisonOutcome struct {
CorrelationID string `json:"correlationId" db:"correlation_id"`
ComparisonStatus string `json:"comparisonStatus" db:"comparison_status"`
DifferenceDetails any `json:"differenceDetails" db:"difference_details"`
PerformanceMetrics any `json:"performanceMetrics" db:"performance_metrics"`
ComparedAt time.Time `json:"comparedAt" db:"compared_at"`
CreatedAt time.Time `json:"createdAt" db:"created_at"`
}
ComparisonOutcome represents a comparison result from the database
type Config ¶
type Config struct {
Enabled bool `yaml:"enabled"` // Whether to enable the UI.
Debug bool `yaml:"debug"`
Goldfish GoldfishConfig `yaml:"goldfish"` // Goldfish query comparison configuration
Ring lokiring.RingConfig `yaml:"ring"` // UI ring configuration for cluster member discovery
}
func (*Config) RegisterFlags ¶
type GoldfishAPIResponse ¶ added in v3.6.0
type GoldfishAPIResponse struct {
Queries []SampledQuery `json:"queries"`
HasMore bool `json:"hasMore"`
Page int `json:"page"`
PageSize int `json:"pageSize"`
}
GoldfishAPIResponse represents the paginated API response
type GoldfishConfig ¶ added in v3.6.0
type GoldfishConfig struct {
Enable bool `yaml:"enable"` // Whether to enable the Goldfish query comparison feature.
CloudSQLUser string `yaml:"cloudsql_user"` // CloudSQL username
CloudSQLHost string `yaml:"cloudsql_host"` // CloudSQL host
CloudSQLPort int `yaml:"cloudsql_port"` // CloudSQL port
CloudSQLDatabase string `yaml:"cloudsql_database"` // CloudSQL database name
MaxConnections int `yaml:"max_connections"` // Maximum number of database connections
MaxIdleTime int `yaml:"max_idle_time"` // Maximum idle time for connections in seconds
GrafanaURL string `yaml:"grafana_url"` // Base URL of Grafana instance for explore links
TracesDatasourceUID string `yaml:"traces_datasource_uid"` // UID of the traces datasource in Grafana
LogsDatasourceUID string `yaml:"logs_datasource_uid"` // UID of the Loki datasource in Grafana
CellANamespace string `yaml:"cell_a_namespace"` // Namespace for Cell A logs
CellBNamespace string `yaml:"cell_b_namespace"` // Namespace for Cell B logs
}
type GoldfishMetrics ¶ added in v3.6.0
type GoldfishMetrics struct {
// contains filtered or unexported fields
}
GoldfishMetrics contains all goldfish-related metrics
func NewGoldfishMetrics ¶ added in v3.6.0
func NewGoldfishMetrics(reg prometheus.Registerer) *GoldfishMetrics
NewGoldfishMetrics creates and registers goldfish metrics
func (*GoldfishMetrics) IncrementDBConnectionErrors ¶ added in v3.6.0
func (m *GoldfishMetrics) IncrementDBConnectionErrors(errorType string)
IncrementDBConnectionErrors increments connection errors
func (*GoldfishMetrics) IncrementErrors ¶ added in v3.6.0
func (m *GoldfishMetrics) IncrementErrors(errorType string)
IncrementErrors increments the error counter
func (*GoldfishMetrics) IncrementRequests ¶ added in v3.6.0
func (m *GoldfishMetrics) IncrementRequests(status string)
IncrementRequests increments the request counter
func (*GoldfishMetrics) RecordDBConnectionWait ¶ added in v3.6.0
func (m *GoldfishMetrics) RecordDBConnectionWait(pool string, duration float64)
RecordDBConnectionWait records connection wait time
func (*GoldfishMetrics) RecordQueryDuration ¶ added in v3.6.0
func (m *GoldfishMetrics) RecordQueryDuration(queryType, status string, duration float64)
RecordQueryDuration records the duration of a database query
func (*GoldfishMetrics) RecordQueryRows ¶ added in v3.6.0
func (m *GoldfishMetrics) RecordQueryRows(queryType string, rows float64)
RecordQueryRows records the number of rows returned
func (*GoldfishMetrics) SetDBConnections ¶ added in v3.6.0
func (m *GoldfishMetrics) SetDBConnections(state string, count float64)
SetDBConnections sets the current connection count
type Member ¶
type Member struct {
Addr string `json:"addr"`
Target string `json:"target"`
Services []ServiceState `json:"services"`
Build BuildInfo `json:"build"`
Error error `json:"error,omitempty"`
Ready ReadyResponse `json:"ready,omitempty"`
// contains filtered or unexported fields
}
Member represents a node in the cluster with its current state and capabilities.
type NodeDetails ¶
type NodeDetails struct {
Member
Config string `json:"config"`
ClusterID string `json:"clusterID"`
ClusterSeededAt int64 `json:"clusterSeededAt"`
OS string `json:"os"`
Arch string `json:"arch"`
Edition string `json:"edition"`
Metrics map[string]interface{} `json:"metrics"`
}
NodeDetails contains the details of a node in the cluster. It adds on top of Member the config, build, clusterID, clusterSeededAt, os, arch, edition and registered analytics metrics.
type ReadyResponse ¶
type SampledQuery ¶ added in v3.6.0
type SampledQuery struct {
// Core query identification
CorrelationID string `json:"correlationId" db:"correlation_id"`
TenantID string `json:"tenantId" db:"tenant_id"`
User string `json:"user" db:"user"`
Query string `json:"query" db:"query"`
QueryType string `json:"queryType" db:"query_type"`
// Time range fields - stored as RFC3339 strings for API compatibility
StartTime string `json:"startTime" db:"start_time"` // RFC3339 formatted
EndTime string `json:"endTime" db:"end_time"` // RFC3339 formatted
StepDuration *int64 `json:"stepDuration" db:"step_duration"` // Step in milliseconds, nullable
// Performance statistics - flattened from QueryStats for API simplicity
// All are nullable as some queries might not have complete stats
CellAExecTimeMs *int64 `json:"cellAExecTimeMs" db:"cell_a_exec_time_ms"`
CellBExecTimeMs *int64 `json:"cellBExecTimeMs" db:"cell_b_exec_time_ms"`
CellAQueueTimeMs *int64 `json:"cellAQueueTimeMs" db:"cell_a_queue_time_ms"`
CellBQueueTimeMs *int64 `json:"cellBQueueTimeMs" db:"cell_b_queue_time_ms"`
CellABytesProcessed *int64 `json:"cellABytesProcessed" db:"cell_a_bytes_processed"`
CellBBytesProcessed *int64 `json:"cellBBytesProcessed" db:"cell_b_bytes_processed"`
CellALinesProcessed *int64 `json:"cellALinesProcessed" db:"cell_a_lines_processed"`
CellBLinesProcessed *int64 `json:"cellBLinesProcessed" db:"cell_b_lines_processed"`
CellABytesPerSecond *int64 `json:"cellABytesPerSecond" db:"cell_a_bytes_per_second"`
CellBBytesPerSecond *int64 `json:"cellBBytesPerSecond" db:"cell_b_bytes_per_second"`
CellALinesPerSecond *int64 `json:"cellALinesPerSecond" db:"cell_a_lines_per_second"`
CellBLinesPerSecond *int64 `json:"cellBLinesPerSecond" db:"cell_b_lines_per_second"`
CellAEntriesReturned *int64 `json:"cellAEntriesReturned" db:"cell_a_entries_returned"`
CellBEntriesReturned *int64 `json:"cellBEntriesReturned" db:"cell_b_entries_returned"`
CellASplits *int64 `json:"cellASplits" db:"cell_a_splits"`
CellBSplits *int64 `json:"cellBSplits" db:"cell_b_splits"`
CellAShards *int64 `json:"cellAShards" db:"cell_a_shards"`
CellBShards *int64 `json:"cellBShards" db:"cell_b_shards"`
// Response metadata - nullable for error cases
CellAResponseHash *string `json:"cellAResponseHash" db:"cell_a_response_hash"`
CellBResponseHash *string `json:"cellBResponseHash" db:"cell_b_response_hash"`
CellAResponseSize *int64 `json:"cellAResponseSize" db:"cell_a_response_size"`
CellBResponseSize *int64 `json:"cellBResponseSize" db:"cell_b_response_size"`
CellAStatusCode *int `json:"cellAStatusCode" db:"cell_a_status_code"`
CellBStatusCode *int `json:"cellBStatusCode" db:"cell_b_status_code"`
// Trace IDs - nullable as not all requests have traces
CellATraceID *string `json:"cellATraceID" db:"cell_a_trace_id"`
CellBTraceID *string `json:"cellBTraceID" db:"cell_b_trace_id"`
CellASpanID *string `json:"cellASpanID" db:"cell_a_span_id"`
CellBSpanID *string `json:"cellBSpanID" db:"cell_b_span_id"`
// Query engine version tracking
CellAUsedNewEngine bool `json:"cellAUsedNewEngine" db:"cell_a_used_new_engine"`
CellBUsedNewEngine bool `json:"cellBUsedNewEngine" db:"cell_b_used_new_engine"`
// Timestamps - time.Time for database scanning, formatted in JSON marshaling
SampledAt time.Time `json:"sampledAt" db:"sampled_at"`
CreatedAt time.Time `json:"createdAt" db:"created_at"`
// Comparison outcome - computed by backend logic
ComparisonStatus string `json:"comparisonStatus" db:"comparison_status"`
// UI-only fields - generated based on configuration, not stored in database
CellATraceLink *string `json:"cellATraceLink,omitempty"`
CellBTraceLink *string `json:"cellBTraceLink,omitempty"`
CellALogsLink *string `json:"cellALogsLink,omitempty"`
CellBLogsLink *string `json:"cellBLogsLink,omitempty"`
}
SampledQuery represents a sampled query from the database for API responses. This is the UI/API representation of goldfish.QuerySample with several important differences:
1. Time formatting: All time fields use RFC3339 strings instead of time.Time
- The frontend expects RFC3339 formatted strings for display
- Database columns store timestamps that are scanned into time.Time then formatted
2. Nullable fields: Uses pointers (*int64, *string) for nullable database columns
- The database schema allows NULLs for metrics that might not be available
- Go's zero values would be ambiguous (is 0 a real value or NULL?)
3. Flattened structure: QueryStats fields are flattened into individual columns
- Makes the API response simpler for frontend consumption
- Matches the database schema which stores stats as individual columns
4. Database tags: Includes `db:` tags for direct sqlx scanning from queries
- The storage layer returns goldfish.QuerySample for internal use
- The UI layer queries the database directly for performance
5. UI-specific fields: Includes trace/logs links generated from configuration
- These are computed based on Grafana configuration, not stored
type Service ¶
func NewService ¶
func (*Service) GenerateLogsExploreURL ¶ added in v3.6.0
GenerateLogsExploreURL generates a Grafana Explore URL for logs related to a trace ID
func (*Service) GenerateTraceExploreURL ¶ added in v3.6.0
GenerateTraceExploreURL generates a Grafana Explore URL for a given trace ID
func (*Service) GetSampledQueries ¶ added in v3.6.0
func (s *Service) GetSampledQueries(page, pageSize int, filter goldfish.QueryFilter) (*GoldfishAPIResponse, error)
GetSampledQueries retrieves sampled queries from the database with pagination and outcome filtering
func (*Service) GetSampledQueriesWithContext ¶ added in v3.6.0
func (s *Service) GetSampledQueriesWithContext(ctx context.Context, page, pageSize int, filter goldfish.QueryFilter) (*GoldfishAPIResponse, error)
GetSampledQueriesWithContext retrieves sampled queries with trace context
func (*Service) RegisterHandler ¶
func (s *Service) RegisterHandler()
RegisterHandler registers all UI API routes with the provided router.
type ServiceState ¶
ServiceState represents the current state of a service running on a member.