objtest

package
v4.0.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

Package objtest builds a data-object storage directory for testing: a bucket holding logs objects, the index objects that describe them, and the tables of contents a metastore.Metastore resolves through.

Reach for objtest when a test needs section resolution to work, because the metastore, the section indexes and the stream IDs are all real.

Reach for github.com/grafana/loki/v4/pkg/dataobj/fixtures instead when a test only needs one object with a hand-laid section and no bucket. That is cheaper and lets the test state every row.

Index

Constants

View Source
const Tenant = "objtest"

Tenant is the tenant a Builder stores logs for. A Builder holds one tenant because the index Calculator accepts only single-tenant objects.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

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

Builder is a bucket holding logs data objects and index data objects. Append logs with Builder.Append, then call Builder.Close to write the indexes that make them resolvable.

func NewBuilder

func NewBuilder(t testing.TB, opts ...Option) *Builder

NewBuilder creates a builder that can be used for accumulating logs.

func (*Builder) Append

func (b *Builder) Append(ctx context.Context, streams ...logproto.Stream)

Append appends the given streams to the builder for Tenant.

func (*Builder) Close

func (b *Builder) Close()

Close flushes all remaining data and writes the indexes that make it resolvable. It does nothing on a second call: indexing twice would register every section again and a query would then count every row twice.

func (*Builder) Flush

func (b *Builder) Flush(ctx context.Context)

Flush writes the buffered logs as one object, so the streams appended after it land in a different object. It does nothing when nothing is buffered.

func (*Builder) Location

func (b *Builder) Location() Location

Location returns the location of index for b so they can be read. Data is not guaranteed to exist in the location until calling Builder.Close.

func (*Builder) Metastore

func (b *Builder) Metastore() *metastore.ObjectMetastore

Metastore returns a metastore that resolves the builder's objects. Call it after Builder.Close, which writes the indexes it reads.

type Location

type Location struct {
	Bucket      objstore.Bucket // Bucket where all data is stored.
	IndexPrefix string          // Prefix for index objects in the Bucket.
}

Location holds information about where objects for a Builder are stored. Location can be used to read data from a builder.

type Option

type Option func(*builderOptions)

Option customizes a Builder.

func WithBufferSize

func WithBufferSize(size flagext.Bytes) Option

WithBufferSize sets the size of the buffer the builder accumulates encoded data in before flushing it. Zero keeps the builder's default.

func WithMaxPageRows

func WithMaxPageRows(rows int) Option

WithMaxPageRows caps the row count of an encoded page. Zero keeps the builder's default.

func WithTargetObjectSize

func WithTargetObjectSize(size flagext.Bytes) Option

WithTargetObjectSize targets the compressed, encoded data one object holds before Append flushes it and starts a new one, so a small value splits a corpus across many objects instead of the few the builder's default otherwise produces. Zero keeps the builder's default.

func WithTargetPageSize

func WithTargetPageSize(size flagext.Bytes) Option

WithTargetPageSize targets the uncompressed data one encoded page holds. Zero keeps the builder's default.

func WithTargetSectionSize

func WithTargetSectionSize(size flagext.Bytes) Option

WithTargetSectionSize targets the uncompressed data one logs section holds, so a small value forces an object to hold several logs sections. Overflow goes to a new section rather than being refused, which is why it is a target and not a limit.

Zero keeps the builder's default, which is large enough that a test's worth of logs lands in one section.

Jump to

Keyboard shortcuts

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