gateway

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 20 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 gateway is the read gateway: a Loki API in front of a stock Loki that marks every line it returns verified or unverified, checked against the interval roots an archive holds, and answers each stream's coverage (intervals proven, holes, retraction receipts). Grafana points at it as at Loki (docs/backend.md).

Index

Constants

View Source
const (
	LabelState  = "blogs_state"
	LabelReason = "blogs_reason"
)

The names a returned line's mark is given: a stream label when Loki answers with labels merged, structured metadata when the client asks for categorized labels (Grafana does).

View Source
const (
	Verified   = "verified"
	Unverified = "unverified"
)

The marks.

View Source
const (
	// ReasonPending: no interval proven in the archive covers the line's
	// batch yet.
	ReasonPending = "pending"
	// ReasonAltered: the line is not the one at its position in the batch
	// the root commits.
	ReasonAltered = "altered"
	// ReasonRelabeled: the line is, but the store's labels or time differ
	// from those the line carries.
	ReasonRelabeled = "relabeled"
	// ReasonRetracted: the batch was retracted; its receipt is in the
	// archive and the anchor still commits the position.
	ReasonRetracted = "retracted"
	// ReasonHole: the root commits the position and the archive never held
	// the batch.
	ReasonHole = "hole"
	// ReasonNoProvenance: the line carries no placement at all.
	ReasonNoProvenance = "no-provenance"
	// ReasonUnreadable: the archive's files for the batch could not be
	// read or did not verify, or, with a second archive, that archive's
	// interval file did not verify or disagrees on the root or the line's
	// path.
	ReasonUnreadable = "unreadable"
)

The reasons a line is unverified.

Variables

This section is empty.

Functions

func DeclareMetrics

func DeclareMetrics(m *metrics.Set)

DeclareMetrics declares the gateway's metrics.

Types

type Coverage

type Coverage struct {
	Stream    string    `json:"stream"`
	Producer  string    `json:"producer"`
	Intervals uint64    `json:"intervals"`
	Proven    []Span    `json:"proven"`
	Holes     []uint64  `json:"holes"`
	Retracted []Receipt `json:"retracted"`
	// Refused are interval files whose paths do not lead to their root.
	Refused map[string]string `json:"refused,omitempty"`
	// Cross is the second archive's agreement, when the gateway has one.
	Cross *Cross `json:"cross,omitempty"`
}

Coverage is one stream's state in the archive.

type Cross added in v0.5.0

type Cross struct {
	// Agree counts the intervals both hold and agree on.
	Agree uint64 `json:"agree"`
	// Missing are intervals the second archive has not proven: their
	// lines are pending.
	Missing []uint64 `json:"missing"`
	// Disagree are intervals whose files there do not verify or differ,
	// each with the first difference: their lines are unreadable.
	Disagree map[string]string `json:"disagree,omitempty"`
}

Cross is how a second archive's interval files compare with the archive's, for the intervals the archive has proven.

type Gateway

type Gateway struct {
	Loki     *url.URL
	Verifier *Verifier
	Metrics  *metrics.Set
	Note     func(format string, args ...any)
	// contains filtered or unexported fields
}

Gateway is the Loki API in front of Loki.

func (*Gateway) Annotate

func (g *Gateway) Annotate(ctx context.Context, raw []byte) ([]byte, error)

Annotate marks every line of a Loki query answer of streams; any other answer is returned as it is.

func (*Gateway) Handler

func (g *Gateway) Handler() http.Handler

Handler serves the Loki API, the coverage endpoint and the metrics.

func (*Gateway) Meter

func (g *Gateway) Meter(ctx context.Context, period time.Duration)

Meter updates the retention gauges and integrates them every period until ctx ends.

type Receipt

type Receipt struct {
	Seq         uint64 `json:"seq"`
	Commitment  string `json:"commitment"`
	Sweep       string `json:"sweep"`
	SweepHeight uint32 `json:"sweepHeight"`
}

Receipt is a retracted position and the sweep that retracted it.

type Span

type Span struct {
	Interval uint64 `json:"interval"`
	First    uint64 `json:"first"`
	Last     uint64 `json:"last"`
	Root     string `json:"root"`
	Token    string `json:"token"`
	Height   uint32 `json:"height"`
}

Span is one proven interval.

type Verdict

type Verdict struct {
	State    string
	Reason   string
	Interval uint64
}

Verdict is one line's mark.

type Verifier

type Verifier struct {
	// Dir is the archive's root: streams are under Dir/<stream>/<producer>.
	Dir string
	// Fetch finds digest-only content.
	Fetch reader.Fetch
	// Cross, when set, is a second archive's root: a line is verified
	// only when Cross also holds a verified interval file covering its seq
	// that agrees with Dir's on the interval, its root and token, and the
	// line's commitment and inclusion path. Cross lacking the interval
	// marks the line pending; a file there that does not verify, or that
	// disagrees, marks it unreadable.
	Cross string
	// Rescan is how stale the interval list may be before a line past its
	// end makes it read again.
	Rescan time.Duration
	// contains filtered or unexported fields
}

Verifier checks lines against an archive directory (blogs archive -dir).

func (*Verifier) Check

func (v *Verifier) Check(ctx context.Context, meta map[string]string, line, ts string, labels map[string]string) Verdict

Check marks one line the store answered: its placement (from structured metadata), its text, its time in nanoseconds as the store gives it, and the store's labels for it.

func (*Verifier) Coverage

func (v *Verifier) Coverage() ([]Coverage, error)

Coverage reads every stream in the archive.

func (*Verifier) Retained

func (v *Verifier) Retained() map[string]map[string]int64

Retained sums, per stream, the bytes the archive keeps for it in two kinds. content is the size of every batch's lines as recorded in the batch (the record's size field, so a digest-only batch counts the same whether or not this archive holds its content): what is billed. evidence is the carriers' BEEF on disk, each with the funding tree it spends: the cost of proof, measured and not billed. A retracted batch counts as neither once the archive has dropped it.

Jump to

Keyboard shortcuts

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