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
- Variables
- func Declare(m *metrics.Set)
- func DeclareDoors(m *metrics.Set)
- func DeclareForward(m *metrics.Set)
- func LabelName(s string) string
- func ParseLabels(s string) (map[string]string, error)
- func PushBody(p []Placed) ([]byte, error)
- func ReadFrame(r *bufio.Reader) ([]byte, error)
- func TLSConfig(certFile, keyFile string, clientCA []byte) (*tls.Config, error)
- type Batcher
- func (b *Batcher) Do(ctx context.Context, fn func(context.Context) error) error
- func (b *Batcher) Prime(ctx context.Context) error
- func (b *Batcher) Run(ctx context.Context, grace time.Duration) error
- func (b *Batcher) Start()
- func (b *Batcher) Submit(ctx context.Context, recs []Record, wait bool) error
- type Doors
- type Engine
- type Forwarder
- type Lane
- type Placed
- type Published
- type Record
Constants ¶
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.
const FormVersion = 1
FormVersion is the line form's version, the "v" of every line.
const MaxBody = 16 << 20
MaxBody bounds one HTTP request's body, before and after decompression.
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.
const MaxSyslogFrame = MaxRecordLine
MaxSyslogFrame bounds one frame.
Variables ¶
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.
var ErrBusy = errors.New("ingest: busy")
ErrBusy is a submission refused because the queue is full.
var SweepStep = 3 * time.Second
SweepStep bounds how long one tick waits on a sweep in flight.
Functions ¶
func DeclareForward ¶
DeclareForward declares the forwarder's metrics.
func LabelName ¶
LabelName makes s a valid store label name: [a-zA-Z_][a-zA-Z0-9_]*, with every other character an underscore.
func ParseLabels ¶
ParseLabels reads a label set in Prometheus form: {a="b", c="d"}.
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
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
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 ¶
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.
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) ServeSyslog ¶
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 ¶
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.
type Placed ¶
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 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 ¶
DecodeLokiJSON reads a push in Loki's JSON form: values are [ts, line] or [ts, line, {structured metadata}].
func DecodeLokiProto ¶
DecodeLokiProto reads a PushRequest in protobuf (already decompressed).
func DecodeOTLPJSON ¶
DecodeOTLPJSON reads an ExportLogsServiceRequest in OTLP's JSON mapping.
func DecodeOTLPProto ¶
DecodeOTLPProto reads an ExportLogsServiceRequest in protobuf.
func ParseLine ¶
ParseLine reads a line in the line form back: the labels and timestamp a read gateway compares with what a store answers.
func ParseSyslog ¶
ParseSyslog reads one message. now stamps a message with no time.