ingest

package
v0.6.7 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 25 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

Overview

Package ingest is the provenance sidecar's engine: it turns what log shippers send (syslog over TCP or TLS, OTLP logs over HTTP, Loki push) into records, writes each record as one line in the line form, batches the lines onto blogs streams through the producer engine, and forwards each published line, with where it was published, to a log store.

Nothing here changes the blogs record: a line is content, and the line form is a convention of the sidecar, versioned by its own field (docs/backend.md).

Index

Constants

View Source
const (
	MetaStream   = "blogs_stream"
	MetaProducer = "blogs_producer"
	MetaSeq      = "blogs_seq"
	MetaLine     = "blogs_line"
)

The structured metadata names every forwarded line carries: where it was published. A read gateway finds the line's batch by them.

View Source
const FormVersion = 1

FormVersion is the line form's version, the "v" of every line.

View Source
const MaxBody = 16 << 20

MaxBody bounds one HTTP request's body, before and after decompression.

View Source
const MaxRecordLine = 64*1024 - 1

MaxRecordLine is the longest line form a record may encode to, newline excluded. The producer carries a longer input line as several lines, which would break the one record, one line rule, so a record over it is refused instead.

View Source
const MaxSyslogFrame = MaxRecordLine

MaxSyslogFrame bounds one frame.

Variables

View Source
var DefaultRetries = []time.Duration{time.Second, 2 * time.Second, 5 * time.Second, 10 * time.Second, 30 * time.Second, 60 * time.Second, 60 * time.Second, 120 * time.Second}

DefaultRetries are a push's waits: about five minutes in all.

View Source
var ErrBusy = errors.New("ingest: busy")

ErrBusy is a submission refused because the queue is full.

View Source
var SweepStep = 3 * time.Second

SweepStep bounds how long one tick waits on a sweep in flight.

Functions

func Declare

func Declare(m *metrics.Set)

Declare declares the batcher's metrics.

func DeclareDoors

func DeclareDoors(m *metrics.Set)

DeclareDoors declares the doors' metrics.

func DeclareForward

func DeclareForward(m *metrics.Set)

DeclareForward declares the forwarder's metrics.

func LabelName

func LabelName(s string) string

LabelName makes s a valid store label name: [a-zA-Z_][a-zA-Z0-9_]*, with every other character an underscore.

func ParseLabels

func ParseLabels(s string) (map[string]string, error)

ParseLabels reads a label set in Prometheus form: {a="b", c="d"}.

func PushBody

func PushBody(p []Placed) ([]byte, error)

PushBody is the Loki JSON push for placed lines: one stream per label set, each line with its placement as structured metadata.

func ReadFrame

func ReadFrame(r *bufio.Reader) ([]byte, error)

ReadFrame reads one syslog frame.

func TLSConfig

func TLSConfig(certFile, keyFile string, clientCA []byte) (*tls.Config, error)

TLSConfig is a server configuration for RFC 5425: the certificate and key, and, when clientCA is set, mutual TLS against it.

Types

type Batcher

type Batcher struct {
	Lanes []*Lane
	// Route picks a record's lane.
	Route func(*Record) int
	// Forward receives every record published, after its batch is.
	Forward func([]Placed)
	// Poll is how often anchors are ticked.
	Poll    time.Duration
	Metrics *metrics.Set
	Note    func(format string, args ...any)
	// Queue bounds the submissions waiting for the publishing goroutine.
	Queue int
	// contains filtered or unexported fields
}

Batcher owns the lanes' engines: one goroutine publishes and anchors for all of them, so engines sharing a home's coin pool never run at once.

func (*Batcher) Do added in v0.4.0

func (b *Batcher) Do(ctx context.Context, fn func(context.Context) error) error

Do runs fn on the publishing goroutine, between batches, and returns its error: how an operation on an engine (a retraction) runs while the sidecar keeps taking records.

func (*Batcher) Prime added in v0.4.0

func (b *Batcher) Prime(ctx context.Context) error

Prime makes sure every lane's stream has a batch funding tree to spend, minting and waiting for one when it has none, so that the first batch after a start does not wait for a block. A lane whose engine is not a producer engine is left as it is.

func (*Batcher) Run

func (b *Batcher) Run(ctx context.Context, grace time.Duration) error

Run publishes and anchors until ctx ends, then publishes what is queued under a context of its own bounded by grace.

func (*Batcher) Start

func (b *Batcher) Start()

Start prepares the batcher; call it before Submit and Run.

func (*Batcher) Submit

func (b *Batcher) Submit(ctx context.Context, recs []Record, wait bool) error

