thanos

package
v1.136.7 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const ChunkEncAggr = chunkenc.Encoding(0xff)

ChunkEncAggr is the top level encoding byte for the AggrChunk. It is defined by Thanos as 0xff to prevent collisions with Prometheus encodings.

Variables

AllAggrTypes contains all supported aggregation types.

View Source
var ErrAggrNotExist = errors.New("aggregate does not exist")

ErrAggrNotExist is returned if a requested aggregation is not present in an AggrChunk.

Functions

func CloseBlocks

func CloseBlocks(blocks []BlockInfo)

CloseBlocks closes all blocks in the slice. Must be called only after all queriers on these blocks have been closed.

func IsAggrChunk

func IsAggrChunk(enc chunkenc.Encoding) bool

IsAggrChunk checks if the encoding byte indicates this is an AggrChunk.

Types

type AggrChunk

type AggrChunk []byte

AggrChunk is a chunk that is composed of a set of aggregates for the same underlying data. Not all aggregates must be present. This is a read-only implementation for decoding Thanos downsampled blocks.

func (AggrChunk) Encoding

func (c AggrChunk) Encoding() chunkenc.Encoding

Encoding returns the encoding type for AggrChunk.

func (AggrChunk) Get

func (c AggrChunk) Get(t AggrType) (chunkenc.Chunk, error)

Get returns the sub-chunk for the given aggregate type if it exists.

type AggrChunkPool

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

AggrChunkPool is a custom Pool that understands AggrChunk encoding (0xff). It delegates standard encodings to the default pool and handles AggrChunk specially.

func NewAggrChunkPool

func NewAggrChunkPool(aggrType AggrType) *AggrChunkPool

NewAggrChunkPool creates a new pool that handles AggrChunk encoding.

func (*AggrChunkPool) Get

Get returns a chunk for the given encoding and data.

func (*AggrChunkPool) Put

func (p *AggrChunkPool) Put(c chunkenc.Chunk) error

Put returns a chunk to the pool.

type AggrChunkWrapper

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

AggrChunkWrapper wraps AggrChunk to implement chunkenc.Chunk interface. It delegates iteration to a specific aggregate type.

func NewAggrChunkWrapper

func NewAggrChunkWrapper(data []byte, aggrType AggrType) *AggrChunkWrapper

NewAggrChunkWrapper creates a new AggrChunk wrapper for the specified aggregate type.

func (*AggrChunkWrapper) Appender

func (c *AggrChunkWrapper) Appender() (chunkenc.Appender, error)

Appender returns an error since AggrChunk is read-only.

func (*AggrChunkWrapper) Bytes

func (c *AggrChunkWrapper) Bytes() []byte

Bytes returns the underlying byte slice.

func (*AggrChunkWrapper) Compact

func (c *AggrChunkWrapper) Compact()

Compact is a no-op for read-only AggrChunk.

func (*AggrChunkWrapper) Encoding

func (c *AggrChunkWrapper) Encoding() chunkenc.Encoding

Encoding returns the AggrChunk encoding.

func (*AggrChunkWrapper) Iterator

Iterator returns an iterator for the specified aggregate type.

func (*AggrChunkWrapper) NumSamples

func (c *AggrChunkWrapper) NumSamples() int

NumSamples returns the number of samples in the aggregate.

func (*AggrChunkWrapper) Reset

func (c *AggrChunkWrapper) Reset(stream []byte)

Reset resets the chunk with new data.

type AggrType

type AggrType uint8

AggrType represents an aggregation type in Thanos downsampled blocks.

const (
	AggrCount AggrType = iota
	AggrSum
	AggrMin
	AggrMax
	AggrCounter
)

Valid aggregation types matching Thanos definitions.

const AggrTypeNone AggrType = 255

AggrTypeNone indicates raw blocks with no aggregation. It is used as a sentinel to distinguish raw block processing from downsampled.

func ParseAggrType

func ParseAggrType(s string) (AggrType, error)

ParseAggrType parses aggregate type from string.

func (AggrType) String

func (t AggrType) String() string

type BlockInfo

type BlockInfo struct {
	Block      tsdb.BlockReader
	Resolution ResolutionLevel
	IsThanos   bool
	// Closer releases the block's resources (file descriptors, mmap).
	// Must be called only after all queriers on this block have been closed.
	Closer io.Closer
}

BlockInfo contains information about a block including Thanos metadata.

func OpenBlocksWithInfo

func OpenBlocksWithInfo(snapshotDir string, aggrType AggrType) ([]BlockInfo, error)

