client

package
v0.0.0-...-f7cdbce Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: MIT Imports: 11 Imported by: 1

Documentation

Overview

Package client provides a client for pushing logs to a Loki instance.

Index

Constants

View Source
const PushPath = "/loki/api/v1/push"

PushPath is the path to the Loki push endpoint.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Push(entry Entry) error
}

Client is an interface that abstracts the sending of log entries to Loki. Each call to Push represents a single log entry being sent to Loki.

Implementations of this interface should be safe to use concurrently.

type Entry

type Entry struct {
	Timestamp          time.Time
	Labels             Labeler
	Line               string
	StructuredMetadata map[string]string
}

Entry is a struct that represents a single log entry to be sent to Loki. It contains the timestamp, labels, line, and structured metadata. It does not have any knowledge of streams.

func (*Entry) AsPushRequest

func (entry *Entry) AsPushRequest() push.PushRequest

AsPushRequest converts the Entry to a push.PushRequest that can be marshaled, compressed, and sent to Loki. This method does not modify the Entry.

func (*Entry) Encode

func (entry *Entry) Encode() ([]byte, error)

Encode converts the Entry to a byte slice that can be sent to Loki. It first serializes the Entry to a protobuf and then encodes it using Snappy compression. This method does not modify the Entry.

type LabelMap

type LabelMap map[string]string

LabelMap is a map of labels that can be converted to a string for sending to Loki. It implements the Labeler interface.

func (LabelMap) Label

func (lm LabelMap) Label() LabelString

Label returns the string representation of the LabelMap.

type LabelString

type LabelString string

LabelString is a string that contains labels already formatted as a string. It implements the Labeler interface.

func (LabelString) Label

func (ls LabelString) Label() LabelString

Label returns the string representation of the LabelsString. It is effectively a no-op.

type Labeler

type Labeler interface {
	// Label returns a single string that represents all the labels to add to the stream.
	//
	// # Format
	//
	// The labels follow the format `{key="value", key2="value2"}`. The values should be properly escaped as Go
	// strings, such as by [strconv.Quote]. The keys should also be sorted alphabetically.
	Label() LabelString
}

Labeler is an interface that abstracts the conversion of labels to a string for sending to Loki. For now, it is best to use the LabelMap type, which implements this interface.

type LokiClient

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

LokiClient is a client for pushing log entries to a Loki instance. It implements the Client interface.

func NewLokiClient

func NewLokiClient(url string) *LokiClient

NewLokiClient creates a new LokiClient with the given URL.

func (*LokiClient) Push

func (client *LokiClient) Push(entry Entry) error

Push implements the Client interface. It sends the given Entry to Loki.

Directories

Path Synopsis
Package fake provides a fake client for testing.
Package fake provides a fake client for testing.

Jump to

Keyboard shortcuts

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