loki

package
v0.0.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2025 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LogEvent

type LogEvent struct {
	PodName   string      `json:"pod_name"`
	Timestamp time.Time   `json:"timestamp,omitempty"`
	Message   string      `json:"message"`
	Metadata  LogMetadata `json:"metadata"`
}

LogEvent represents a log line event sent via SSE

func ParseLokiResponse

func ParseLokiResponse(resp *http.Response, opts LokiLogHTTPOptions) ([]LogEvent, error)

ParseLokiResponse parses a Loki HTTP API response and returns LogEvents

type LogEvents

type LogEvents struct {
	MessageType LogEventsMessageType `json:"type"`
	// LogEvents is a slice of log events
	Logs []LogEvent `json:"logs"`
	// Error message
	ErrorMessage string `json:"error_message,omitempty"`
}

type LogEventsMessageType

type LogEventsMessageType string
const (
	LogEventsMessageTypeLog       LogEventsMessageType = "log"
	LogEventsMessageTypeHeartbeat LogEventsMessageType = "heartbeat"
	LogEventsMessageTypeError     LogEventsMessageType = "error"
)

func (LogEventsMessageType) Schema

Register enum in OpenAPI specification https://github.com/danielgtaylor/huma/issues/621

type LogMetadata

type LogMetadata struct {
	// Metadata to stick on
	ServiceID     string `json:"service_id,omitempty"`
	TeamID        string `json:"team_id,omitempty"`
	ProjectID     string `json:"project_id,omitempty"`
	EnvironmentID string `json:"environment_id,omitempty"`
	DeploymentID  string `json:"deployment_id,omitempty"`
}

type LokiDirection

type LokiDirection string

LokiDirection represents the direction in which to return logs, loki defaults to backward

const (
	LokiDirectionForward  LokiDirection = "forward"
	LokiDirectionBackward LokiDirection = "backward"
)

func (LokiDirection) Schema

func (u LokiDirection) Schema(r huma.Registry) *huma.Schema

Register enum in OpenAPI specification https://github.com/danielgtaylor/huma/issues/621

func (LokiDirection) Values

func (LokiDirection) Values() (kinds []string)

Values provides list valid values for Enum.

type LokiLabelName

type LokiLabelName string
const (
	LokiLabelTeam        LokiLabelName = "unbind_team"
	LokiLabelProject     LokiLabelName = "unbind_project"
	LokiLabelEnvironment LokiLabelName = "unbind_environment"
	LokiLabelService     LokiLabelName = "unbind_service"
	LokiLabelDeployment  LokiLabelName = "unbind_deployment"
	LokiLabelBuild       LokiLabelName = "unbind_deployment_build"
)

type LokiLogHTTPOptions

type LokiLogHTTPOptions struct {
	Label      LokiLabelName // Label to filter logs by
	LabelValue string        // Value of the label to filter logs by
	RawFilter  string        // Raw logql filter string
	// * Query range options
	Start *time.Time     // Start time for the query
	End   *time.Time     // End time for the query
	Since *time.Duration // Get logs from this time ago
	// * Query options
	Time *time.Time // Time for the query
	// * Shared options
	Limit     *int           // Number of log lines to get
	Direction *LokiDirection // Direction of the logs (forward or backward)
}

LokiLogOptions represents options for querying logs from Loki query and query_range APIs

type LokiLogQuerier

type LokiLogQuerier struct {
	// contains filtered or unexported fields
}

func NewLokiLogger

func NewLokiLogger(cfg *config.Config) (*LokiLogQuerier, error)

func (*LokiLogQuerier) QueryLokiLogs

func (self *LokiLogQuerier) QueryLokiLogs(
	ctx context.Context,
	opts LokiLogHTTPOptions,
) ([]LogEvent, error)

QueryLokiLogs handles both instant queries (query) and range queries (query_range) based on the provided options

func (*LokiLogQuerier) StreamLokiPodLogs

func (self *LokiLogQuerier) StreamLokiPodLogs(
	ctx context.Context,
	opts LokiLogStreamOptions,
	eventChan chan<- LogEvents,
) error

StreamLokiPodLogs streams logs from Loki tail API using WebSocket for multiple pods using a single connection

type LokiLogStreamOptions

type LokiLogStreamOptions struct {
	Label      LokiLabelName // Label to filter logs by
	LabelValue string        // Value of the label to filter logs by
	RawFilter  string        // Raw logql filter string
	Since      time.Duration // Get logs from this time ago
	Limit      int           // Number of log lines to get
	Start      time.Time     // Get logs from a specific time
}

LokiLogStreamOptions represents options for filtering and streaming logs from Loki

type LokiQueryData

type LokiQueryData struct {
	ResultType string          `json:"resultType"`
	Result     json.RawMessage `json:"result"`
	Stats      json.RawMessage `json:"stats,omitempty"`
}

LokiQueryData contains the query result data

type LokiQueryResponse

type LokiQueryResponse struct {
	Status    string        `json:"status"`
	Data      LokiQueryData `json:"data"`
	ErrorType string        `json:"errorType,omitempty"`
	Error     string        `json:"error,omitempty"`
}

* HTTP API Responses LokiQueryResponse represents the response structure from Loki HTTP API

type LokiStreamResponse

type LokiStreamResponse struct {
	Streams []struct {
		Stream map[string]string `json:"stream"`
		Values [][2]string       `json:"values"` // [timestamp, message]
	} `json:"streams"`
}

LokiStreamResponse represents the format of a Loki log stream response

type MatrixSample

type MatrixSample struct {
	Timestamp int64   `json:"timestamp"`
	Value     float64 `json:"value,string"`
}

MatrixSample represents a sample in a matrix result

type MatrixValue

type MatrixValue struct {
	Metric map[string]string `json:"metric"`
	Values []MatrixSample    `json:"values"`
}

MatrixValue represents a series in a matrix result

type Stream

type Stream struct {
	Stream map[string]string `json:"stream"`
	Values []StreamValue     `json:"values"`
}

Stream represents a stream of logs for a specific set of labels

type StreamValue

type StreamValue []string // [timestamp, message]

StreamValue represents a single log entry in a stream

type VectorSample

type VectorSample struct {
	Timestamp int64   `json:"timestamp"`
	Value     float64 `json:"value,string"`
}

VectorSample represents a sample in a vector result

type VectorValue

type VectorValue struct {
	Metric map[string]string `json:"metric"`
	Value  VectorSample      `json:"value"`
}

VectorValue represents an instant vector sample

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL