Documentation
¶
Overview ¶
Package simple_storage provides an in-memory time series storage implementation for PromQL.
Index ¶
- Constants
- func OpenMaybeCompressed(path string) (io.ReadCloser, error)
- type AtomicWriteCloser
- type MetricSample
- type SaveOptions
- type SimpleIterator
- func (it *SimpleIterator) At() (int64, float64)
- func (it *SimpleIterator) AtFloatHistogram(*histogram.FloatHistogram) (int64, *histogram.FloatHistogram)
- func (it *SimpleIterator) AtHistogram(*histogram.Histogram) (int64, *histogram.Histogram)
- func (it *SimpleIterator) AtST() int64
- func (it *SimpleIterator) AtT() int64
- func (it *SimpleIterator) Err() error
- func (it *SimpleIterator) Next() chunkenc.ValueType
- func (it *SimpleIterator) Seek(t int64) chunkenc.ValueType
- type SimpleQuerier
- func (q *SimpleQuerier) Close() error
- func (q *SimpleQuerier) LabelNames(_ context.Context, hints *storage.LabelHints, matchers ...*labels.Matcher) ([]string, annotations.Annotations, error)
- func (q *SimpleQuerier) LabelValues(_ context.Context, name string, hints *storage.LabelHints, ...) ([]string, annotations.Annotations, error)
- func (q *SimpleQuerier) Select(_ context.Context, sortSeries bool, hints *storage.SelectHints, ...) storage.SeriesSet
- type SimpleSeries
- type SimpleSeriesSet
- type SimpleStorage
- func (s *SimpleStorage) AddSample(labels map[string]string, value float64, timestampMillis int64)
- func (s *SimpleStorage) LatestTimestamp(re *regexp.Regexp) (int64, bool)
- func (s *SimpleStorage) LoadFromReader(reader io.Reader) error
- func (s *SimpleStorage) LoadFromReaderWithFilter(reader io.Reader, filter func(name string) bool) error
- func (s *SimpleStorage) Querier(mint, maxt int64) (storage.Querier, error)
- func (s *SimpleStorage) RenameMetric(oldName, newName string) error
- func (s *SimpleStorage) SaveToWriter(w io.Writer) error
- func (s *SimpleStorage) SaveToWriterWithOptions(w io.Writer, opts SaveOptions) error
Constants ¶
const SampleMetrics = `` /* 289-byte string literal not displayed */
SampleMetrics provides a small Prometheus exposition set with a counter and a gauge.
Variables ¶
This section is empty.
Functions ¶
func OpenMaybeCompressed ¶ added in v0.6.5
func OpenMaybeCompressed(path string) (io.ReadCloser, error)
OpenMaybeCompressed opens path for reading and transparently decompresses gzip or zstd content. The format is detected from the leading magic bytes, never from the file name; anything else is returned as plain text. Closing the result closes the decompressor and the file.
Types ¶
type AtomicWriteCloser ¶ added in v0.6.5
type AtomicWriteCloser interface {
io.WriteCloser
Abort()
}
AtomicWriteCloser writes to a temporary file next to its target. Close flushes and renames it into place only if everything succeeded, so a failed save never replaces a previous good file; Abort discards it.
func CreateMaybeCompressed ¶ added in v0.6.5
func CreateMaybeCompressed(path string) (AtomicWriteCloser, error)
CreateMaybeCompressed opens path for an atomic write, compressing by its extension: .gz gzip, .zst/.zstd zstd, anything else plain text. Data goes to a temporary file in the same directory; the caller must Close the result and check the error (the file only appears at path then), or Abort it.
type MetricSample ¶
MetricSample represents a single metric sample
type SaveOptions ¶
type SaveOptions struct {
// TimestampMode controls how timestamps are written: "keep" (default), "remove", or "set" (use FixedTimestamp)
TimestampMode string
// FixedTimestamp is used when TimestampMode=="set" (milliseconds since epoch)
// When TimestampMode=="set", the latest timestamp is aligned to FixedTimestamp and all others are offset accordingly
FixedTimestamp int64
// SeriesRegex filters which time series to write. It matches against "name{labels}" (labels sorted, quoted), excluding value/timestamp.
SeriesRegex *regexp.Regexp
}
SaveOptions controls optional behaviors for SaveToWriter
type SimpleIterator ¶
type SimpleIterator struct {
// contains filtered or unexported fields
}
SimpleIterator implements chunkenc.Iterator
func (*SimpleIterator) At ¶
func (it *SimpleIterator) At() (int64, float64)
func (*SimpleIterator) AtFloatHistogram ¶
func (it *SimpleIterator) AtFloatHistogram(*histogram.FloatHistogram) (int64, *histogram.FloatHistogram)
func (*SimpleIterator) AtHistogram ¶
func (*SimpleIterator) AtST ¶ added in v0.5.15
func (it *SimpleIterator) AtST() int64
func (*SimpleIterator) AtT ¶
func (it *SimpleIterator) AtT() int64
func (*SimpleIterator) Err ¶
func (it *SimpleIterator) Err() error
func (*SimpleIterator) Next ¶
func (it *SimpleIterator) Next() chunkenc.ValueType
type SimpleQuerier ¶
type SimpleQuerier struct {
// contains filtered or unexported fields
}
SimpleQuerier implements storage.Querier
func (*SimpleQuerier) Close ¶
func (q *SimpleQuerier) Close() error
func (*SimpleQuerier) LabelNames ¶
func (q *SimpleQuerier) LabelNames(_ context.Context, hints *storage.LabelHints, matchers ...*labels.Matcher) ([]string, annotations.Annotations, error)
func (*SimpleQuerier) LabelValues ¶
func (q *SimpleQuerier) LabelValues(_ context.Context, name string, hints *storage.LabelHints, matchers ...*labels.Matcher) ([]string, annotations.Annotations, error)
type SimpleSeries ¶
type SimpleSeries struct {
// contains filtered or unexported fields
}
SimpleSeries implements storage.Series
func (*SimpleSeries) Iterator ¶
func (s *SimpleSeries) Iterator(_ chunkenc.Iterator) chunkenc.Iterator
func (*SimpleSeries) Labels ¶
func (s *SimpleSeries) Labels() labels.Labels
type SimpleSeriesSet ¶
type SimpleSeriesSet struct {
// contains filtered or unexported fields
}
SimpleSeriesSet implements storage.SeriesSet
func (*SimpleSeriesSet) At ¶
func (s *SimpleSeriesSet) At() storage.Series
func (*SimpleSeriesSet) Err ¶
func (s *SimpleSeriesSet) Err() error
func (*SimpleSeriesSet) Next ¶
func (s *SimpleSeriesSet) Next() bool
func (*SimpleSeriesSet) Warnings ¶
func (s *SimpleSeriesSet) Warnings() annotations.Annotations
type SimpleStorage ¶
type SimpleStorage struct {
Metrics map[string][]MetricSample
MetricsHelp map[string]string // metric name -> help text
}
SimpleStorage holds metrics in a simple format for querying
func NewSimpleStorage ¶
func NewSimpleStorage() *SimpleStorage
NewSimpleStorage creates a new simple storage
func (*SimpleStorage) AddSample ¶
func (s *SimpleStorage) AddSample(labels map[string]string, value float64, timestampMillis int64)
AddSample appends a single sample to the in-memory store.
func (*SimpleStorage) LatestTimestamp ¶ added in v0.6.3
func (s *SimpleStorage) LatestTimestamp(re *regexp.Regexp) (int64, bool)
LatestTimestamp returns the newest sample timestamp (ms), only among series matching re when it is non-nil (the "name{labels}" signature used by SaveOptions.SeriesRegex).
func (*SimpleStorage) LoadFromReader ¶
func (s *SimpleStorage) LoadFromReader(reader io.Reader) error
LoadFromReader loads Prometheus exposition format data using the official Prometheus parser
func (*SimpleStorage) LoadFromReaderWithFilter ¶
func (s *SimpleStorage) LoadFromReaderWithFilter(reader io.Reader, filter func(name string) bool) error
LoadFromReaderWithFilter loads metrics and applies a metric-name filter function. Only metric families for which filter(name) returns true are loaded.
func (*SimpleStorage) Querier ¶
func (s *SimpleStorage) Querier(mint, maxt int64) (storage.Querier, error)
Queryable implementation for SimpleStorage
func (*SimpleStorage) RenameMetric ¶
func (s *SimpleStorage) RenameMetric(oldName, newName string) error
RenameMetric renames all series with oldName to newName
func (*SimpleStorage) SaveToWriter ¶
func (s *SimpleStorage) SaveToWriter(w io.Writer) error
SaveToWriter writes the store content in Prometheus text exposition (line) format. For determinism, metrics and samples are sorted.
func (*SimpleStorage) SaveToWriterWithOptions ¶
func (s *SimpleStorage) SaveToWriterWithOptions(w io.Writer, opts SaveOptions) error
SaveToWriterWithOptions writes the store content with additional formatting options.