Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildFilter ¶ added in v1.16.1
func BuildFilter(opts QueryOptions) string
BuildFilter constructs the Cloud Logging filter string
When TraceID is set, filters by SEARCH() across the entry payload. Otherwise filters by jsonPayload.user_id. When AllMessages is set, the filter is not restricted to the incoming-request/request-stats messages, returning every log entry of the matched request instead.
The filter is exported because it is also rendered back to the user, both as a Cloud Logging console link and as a `gcloud logging read` invocation.
func ConsoleURL ¶ added in v1.16.1
func ConsoleURL(projectID string, opts QueryOptions) string
ConsoleURL returns a Google Cloud Logging "Logs Explorer" URL that opens the browser on the exact same entries the given query options match, so the user can browse the actual logs interactively.
The Logs Explorer takes its parameters as `;key=value` path segments, each percent-encoded, with the project passed as a regular query parameter.
See https://cloud.google.com/logging/docs/view/logs-explorer-interface
func IsNormalDisconnect ¶ added in v1.13.1
isNormalDisconnect returns true if the error indicates a normal client disconnect rather than an actual error condition
Types ¶
type Backend ¶ added in v1.13.1
type Backend interface {
// QueryLogs returns all log entries matching the criteria
// Returns both incoming requests and stats logs for correlation
QueryLogs(ctx context.Context, opts QueryOptions) ([]LogEntry, error)
// Close releases any resources held by the backend
Close() error
}
Backend abstracts the log querying mechanism
type ConnectionLog ¶
type ConnectionLog struct {
// From incoming request
TraceID string
UserID string
IPAddress string
OutputModule string
OutputModuleHash string
StartBlock int64
StopBlock uint64
ProductionMode bool
Timestamp time.Time
// From resource labels (backend-specific, extracted by backend)
Namespace string
ClusterName string
PodName string
// From stats (nil if not yet received)
Stats *ConnectionStats
// IsOrphan indicates this is a stats-only record with no matching incoming request
IsOrphan bool
}
ConnectionLog represents a single connection (may be partial if stats not yet received)
func (*ConnectionLog) Duration ¶
func (c *ConnectionLog) Duration() time.Duration
Duration returns the duration of the connection For active connections, returns time since start For closed connections, returns the actual duration
func (*ConnectionLog) Status ¶
func (c *ConnectionLog) Status() ConnectionStatus
Status returns the connection status based on whether stats are present and if there's an error
type ConnectionStats ¶
type ConnectionStats struct {
TotalBlocksProcessed uint64
BlockRatePerSec string
TimeToFirstData float64
ResolvedStartBlock uint64
Error string
EndTimestamp time.Time
Duration time.Duration // Request duration (from parallel_duration)
}
ConnectionStats contains statistics from the request stats log
type ConnectionStatus ¶
type ConnectionStatus string
Connection status constants
const ( StatusActive ConnectionStatus = "active" StatusClosed ConnectionStatus = "closed" StatusError ConnectionStatus = "error" StatusOrphan ConnectionStatus = "orphan" )
type CorrelationResult ¶
type CorrelationResult struct {
Connections []*ConnectionLog
MaxConcurrent int // Maximum number of connections active at the same time (orphans use range start as start time)
}
CorrelationResult holds the result of correlating incoming requests with stats
func CorrelateConnections ¶
func CorrelateConnections(entries []LogEntry, queryStartTime time.Time) *CorrelationResult
CorrelateConnections matches incoming request logs with their corresponding stats logs by trace_id. Returns correlated connections including orphaned stats records. queryStartTime is used as the timestamp for orphaned records (for sorting purposes).
type GCPBackend ¶
type GCPBackend struct {
// contains filtered or unexported fields
}
GCPBackend implements LogBackend using Google Cloud Logging
func NewGCPBackend ¶
NewGCPBackend creates a new GCP Cloud Logging backend
func (*GCPBackend) Close ¶
func (b *GCPBackend) Close() error
Close releases resources held by the backend
func (*GCPBackend) QueryLogs ¶
func (b *GCPBackend) QueryLogs(ctx context.Context, opts QueryOptions) ([]LogEntry, error)
QueryLogs queries Cloud Logging for connection-related log entries
type LogEntry ¶
type LogEntry struct {
// Common fields from jsonPayload
Message string
TraceID string
SessionID string
UserID string
IPAddress string
OutputModule string
OutputModuleHash string
StartBlock int64
StopBlock uint64
Cursor string
ProductionMode bool
FinalBlocksOnly bool
NoopMode bool
Timestamp string
// EntryTime is the timestamp of the log entry itself as recorded by the
// backend, used when the payload carries no `timestamp` field
EntryTime time.Time
// Stats-specific fields (only present for "substreams request stats")
Tier string
TotalBlocksProcessed uint64
BlockRatePerSec string
TimeToFirstData float64
ResolvedStartBlock uint64
Error string
Duration float64 // Request duration in seconds
// Resource labels (backend extracts these from envelope)
Namespace string
ClusterName string
PodName string
// Severity of the entry as reported by the backend ("INFO", "ERROR", ...),
// empty when the backend does not report one
Severity string
// Fields holds every jsonPayload field of the entry, used to render raw
// logs. Nil for entries whose payload was not a JSON object.
Fields map[string]any
}
LogEntry represents a raw log entry from any backend The backend extracts jsonPayload fields into this struct
func (*LogEntry) IsIncomingRequest ¶
IsIncomingRequest returns true if this is an incoming request log
func (*LogEntry) IsRequestStats ¶
IsRequestStats returns true if this is a request stats log (tier1 only)
type QueryOptions ¶
type QueryOptions struct {
UserID string
TraceID string
Namespace string
StartTime time.Time
EndTime time.Time
// AllMessages disables the "incoming request"/"request stats" message
// restriction, returning every log entry matching the subject (trace ID or
// user ID) instead. Used to display the raw logs of a single request.
AllMessages bool
// Limit caps the number of entries returned, keeping the newest ones. Zero
// means no limit.
Limit int
}
QueryOptions contains parameters for querying connection logs
Either UserID or TraceID must be set. UserID matches all requests for an organization; TraceID matches a single request via Cloud Logging SEARCH().