OpenBlocksWithInfo opens all blocks and returns them with their metadata. snapshotDir must be a snapshot directory containing block directories.

type BlockMeta

type BlockMeta struct {
	// Thanos-specific metadata
	Thanos ThanosMeta `json:"thanos,omitempty"`
}

BlockMeta extends Prometheus BlockMeta with Thanos-specific fields.

func ReadBlockMeta

func ReadBlockMeta(blockDir string) (*BlockMeta, error)

ReadBlockMeta reads Thanos-extended block metadata from meta.json.

func (*BlockMeta) IsDownsampled

func (m *BlockMeta) IsDownsampled() bool

IsDownsampled returns true if the block contains downsampled data.

func (*BlockMeta) Resolution

func (m *BlockMeta) Resolution() ResolutionLevel

Resolution returns the block's downsampling resolution.

func (*BlockMeta) ResolutionSuffix

func (m *BlockMeta) ResolutionSuffix() string

ResolutionSuffix returns a suffix string for metric names based on resolution. For example: ":5m" or ":1h" for downsampled data, empty for raw data.

type Client

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

Client reads Thanos snapshot blocks, including downsampled blocks with AggrChunk encoding.

func NewClient

func NewClient(cfg Config) (*Client, error)

NewClient creates a new Thanos snapshot client.

func (*Client) Explore

func (c *Client) Explore(aggrType AggrType) ([]BlockInfo, error)

Explore fetches all available blocks from the snapshot with support for Thanos AggrChunk (downsampled blocks). It opens blocks with a custom pool that can decode AggrChunk encoding (0xff).

func (*Client) Read

func (c *Client) Read(bi BlockInfo) (ClosableSeriesSet, error)

Read reads the given BlockInfo according to configured time and label filters. The returned ClosableSeriesSet automatically closes the underlying querier when fully consumed, but Close() should be called explicitly (e.g., via defer) to handle early returns.

type ClosableSeriesSet

type ClosableSeriesSet interface {
	storage.SeriesSet
	Close()
}

ClosableSeriesSet extends storage.SeriesSet with a Close method for explicit cleanup.

type Config

type Config struct {
	Snapshot string
	Filter   Filter
}

Config contains parameters for reading Thanos snapshots.

type Filter

type Filter struct {
	TimeMin    string
	TimeMax    string
	Label      string
	LabelValue string
}

Filter contains configuration for filtering the timeseries.

type ResolutionLevel

type ResolutionLevel int64

ResolutionLevel represents the downsampling resolution.

const (
	// ResolutionRaw is for raw, non-downsampled data.
	ResolutionRaw ResolutionLevel = 0
	// Resolution5m is for 5-minute downsampled data (300000 ms).
	Resolution5m ResolutionLevel = 300000
	// Resolution1h is for 1-hour downsampled data (3600000 ms).
	Resolution1h ResolutionLevel = 3600000
)

func (ResolutionLevel) String

func (r ResolutionLevel) String() string

String returns human-readable resolution string.

type Stats

type Stats struct {
	Filtered      bool
	MinTime       int64
	MaxTime       int64
	Samples       uint64
	Series        uint64
	Blocks        int
	SkippedBlocks int
}

Stats represents data migration stats for Thanos blocks.

func (Stats) String

func (s Stats) String() string

String returns string representation for s.

type ThanosDownsample

type ThanosDownsample struct {
	// Resolution is the downsampling resolution in milliseconds.
	// 0 means raw data (no downsampling).
	// 300000 (5 minutes) or 3600000 (1 hour) for downsampled data.
	Resolution int64 `json:"resolution"`
}

ThanosDownsample contains downsampling resolution info.

type ThanosFile

type ThanosFile struct {
	RelPath   string `json:"rel_path"`
	SizeBytes int64  `json:"size_bytes,omitempty"`
}

ThanosFile contains metadata about a file in the block.

type ThanosMeta

type ThanosMeta struct {
	// Labels are external labels identifying the producer.
	Labels map[string]string `json:"labels,omitempty"`

	// Downsample contains downsampling information.
	Downsample ThanosDownsample `json:"downsample,omitempty"`

	// Source indicates where the block came from.
	Source string `json:"source,omitempty"`

	// SegmentFiles contains list of segment files in the block.
	SegmentFiles []string `json:"segment_files,omitempty"`

	// Files contains metadata about files in the block.
	Files []ThanosFile `json:"files,omitempty"`
}

ThanosMeta contains Thanos-specific block metadata.

Jump to

Keyboard shortcuts

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