Documentation
¶
Index ¶
- Variables
- func ChainSampleIteratorFromIterables(it chunkenc.Iterator, iterables []chunkenc.Iterable) chunkenc.Iterator
- func ChainSampleIteratorFromIterators(it chunkenc.Iterator, iterators []chunkenc.Iterator) chunkenc.Iterator
- func ChainSampleIteratorFromSeries(it chunkenc.Iterator, series []Series) chunkenc.Iterator
- func ExpandChunks(iter chunks.Iterator) ([]chunks.Meta, error)
- func ExpandSamples(iter chunkenc.Iterator, ...) ([]chunks.Sample, error)
- func NewDuplicateFloatErr(t int64, existing, newValue float64) error
- func NewDuplicateHistogramToFloatErr(t int64, newValue float64) error
- func NewListChunkSeriesIterator(chks ...chunks.Meta) chunks.Iterator
- func NewListSeriesIterator(samples Samples) chunkenc.Iterator
- func NewListSeriesIteratorWithCopy(samples Samples) chunkenc.Iterator
- type AOptions
- type AppendOptions
- type AppendPartialError
- type AppendV2Options
- type Appendable
- type AppendableV2
- type Appender
- type AppenderTransaction
- type AppenderV2
- type BufferedSeriesIterator
- func (b *BufferedSeriesIterator) At() (int64, float64)
- func (b *BufferedSeriesIterator) AtFloatHistogram(fh *histogram.FloatHistogram) (int64, *histogram.FloatHistogram)
- func (b *BufferedSeriesIterator) AtHistogram(fh *histogram.Histogram) (int64, *histogram.Histogram)
- func (b *BufferedSeriesIterator) AtT() int64
- func (b *BufferedSeriesIterator) Buffer() *SampleRingIterator
- func (b *BufferedSeriesIterator) Err() error
- func (b *BufferedSeriesIterator) Next() chunkenc.ValueType
- func (b *BufferedSeriesIterator) PeekBack(n int) (sample chunks.Sample, ok bool)
- func (b *BufferedSeriesIterator) ReduceDelta(delta int64) bool
- func (b *BufferedSeriesIterator) Reset(it chunkenc.Iterator)
- func (b *BufferedSeriesIterator) Seek(t int64) chunkenc.ValueType
- type ChunkIterable
- type ChunkQuerier
- type ChunkQueryable
- type ChunkSeries
- type ChunkSeriesEntry
- type ChunkSeriesSet
- func EmptyChunkSeriesSet() ChunkSeriesSet
- func ErrChunkSeriesSet(err error) ChunkSeriesSet
- func NewMergeChunkSeriesSet(sets []ChunkSeriesSet, limit int, mergeFunc VerticalChunkSeriesMergeFunc) ChunkSeriesSet
- func NewSeriesSetToChunkSet(chk SeriesSet) ChunkSeriesSet
- func NoopChunkedSeriesSet() ChunkSeriesSet
- type ExemplarAppender
- type ExemplarQuerier
- type ExemplarQueryable
- type ExemplarStorage
- type GetRef
- type HistogramAppender
- type LabelHints
- type LabelQuerier
- type Labels
- type LimitedAppenderV1
- type MemoizedSeriesIterator
- func (b *MemoizedSeriesIterator) At() (int64, float64)
- func (b *MemoizedSeriesIterator) AtFloatHistogram() (int64, *histogram.FloatHistogram)
- func (b *MemoizedSeriesIterator) AtT() int64
- func (b *MemoizedSeriesIterator) Err() error
- func (b *MemoizedSeriesIterator) Next() chunkenc.ValueType
- func (b *MemoizedSeriesIterator) PeekPrev() (t int64, v float64, fh *histogram.FloatHistogram, ok bool)
- func (b *MemoizedSeriesIterator) Reset(it chunkenc.Iterator)
- func (b *MemoizedSeriesIterator) Seek(t int64) chunkenc.ValueType
- type MetadataUpdater
- type MockQuerier
- func (*MockQuerier) Close() error
- func (*MockQuerier) LabelNames(context.Context, *LabelHints, ...*labels.Matcher) ([]string, annotations.Annotations, error)
- func (*MockQuerier) LabelValues(context.Context, string, *LabelHints, ...*labels.Matcher) ([]string, annotations.Annotations, error)
- func (q *MockQuerier) Select(_ context.Context, sortSeries bool, hints *SelectHints, ...) SeriesSet
- type MockQueryable
- type Querier
- type Queryable
- type QueryableFunc
- type SampleAndChunkQueryable
- type SampleIterable
- type SampleRingIterator
- func (it *SampleRingIterator) At() (int64, float64)
- func (it *SampleRingIterator) AtFloatHistogram(fh *histogram.FloatHistogram) (int64, *histogram.FloatHistogram)
- func (it *SampleRingIterator) AtHistogram() (int64, *histogram.Histogram)
- func (it *SampleRingIterator) AtT() int64
- func (it *SampleRingIterator) Next() chunkenc.ValueType
- type Samples
- type SelectHints
- type Series
- type SeriesEntry
- type SeriesRef
- type SeriesSet
- func EmptySeriesSet() SeriesSet
- func ErrSeriesSet(err error) SeriesSet
- func NewMergeSeriesSet(sets []SeriesSet, limit int, mergeFunc VerticalSeriesMergeFunc) SeriesSet
- func NewSeriesSetFromChunkSeriesSet(chk ChunkSeriesSet) SeriesSet
- func NoopSeriesSet() SeriesSet
- func TestSeriesSet(series Series) SeriesSet
- type StartTimestampAppender
- type Storage
- type VerticalChunkSeriesMergeFunc
- type VerticalSeriesMergeFunc
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("not found") // ErrOutOfOrderSample is when out of order support is disabled and the sample is out of order. ErrOutOfOrderSample = errors.New("out of order sample") // ErrOutOfBounds is when out of order support is disabled and the sample is older than the min valid time for the append. ErrOutOfBounds = errors.New("out of bounds") // ErrTooOldSample is when out of order support is enabled but the sample is outside the time window allowed. ErrTooOldSample = errors.New("too old sample") // ErrDuplicateSampleForTimestamp is when the sample has same timestamp but different value. ErrDuplicateSampleForTimestamp = errDuplicateSampleForTimestamp{} ErrOutOfOrderExemplar = errors.New("out of order exemplar") ErrDuplicateExemplar = errors.New("duplicate exemplar") ErrExemplarLabelLength = fmt.Errorf("label length for exemplar exceeds maximum of %d UTF-8 characters", exemplar.ExemplarMaxLabelSetLength) ErrExemplarsDisabled = errors.New("exemplar storage is disabled or max exemplars is less than or equal to 0") ErrNativeHistogramsDisabled = errors.New("native histograms are disabled") // ErrOutOfOrderST indicates failed append of ST to the storage // due to ST being older the then newer sample. // NOTE(bwplotka): This can be both an instrumentation failure or commonly expected // behaviour, and we currently don't have a way to determine this. As a result // it's recommended to ignore this error for now. // TODO(bwplotka): Remove with appender v1 flow; not used in v2. ErrOutOfOrderST = errors.New("start timestamp out of order, ignoring") ErrSTNewerThanSample = errors.New("ST is newer or the same as sample's timestamp, ignoring") )
The errors exposed.
Functions ¶
func ChainSampleIteratorFromIterables ¶ added in v0.49.0
func ChainSampleIteratorFromIterators ¶ added in v0.42.0
func ChainSampleIteratorFromSeries ¶ added in v0.42.0
func ExpandChunks ¶
ExpandChunks iterates over all chunks in the iterator, buffering all in slice.
func ExpandSamples ¶
func ExpandSamples(iter chunkenc.Iterator, newSampleFn func(t int64, f float64, h *histogram.Histogram, fh *histogram.FloatHistogram) chunks.Sample) ([]chunks.Sample, error)
ExpandSamples iterates over all samples in the iterator, buffering all in slice. Optionally it takes samples constructor, useful when you want to compare sample slices with different sample implementations. if nil, sample type from this package will be used.
func NewDuplicateFloatErr ¶ added in v0.53.0
func NewDuplicateHistogramToFloatErr ¶ added in v0.55.0
NewDuplicateHistogramToFloatErr describes an error where a new float sample is sent for same timestamp as previous histogram.
func NewListChunkSeriesIterator ¶
NewListChunkSeriesIterator returns listChunkSeriesIterator that allows to iterate over provided chunks.
func NewListSeriesIterator ¶
NewListSeriesIterator returns listSeriesIterator that allows to iterate over provided samples.
func NewListSeriesIteratorWithCopy ¶ added in v0.300.0
Types ¶
type AOptions ¶ added in v0.309.0
type AOptions = AppendV2Options
AOptions is a shorthand for AppendV2Options. NOTE: AppendOption is used already.
type AppendOptions ¶ added in v0.300.0
type AppendOptions struct {
// DiscardOutOfOrder tells implementation that this append should not be out
// of order. An OOO append MUST be rejected with storage.ErrOutOfOrderSample
// error.
DiscardOutOfOrder bool
}
AppendOptions provides options for implementations of the Appender interface.
WARNING: Work AppendableV2 is in progress. Appendable will be removed soon (ETA: Q2 2026).
type AppendPartialError ¶ added in v0.309.0
type AppendPartialError struct {
ExemplarErrors []error
}
AppendPartialError represents an AppenderV2.Append error that tells callers sample was written but some auxiliary optional data (e.g. exemplars) was not (or partially written)
It's up to the caller to decide if it's an ignorable error or not, plus it allows extra reporting (e.g. for Remote Write 2.0 X-Remote-Write-Written headers).
func (*AppendPartialError) Error ¶ added in v0.309.0
func (e *AppendPartialError) Error() string
Error returns combined error string.
type AppendV2Options ¶ added in v0.309.0
type AppendV2Options struct {
// MetricFamilyName (optional) provides metric family name for the appended sample's
// series. If the client of the AppenderV2 has this information
// (e.g. from scrape) it's recommended to pass it to the appender.
//
// Provided string bytes are unsafe to reuse, it only lives for the duration of the Append call.
//
// Some implementations use this to avoid slow and prone to error metric family detection for:
// * Metadata per metric family storages (e.g. Prometheus metadata WAL/API/RW1)
// * Strictly complex types storages (e.g. OpenTelemetry Collector).
//
// NOTE(krajorama): Example purpose is highlighted in OTLP ingestion: OTLP calculates the
// metric family name for all metrics and uses it for generating summary,
// histogram series by adding the magic suffixes. The metric family name is
// passed down to the appender in case the storage needs it for metadata updates.
// Known user of this is Mimir that implements /api/v1/metadata and uses
// Remote-Write 1.0 for this. Might be removed later if no longer
// needed by any downstream project.
// NOTE(bwplotka): Long term, once Prometheus uses complex types on storage level
// the MetricFamilyName can be removed as MetricFamilyName will equal to __name__ always.
MetricFamilyName string
// Metadata (optional) attached to the appended sample.
// Metadata strings are safe for reuse.
// IMPORTANT: Appender v1 was only providing update. This field MUST be
// set (if known) even if it didn't change since the last iteration.
// This moves the responsibility for metadata storage options to TSDB.
Metadata metadata.Metadata
// Exemplars (optional) attached to the appended sample.
// Exemplar slice MUST be sorted by Exemplar.TS.
// Exemplar slice is unsafe for reuse.
Exemplars []exemplar.Exemplar
// RejectOutOfOrder tells implementation that this append should not be out
// of order. An OOO append MUST be rejected with storage.ErrOutOfOrderSample
// error.
RejectOutOfOrder bool
}
AppendV2Options provides optional, auxiliary data and configuration for AppenderV2.Append.
type Appendable ¶
type Appendable interface {
// Appender returns a new appender for the storage.
//
// Implementations CAN choose whether to use the context e.g. for deadlines,
// but it's not mandatory.
Appender(ctx context.Context) Appender
}
Appendable allows creating Appender.
WARNING: Work AppendableV2 is in progress. Appendable will be removed soon (ETA: Q2 2026).
type AppendableV2 ¶ added in v0.309.0
type AppendableV2 interface {
// AppenderV2 returns a new appender for the storage.
//
// Implementations CAN choose whether to use the context e.g. for deadlines,
// but it's not mandatory.
AppenderV2(ctx context.Context) AppenderV2
}
AppendableV2 allows creating AppenderV2.
type Appender ¶
type Appender interface {
AppenderTransaction
// Append adds a sample pair for the given series.
// An optional series reference can be provided to accelerate calls.
// A series reference number is returned which can be used to add further
// samples to the given series in the same or later transactions.
// Returned reference numbers are ephemeral and may be rejected in calls
// to Append() at any point. Adding the sample via Append() returns a new
// reference number.
// If the reference is 0 it must not be used for caching.
Append(ref SeriesRef, l labels.Labels, t int64, v float64) (SeriesRef, error)
// SetOptions configures the appender with specific append options such as
// discarding out-of-order samples even if out-of-order is enabled in the TSDB.
SetOptions(opts *AppendOptions)
ExemplarAppender
HistogramAppender
MetadataUpdater
StartTimestampAppender
}
Appender provides batched appends against a storage. It must be completed with a call to Commit or Rollback and must not be reused afterwards.
Operations on the Appender interface are not goroutine-safe.
The order of samples appended via the Appender is preserved within each series. I.e. timestamp order within batch is not validated, samples are not reordered per timestamp or by float/histogram type.
WARNING: Work AppendableV2 is in progress. Appendable will be removed soon (ETA: Q2 2026).
type AppenderTransaction ¶ added in v0.309.0
type AppenderTransaction interface {
// Commit submits the collected samples and purges the batch. If Commit
// returns a non-nil error, it also rolls back all modifications made in
// the appender so far, as Rollback would do. In any case, an Appender
// must not be used anymore after Commit has been called.
Commit() error
// Rollback rolls back all modifications made in the appender so far.
// Appender has to be discarded after rollback.
Rollback() error
}
AppenderTransaction allows transactional appends.
type AppenderV2 ¶ added in v0.309.0
type AppenderV2 interface {
AppenderTransaction
// Append appends a sample and related exemplars, metadata, and start timestamp (st) to the storage.
//
// ref (optional) represents the stable ID for the given series identified by ls (excluding metadata).
// Callers MAY provide the ref to help implementation avoid ls -> ref computation, otherwise ref MUST be 0 (unknown).
//
// ls represents labels for the sample's series.
//
// st (optional) represents sample start timestamp. 0 means unknown. Implementations
// are responsible for any potential ST storage logic (e.g. ST zero injections).
//
// t represents sample timestamp.
//
// v, h, fh represents sample value for each sample type.
// Callers MUST only provide one of the sample types (either v, h or fh).
// Implementations can detect the type of the sample with the following switch:
//
// switch {
// case fh != nil: It's a float histogram append.
// case h != nil: It's a histogram append.
// default: It's a float append.
// }
// TODO(bwplotka): We plan to experiment on using generics for complex sampleType, but do it after we unify interface (derisk) and before we add native summaries.
//
// Implementations MUST attempt to append sample even if metadata, exemplar or (st) start timestamp appends fail.
// Implementations MAY return AppendPartialError as an error. Use errors.As to detect.
// For the successful Append, Implementations MUST return valid SeriesRef that represents ls.
// NOTE(bwplotka): Given OTLP and native histograms and the relaxation of the requirement for
// type and unit suffixes in metric names we start to hit cases of ls being not enough for id
// of the series (metadata matters). Current solution is to enable 'type-and-unit-label' features for those cases, but we may
// start to extend the id with metadata one day.
Append(ref SeriesRef, ls labels.Labels, st, t int64, v float64, h *histogram.Histogram, fh *histogram.FloatHistogram, opts AppendV2Options) (SeriesRef, error)
}
AppenderV2 provides appends against a storage for all types of samples. It must be completed with a call to Commit or Rollback and must not be reused afterwards.
Operations on the AppenderV2 interface are not goroutine-safe.
The order of samples appended via the AppenderV2 is preserved within each series. I.e. timestamp order within batch is not validated, samples are not reordered per timestamp or by float/histogram type.
type BufferedSeriesIterator ¶
type BufferedSeriesIterator struct {
// contains filtered or unexported fields
}
BufferedSeriesIterator wraps an iterator with a look-back buffer.
func NewBuffer ¶
func NewBuffer(delta int64) *BufferedSeriesIterator
NewBuffer returns a new iterator that buffers the values within the time range of the current element and the duration of delta before, initialized with an empty iterator. Use Reset() to set an actual iterator to be buffered.
func NewBufferIterator ¶
func NewBufferIterator(it chunkenc.Iterator, delta int64) *BufferedSeriesIterator
NewBufferIterator returns a new iterator that buffers the values within the time range of the current element and the duration of delta before.
func (*BufferedSeriesIterator) At ¶
func (b *BufferedSeriesIterator) At() (int64, float64)
At returns the current float element of the iterator.
func (*BufferedSeriesIterator) AtFloatHistogram ¶ added in v0.40.0
func (b *BufferedSeriesIterator) AtFloatHistogram(fh *histogram.FloatHistogram) (int64, *histogram.FloatHistogram)
AtFloatHistogram returns the current float-histogram element of the iterator.
func (*BufferedSeriesIterator) AtHistogram ¶ added in v0.40.0
AtHistogram returns the current histogram element of the iterator.
func (*BufferedSeriesIterator) AtT ¶ added in v0.40.0
func (b *BufferedSeriesIterator) AtT() int64
AtT returns the current timestamp of the iterator.
func (*BufferedSeriesIterator) Buffer ¶
func (b *BufferedSeriesIterator) Buffer() *SampleRingIterator
Buffer returns an iterator over the buffered data. Invalidates previously returned iterators.
func (*BufferedSeriesIterator) Err ¶
func (b *BufferedSeriesIterator) Err() error
Err returns the last encountered error.
func (*BufferedSeriesIterator) Next ¶
func (b *BufferedSeriesIterator) Next() chunkenc.ValueType
Next advances the iterator to the next element.
func (*BufferedSeriesIterator) PeekBack ¶
func (b *BufferedSeriesIterator) PeekBack(n int) (sample chunks.Sample, ok bool)
PeekBack returns the nth previous element of the iterator. If there is none buffered, ok is false.
func (*BufferedSeriesIterator) ReduceDelta ¶
func (b *BufferedSeriesIterator) ReduceDelta(delta int64) bool
ReduceDelta lowers the buffered time delta, for the current SeriesIterator only.
func (*BufferedSeriesIterator) Reset ¶
func (b *BufferedSeriesIterator) Reset(it chunkenc.Iterator)
Reset re-uses the buffer with a new iterator, resetting the buffered time delta to its original value.
type ChunkIterable ¶
type ChunkQuerier ¶
type ChunkQuerier interface {
LabelQuerier
// Select returns a set of series that matches the given label matchers.
// Results are not checked whether they match. Results that do not match
// may cause undefined behavior.
// Caller can specify if it requires returned series to be sorted. Prefer not requiring sorting for better performance.
// It allows passing hints that can help in optimising select, but it's up to implementation how this is used if used at all.
Select(ctx context.Context, sortSeries bool, hints *SelectHints, matchers ...*labels.Matcher) ChunkSeriesSet
}
ChunkQuerier provides querying access over time series data of a fixed time range.
func NewMergeChunkQuerier ¶
func NewMergeChunkQuerier(primaries, secondaries []ChunkQuerier, mergeFn VerticalChunkSeriesMergeFunc) ChunkQuerier
NewMergeChunkQuerier returns a new Chunk Querier that merges results of given primary and secondary chunk queriers. See NewFanout commentary to learn more about primary vs secondary differences.
In case of overlaps between the data given by primaries' and secondaries' Selects, merge function will be used. TODO(bwplotka): Currently merge will compact overlapping chunks with bigger chunk, without limit. Split it: https://github.com/prometheus/tsdb/issues/670
func NoopChunkedQuerier ¶
func NoopChunkedQuerier() ChunkQuerier
NoopChunkedQuerier is a ChunkQuerier that does nothing.
type ChunkQueryable ¶
type ChunkQueryable interface {
// ChunkQuerier returns a new ChunkQuerier on the storage.
ChunkQuerier(mint, maxt int64) (ChunkQuerier, error)
}
A ChunkQueryable handles queries against a storage. Use it when you need to have access to samples in encoded format.
type ChunkSeries ¶
type ChunkSeries interface {
Labels
ChunkIterable
}
ChunkSeries exposes a single time series and allows iterating over chunks.
func NewSeriesToChunkEncoder ¶
func NewSeriesToChunkEncoder(series Series) ChunkSeries
NewSeriesToChunkEncoder encodes samples to chunks with 120 samples limit.
type ChunkSeriesEntry ¶
type ChunkSeriesEntry struct {
Lset labels.Labels
ChunkIteratorFn func(chunks.Iterator) chunks.Iterator
}
func NewListChunkSeriesFromSamples ¶
func NewListChunkSeriesFromSamples(lset labels.Labels, samples ...[]chunks.Sample) *ChunkSeriesEntry
NewListChunkSeriesFromSamples returns a chunk series entry that allows to iterate over provided samples. NOTE: It uses an inefficient chunks encoding implementation, not caring about chunk size. Use only for testing.
func (*ChunkSeriesEntry) Iterator ¶
func (s *ChunkSeriesEntry) Iterator(it chunks.Iterator) chunks.Iterator
func (*ChunkSeriesEntry) Labels ¶
func (s *ChunkSeriesEntry) Labels() labels.Labels
type ChunkSeriesSet ¶
type ChunkSeriesSet interface {
Next() bool
// At returns full chunk series. Returned series should be iterable even after Next is called.
At() ChunkSeries
// The error that iteration has failed with.
// When an error occurs, set cannot continue to iterate.
Err() error
// A collection of warnings for the whole set.
// Warnings could be return even iteration has not failed with error.
Warnings() annotations.Annotations
}
ChunkSeriesSet contains a set of chunked series.
func EmptyChunkSeriesSet ¶
func EmptyChunkSeriesSet() ChunkSeriesSet
EmptyChunkSeriesSet returns a chunk series set that's always empty.
func ErrChunkSeriesSet ¶
func ErrChunkSeriesSet(err error) ChunkSeriesSet
ErrChunkSeriesSet returns a chunk series set that wraps an error.
func NewMergeChunkSeriesSet ¶
func NewMergeChunkSeriesSet(sets []ChunkSeriesSet, limit int, mergeFunc VerticalChunkSeriesMergeFunc) ChunkSeriesSet
NewMergeChunkSeriesSet returns a new ChunkSeriesSet that merges many SeriesSet together.
func NewSeriesSetToChunkSet ¶
func NewSeriesSetToChunkSet(chk SeriesSet) ChunkSeriesSet
NewSeriesSetToChunkSet converts SeriesSet to ChunkSeriesSet by encoding chunks from samples.
func NoopChunkedSeriesSet ¶
func NoopChunkedSeriesSet() ChunkSeriesSet
NoopChunkedSeriesSet is a ChunkSeriesSet that does nothing.
type ExemplarAppender ¶
type ExemplarAppender interface {
// AppendExemplar adds an exemplar for the given series labels.
// An optional reference number can be provided to accelerate calls.
// A reference number is returned which can be used to add further
// exemplars in the same or later transactions.
// Returned reference numbers are ephemeral and may be rejected in calls
// to Append() at any point. Adding the sample via Append() returns a new
// reference number.
// If the reference is 0 it must not be used for caching.
// Note that in our current implementation of Prometheus' exemplar storage
// calls to Append should generate the reference numbers, AppendExemplar
// generating a new reference number should be considered possible erroneous behaviour and be logged.
AppendExemplar(ref SeriesRef, l labels.Labels, e exemplar.Exemplar) (SeriesRef, error)
}
ExemplarAppender provides an interface for adding samples to exemplar storage, which within Prometheus is in-memory only.
WARNING: Work AppendableV2 is in progress. Appendable will be removed soon (ETA: Q2 2026).
type ExemplarQuerier ¶
type ExemplarQuerier interface {
// Select all the exemplars that match the matchers.
// Within a single slice of matchers, it is an intersection. Between the slices, it is a union.
Select(start, end int64, matchers ...[]*labels.Matcher) ([]exemplar.QueryResult, error)
}
ExemplarQuerier provides reading access to time series data.
type ExemplarQueryable ¶
type ExemplarQueryable interface {
// ExemplarQuerier returns a new ExemplarQuerier on the storage.
ExemplarQuerier(ctx context.Context) (ExemplarQuerier, error)
}
type ExemplarStorage ¶
type ExemplarStorage interface {
ExemplarQueryable
ExemplarAppender
}
ExemplarStorage ingests and manages exemplars, along with various indexes. All methods are goroutine-safe. ExemplarStorage implements storage.ExemplarAppender and storage.ExemplarQuerier.
type GetRef ¶
type GetRef interface {
// GetRef returns a reference number that can be used to pass to AppenderV2.Append(),
// and a set of labels that will not cause another copy when passed to AppenderV2.Append().
// 0 means the appender does not have a reference to this series.
// hash should be a hash of lset.
GetRef(lset labels.Labels, hash uint64) (SeriesRef, labels.Labels)
}
GetRef is an extra interface on Appenders used by downstream projects (e.g. Cortex) to avoid maintaining a parallel set of references.
type HistogramAppender ¶ added in v0.40.0
type HistogramAppender interface {
// AppendHistogram adds a histogram for the given series labels. An
// optional reference number can be provided to accelerate calls. A
// reference number is returned which can be used to add further
// histograms in the same or later transactions. Returned reference
// numbers are ephemeral and may be rejected in calls to Append() at any
// point. Adding the sample via Append() returns a new reference number.
// If the reference is 0, it must not be used for caching.
//
// For efficiency reasons, the histogram is passed as a
// pointer. AppendHistogram won't mutate the histogram, but in turn
// depends on the caller to not mutate it either.
AppendHistogram(ref SeriesRef, l labels.Labels, t int64, h *histogram.Histogram, fh *histogram.FloatHistogram) (SeriesRef, error)
// AppendHistogramSTZeroSample adds synthetic zero sample for the given st timestamp,
// which will be associated with given series, labels and the incoming
// sample's t (timestamp). AppendHistogramSTZeroSample returns error if zero sample can't be
// appended, for example when st is too old, or when it would collide with
// incoming sample (sample has priority).
//
// AppendHistogramSTZeroSample has to be called before the corresponding histogram AppendHistogram.
// A series reference number is returned which can be used to modify the
// ST for the given series in the same or later transactions.
// Returned reference numbers are ephemeral and may be rejected in calls
// to AppendHistogramSTZeroSample() at any point.
//
// If the reference is 0 it must not be used for caching.
AppendHistogramSTZeroSample(ref SeriesRef, l labels.Labels, t, st int64, h *histogram.Histogram, fh *histogram.FloatHistogram) (SeriesRef, error)
}
HistogramAppender provides an interface for appending histograms to the storage.
WARNING: Work AppendableV2 is in progress. Appendable will be removed soon (ETA: Q2 2026).
type LabelHints ¶ added in v0.54.0
type LabelHints struct {
// Maximum number of results returned. Use a value of 0 to disable.
Limit int
}
LabelHints specifies hints passed for label reads. This is used only as an option for implementation to use.
type LabelQuerier ¶
type LabelQuerier interface {
// LabelValues returns all potential values for a label name in sorted order.
// It is not safe to use the strings beyond the lifetime of the querier.
// If matchers are specified the returned result set is reduced
// to label values of metrics matching the matchers.
LabelValues(ctx context.Context, name string, hints *LabelHints, matchers ...*labels.Matcher) ([]string, annotations.Annotations, error)
// LabelNames returns all the unique label names present in the block in sorted order.
// If matchers are specified the returned result set is reduced
// to label names of metrics matching the matchers.
LabelNames(ctx context.Context, hints *LabelHints, matchers ...*labels.Matcher) ([]string, annotations.Annotations, error)
// Close releases the resources of the Querier.
Close() error
}
LabelQuerier provides querying access over labels.
type Labels ¶
type Labels interface {
// Labels returns the complete set of labels. For series it means all labels identifying the series.
Labels() labels.Labels
}
Labels represents an item that has labels e.g. time series.
type LimitedAppenderV1 ¶ added in v0.309.0
type LimitedAppenderV1 interface {
Append(ref SeriesRef, l labels.Labels, t int64, v float64) (SeriesRef, error)
AppendHistogram(ref SeriesRef, l labels.Labels, t int64, h *histogram.Histogram, fh *histogram.FloatHistogram) (SeriesRef, error)
}
LimitedAppenderV1 is an Appender that only supports appending float and histogram samples. This is to support migration to AppenderV2. TODO(bwplotka): Remove once migration to AppenderV2 is fully complete.
func AppenderV2AsLimitedV1 ¶ added in v0.309.0
func AppenderV2AsLimitedV1(app AppenderV2) LimitedAppenderV1
AppenderV2AsLimitedV1 returns appender that exposes AppenderV2 as LimitedAppenderV1 TODO(bwplotka): Remove once migration to AppenderV2 is fully complete.
type MemoizedSeriesIterator ¶
type MemoizedSeriesIterator struct {
// contains filtered or unexported fields
}
MemoizedSeriesIterator wraps an iterator with a buffer to look back the previous element.
This iterator regards integer histograms as float histograms; calls to Seek() will never return chunkenc.Histogram. This iterator deliberately does not implement chunkenc.Iterator.
func NewMemoizedEmptyIterator ¶
func NewMemoizedEmptyIterator(delta int64) *MemoizedSeriesIterator
NewMemoizedEmptyIterator is like NewMemoizedIterator but it's initialised with an empty iterator.
func NewMemoizedIterator ¶
func NewMemoizedIterator(it chunkenc.Iterator, delta int64) *MemoizedSeriesIterator
NewMemoizedIterator returns a new iterator that buffers the values within the time range of the current element and the duration of delta before.
func (*MemoizedSeriesIterator) At ¶
func (b *MemoizedSeriesIterator) At() (int64, float64)
At returns the current float element of the iterator.
func (*MemoizedSeriesIterator) AtFloatHistogram ¶ added in v0.40.0
func (b *MemoizedSeriesIterator) AtFloatHistogram() (int64, *histogram.FloatHistogram)
AtFloatHistogram returns the current float-histogram element of the iterator.
func (*MemoizedSeriesIterator) AtT ¶ added in v0.40.0
func (b *MemoizedSeriesIterator) AtT() int64
AtT returns the timestamp of the current element of the iterator.
func (*MemoizedSeriesIterator) Err ¶
func (b *MemoizedSeriesIterator) Err() error
Err returns the last encountered error.
func (*MemoizedSeriesIterator) Next ¶
func (b *MemoizedSeriesIterator) Next() chunkenc.ValueType
Next advances the iterator to the next element. Note that this does not check whether the element being buffered is within the time range of the current element and the duration of delta before.
func (*MemoizedSeriesIterator) PeekPrev ¶
func (b *MemoizedSeriesIterator) PeekPrev() (t int64, v float64, fh *histogram.FloatHistogram, ok bool)
PeekPrev returns the previous element of the iterator. If there is none buffered, ok is false.
func (*MemoizedSeriesIterator) Reset ¶
func (b *MemoizedSeriesIterator) Reset(it chunkenc.Iterator)
Reset the internal state to reuse the wrapper with the provided iterator.
type MetadataUpdater ¶ added in v0.38.0
type MetadataUpdater interface {
// UpdateMetadata updates a metadata entry for the given series and labels.
// A series reference number is returned which can be used to modify the
// metadata of the given series in the same or later transactions.
// Returned reference numbers are ephemeral and may be rejected in calls
// to UpdateMetadata() at any point. If the series does not exist,
// UpdateMetadata returns an error.
// If the reference is 0 it must not be used for caching.
UpdateMetadata(ref SeriesRef, l labels.Labels, m metadata.Metadata) (SeriesRef, error)
}
MetadataUpdater provides an interface for associating metadata to stored series.
WARNING: Work AppendableV2 is in progress. Appendable will be removed soon (ETA: Q2 2026).
type MockQuerier ¶
type MockQuerier struct {
SelectMockFunction func(sortSeries bool, hints *SelectHints, matchers ...*labels.Matcher) SeriesSet
}
MockQuerier is used for test purposes to mock the selected series that is returned.
func (*MockQuerier) Close ¶
func (*MockQuerier) Close() error
func (*MockQuerier) LabelNames ¶
func (*MockQuerier) LabelNames(context.Context, *LabelHints, ...*labels.Matcher) ([]string, annotations.Annotations, error)
func (*MockQuerier) LabelValues ¶
func (*MockQuerier) LabelValues(context.Context, string, *LabelHints, ...*labels.Matcher) ([]string, annotations.Annotations, error)
func (*MockQuerier) Select ¶
func (q *MockQuerier) Select(_ context.Context, sortSeries bool, hints *SelectHints, matchers ...*labels.Matcher) SeriesSet
type MockQueryable ¶
type MockQueryable struct {
MockQuerier Querier
}
A MockQueryable is used for testing purposes so that a mock Querier can be used.
type Querier ¶
type Querier interface {
LabelQuerier
// Select returns a set of series that matches the given label matchers.
// Results are not checked whether they match. Results that do not match
// may cause undefined behavior.
// Caller can specify if it requires returned series to be sorted. Prefer not requiring sorting for better performance.
// It allows passing hints that can help in optimising select, but it's up to implementation how this is used if used at all.
Select(ctx context.Context, sortSeries bool, hints *SelectHints, matchers ...*labels.Matcher) SeriesSet
}
Querier provides querying access over time series data of a fixed time range.
func NewMergeQuerier ¶
func NewMergeQuerier(primaries, secondaries []Querier, mergeFn VerticalSeriesMergeFunc) Querier
NewMergeQuerier returns a new Querier that merges results of given primary and secondary queriers. See NewFanout commentary to learn more about primary vs secondary differences.
In case of overlaps between the data given by primaries' and secondaries' Selects, merge function will be used.
type Queryable ¶
type Queryable interface {
// Querier returns a new Querier on the storage.
Querier(mint, maxt int64) (Querier, error)
}
A Queryable handles queries against a storage. Use it when you need to have access to all samples without chunk encoding abstraction e.g promQL.
type QueryableFunc ¶
QueryableFunc is an adapter to allow the use of ordinary functions as Queryables. It follows the idea of http.HandlerFunc. TODO(bwplotka): Move to promql/engine_test.go?
type SampleAndChunkQueryable ¶
type SampleAndChunkQueryable interface {
Queryable
ChunkQueryable
}
SampleAndChunkQueryable allows retrieving samples as well as encoded samples in form of chunks.
type SampleIterable ¶
type SampleRingIterator ¶ added in v0.50.0
type SampleRingIterator struct {
// contains filtered or unexported fields
}
SampleRingIterator is returned by BufferedSeriesIterator.Buffer() and can be used to iterate samples buffered in the lookback window.
func (*SampleRingIterator) At ¶ added in v0.50.0
func (it *SampleRingIterator) At() (int64, float64)
At returns the current float element of the iterator.
func (*SampleRingIterator) AtFloatHistogram ¶ added in v0.50.0
func (it *SampleRingIterator) AtFloatHistogram(fh *histogram.FloatHistogram) (int64, *histogram.FloatHistogram)
AtFloatHistogram returns the current histogram element of the iterator. If the current sample is an integer histogram, it will be converted to a float histogram. An optional histogram.FloatHistogram can be provided to avoid allocating a new object for the conversion.
func (*SampleRingIterator) AtHistogram ¶ added in v0.50.0
func (it *SampleRingIterator) AtHistogram() (int64, *histogram.Histogram)
AtHistogram returns the current histogram element of the iterator.
func (*SampleRingIterator) AtT ¶ added in v0.50.0
func (it *SampleRingIterator) AtT() int64
func (*SampleRingIterator) Next ¶ added in v0.50.0
func (it *SampleRingIterator) Next() chunkenc.ValueType
type Samples ¶
Samples interface allows to work on arrays of types that are compatible with chunks.Sample.
type SelectHints ¶
type SelectHints struct {
Start int64 // Start time in milliseconds for this select.
End int64 // End time in milliseconds for this select.
// Maximum number of results returned. Use a value of 0 to disable.
Limit int
Step int64 // Query step size in milliseconds.
Func string // String representation of surrounding function or aggregation.
Grouping []string // List of label names used in aggregation.
By bool // Indicate whether it is without or by.
Range int64 // Range vector selector range in milliseconds.
// ShardCount is the total number of shards that series should be split into
// at query time. Then, only series in the ShardIndex shard will be returned
// by the query.
//
// ShardCount equal to 0 means that sharding is disabled.
ShardCount uint64
// ShardIndex is the series shard index to query. The index must be between 0 and ShardCount-1.
// When ShardCount is set to a value > 0, then a query will only process series within the
// ShardIndex's shard.
//
// Series are sharded by "labels stable hash" mod "ShardCount".
ShardIndex uint64
// DisableTrimming allows to disable trimming of matching series chunks based on query Start and End time.
// When disabled, the result may contain samples outside the queried time range but Select() performances
// may be improved.
DisableTrimming bool
// ProjectionLabels are the minimum amount of labels required to be fetched for this Select call
// When honored it is required to add an __series_hash__ label containing the hash of all labels
// of a particular series so that the engine can still perform horizontal joins.
ProjectionLabels []string
// ProjectionInclude defines if we have to include or exclude the labels from the ProjectLabels field.
ProjectionInclude bool
}
SelectHints specifies hints passed for data selections. This is used only as an option for implementation to use.
type Series ¶
type Series interface {
Labels
SampleIterable
}
Series exposes a single time series and allows iterating over samples.
func ChainedSeriesMerge ¶
ChainedSeriesMerge returns single series from many same, potentially overlapping series by chaining samples together. If one or more samples overlap, one sample from random overlapped ones is kept and all others with the same timestamp are dropped.
This works the best with replicated series, where data from two series are exactly the same. This does not work well with "almost" the same data, e.g. from 2 Prometheus HA replicas. This is fine, since from the Prometheus perspective this never happens.
It's optimized for non-overlap cases as well.
type SeriesEntry ¶
type SeriesEntry struct {
Lset labels.Labels
SampleIteratorFn func(chunkenc.Iterator) chunkenc.Iterator
}
func NewListSeries ¶
func NewListSeries(lset labels.Labels, s []chunks.Sample) *SeriesEntry
NewListSeries returns series entry with iterator that allows to iterate over provided samples.
func (*SeriesEntry) Iterator ¶
func (s *SeriesEntry) Iterator(it chunkenc.Iterator) chunkenc.Iterator
func (*SeriesEntry) Labels ¶
func (s *SeriesEntry) Labels() labels.Labels
type SeriesRef ¶
type SeriesRef uint64
SeriesRef is a generic series reference. In prometheus it is either a HeadSeriesRef or BlockSeriesRef, though other implementations may have their own reference types.
type SeriesSet ¶
type SeriesSet interface {
Next() bool
// At returns full series. Returned series should be iterable even after Next is called.
At() Series
// Err returns the error that iteration has failed with.
// When an error occurs, set cannot continue to iterate.
Err() error
// Warnings returns a collection of warnings for the whole set.
// Warnings could be return even iteration has not failed with error.
Warnings() annotations.Annotations
}
SeriesSet contains a set of series.
func EmptySeriesSet ¶
func EmptySeriesSet() SeriesSet
EmptySeriesSet returns a series set that's always empty.
func ErrSeriesSet ¶
ErrSeriesSet returns a series set that wraps an error.
func NewMergeSeriesSet ¶
func NewMergeSeriesSet(sets []SeriesSet, limit int, mergeFunc VerticalSeriesMergeFunc) SeriesSet
NewMergeSeriesSet returns a new SeriesSet that merges many SeriesSets together. If limit is set, the SeriesSet will be limited up-to the limit. 0 means disabled.
func NewSeriesSetFromChunkSeriesSet ¶
func NewSeriesSetFromChunkSeriesSet(chk ChunkSeriesSet) SeriesSet
NewSeriesSetFromChunkSeriesSet converts ChunkSeriesSet to SeriesSet by decoding chunks one by one.
func TestSeriesSet ¶
TestSeriesSet returns a mock series set.
type StartTimestampAppender ¶ added in v0.309.0
type StartTimestampAppender interface {
// AppendSTZeroSample adds synthetic zero sample for the given st timestamp,
// which will be associated with given series, labels and the incoming
// sample's t (timestamp). AppendSTZeroSample returns error if zero sample can't be
// appended, for example when st is too old, or when it would collide with
// incoming sample (sample has priority).
//
// AppendSTZeroSample has to be called before the corresponding sample Append.
// A series reference number is returned which can be used to modify the
// ST for the given series in the same or later transactions.
// Returned reference numbers are ephemeral and may be rejected in calls
// to AppendSTZeroSample() at any point.
//
// If the reference is 0 it must not be used for caching.
AppendSTZeroSample(ref SeriesRef, l labels.Labels, t, st int64) (SeriesRef, error)
}
StartTimestampAppender provides an interface for appending ST to storage.
WARNING: Work AppendableV2 is in progress. Appendable will be removed soon (ETA: Q2 2026).
type Storage ¶
type Storage interface {
SampleAndChunkQueryable
Appendable
// StartTime returns the oldest timestamp stored in the storage.
StartTime() (int64, error)
// Close closes the storage and all its underlying resources.
Close() error
}
Storage ingests and manages samples, along with various indexes. All methods are goroutine-safe. Storage implements storage.Appender.
func NewFanout ¶
NewFanout returns a new fanout Storage, which proxies reads and writes through to multiple underlying storages.
The difference between primary and secondary Storage is only for read (Querier) path and it goes as follows: * If the primary querier returns an error, then any of the Querier operations will fail. * If any secondary querier returns an error the result from that queries is discarded. The overall operation will succeed, and the error from the secondary querier will be returned as a warning.
NOTE: In the case of Prometheus, it treats all remote storages as secondary / best effort.
type VerticalChunkSeriesMergeFunc ¶
type VerticalChunkSeriesMergeFunc func(...ChunkSeries) ChunkSeries
VerticalChunkSeriesMergeFunc returns merged chunk series implementation that merges potentially time-overlapping chunk series with the same labels into single ChunkSeries.
NOTE: It's up to implementation how series are vertically merged (if chunks are sorted, re-encoded etc).
func NewCompactingChunkSeriesMerger ¶
func NewCompactingChunkSeriesMerger(mergeFunc VerticalSeriesMergeFunc) VerticalChunkSeriesMergeFunc
NewCompactingChunkSeriesMerger returns VerticalChunkSeriesMergeFunc that merges the same chunk series into single chunk series. In case of the chunk overlaps, it compacts those into one or more time-ordered non-overlapping chunks with merged data. Samples from overlapped chunks are merged using series vertical merge func. It expects the same labels for each given series.
NOTE: Use the returned merge function only when you see potentially overlapping series, as this introduces small a overhead to handle overlaps between series.
func NewConcatenatingChunkSeriesMerger ¶ added in v0.39.0
func NewConcatenatingChunkSeriesMerger() VerticalChunkSeriesMergeFunc
NewConcatenatingChunkSeriesMerger returns a VerticalChunkSeriesMergeFunc that simply concatenates the chunks from the series. The resultant stream of chunks for a series might be overlapping and unsorted.
type VerticalSeriesMergeFunc ¶
VerticalSeriesMergeFunc returns merged series implementation that merges series with same labels together. It has to handle time-overlapped series as well.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
googleiam
Package googleiam provides an http.RoundTripper that attaches an Google Cloud accessToken to remote write requests.
|
Package googleiam provides an http.RoundTripper that attaches an Google Cloud accessToken to remote write requests. |
|
otlptranslator/prometheusremotewrite
TODO(krajorama): rename this package to otlpappender or similar, as it is not specific to Prometheus remote write anymore.
|
TODO(krajorama): rename this package to otlpappender or similar, as it is not specific to Prometheus remote write anymore. |