Submit puts records on their lanes. With wait it returns once every record's batch is published, or with the error that stopped it; without, once the records are queued. A record that does not encode refuses the whole submission before anything is queued.

type Doors

type Doors struct {
	Batcher *Batcher
	Metrics *metrics.Set
	Note    func(format string, args ...any)
	// Ready reports whether the sidecar is serving (the health endpoint).
	Ready func() bool
}

Doors serves the ingest doors in front of a batcher: OTLP logs and Loki push over HTTP, and syslog over TCP and TLS.

func (*Doors) Handler

func (d *Doors) Handler() http.Handler

Handler serves the HTTP doors, the metrics and the health check.

func (*Doors) ServeSyslog

func (d *Doors) ServeSyslog(ctx context.Context, l net.Listener, door string) error

ServeSyslog accepts syslog connections on l until ctx ends. Over TLS (RFC 5425), l is a TLS listener. Syslog has no acknowledgment, so a connection's messages are queued, not waited for; a full queue holds the connection back.

type Engine

type Engine interface {
	Stream() string
	Producer() string
	// Publish publishes lines (each LF-terminated) as one batch, or as
	// several when its encoding is over the record's bound, and returns
	// each batch published, in order.
	Publish(ctx context.Context, raw []byte, count int) ([]Published, error)
	// Tick anchors when the interval is due and collects an anchor in
	// flight.
	Tick(ctx context.Context) error
}

Engine is a producer on one stream, as the batcher drives it.

func FromEngine

func FromEngine(e *produce.Engine) Engine

FromEngine adapts a producer engine. It takes the engine's Published hook.

type Forwarder

type Forwarder struct {
	// URL is Loki's base URL.
	URL string
	// Tenant, when set, is sent as X-Scope-OrgID.
	Tenant  string
	HTTP    *http.Client
	Metrics *metrics.Set
	Note    func(format string, args ...any)
	// Retries are the waits between tries of one push.
	Retries []time.Duration
	// contains filtered or unexported fields
}

Forwarder pushes published lines to a stock Loki, in order, retrying a push that fails. Its queue is bounded: a push that cannot be queued, or that fails for good, is counted and dropped, and the lines stay on the stream, where an archive holds them.

func (*Forwarder) Forward

func (f *Forwarder) Forward(p []Placed)

Forward queues lines for the store, or drops them when the queue is full.

func (*Forwarder) Start

func (f *Forwarder) Start(ctx context.Context, queue int)

Start starts the pushing goroutine; it stops when ctx ends.

type Lane

type Lane struct {
	Engine Engine
	Cut    produce.Cut
}

Lane is one stream the batcher feeds, and when its batches are cut.

type Placed

type Placed struct {
	Rec      *Record
	Line     []byte
	Stream   string
	Producer string
	Seq      uint64
	Index    int
}

Placed is a record as it was published: the line, its stream and producer, and its batch's seq and its 1-based position in the batch.

type Published

type Published struct {
	Seq     uint64
	Carrier string
	Raw     []byte
}

Published is one batch published.

type Record

type Record struct {
	// Ts is the record's own time in nanoseconds since the epoch: a claim
	// of the shipper, like a batch's timestamp.
	Ts int64
	// Sev is the severity as text, or empty.
	Sev string
	// Labels are the low-cardinality keys a store indexes.
	Labels map[string]string
	// Attrs are everything else: attributes, structured metadata, fields.
	Attrs map[string]string
	Body  string
}

Record is one log record from any door.

func DecodeLokiJSON

func DecodeLokiJSON(b []byte) ([]Record, error)

DecodeLokiJSON reads a push in Loki's JSON form: values are [ts, line] or [ts, line, {structured metadata}].

func DecodeLokiProto

func DecodeLokiProto(b []byte) ([]Record, error)

DecodeLokiProto reads a PushRequest in protobuf (already decompressed).

func DecodeOTLPJSON

func DecodeOTLPJSON(b []byte) ([]Record, error)

DecodeOTLPJSON reads an ExportLogsServiceRequest in OTLP's JSON mapping.

func DecodeOTLPProto

func DecodeOTLPProto(b []byte) ([]Record, error)

DecodeOTLPProto reads an ExportLogsServiceRequest in protobuf.

func ParseLine

func ParseLine(b []byte) (*Record, error)

ParseLine reads a line in the line form back: the labels and timestamp a read gateway compares with what a store answers.

func ParseSyslog

func ParseSyslog(msg []byte, now time.Time) (Record, error)

ParseSyslog reads one message. now stamps a message with no time.

func (*Record) Line

func (r *Record) Line() ([]byte, error)

Line is the record in the line form, with no trailing newline.

Jump to

Keyboard shortcuts

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