2014-09-19 16:18:44 +00:00
|
|
|
// Copyright 2014 Prometheus Team
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2014-09-16 13:47:24 +00:00
|
|
|
package local
|
2014-06-06 09:55:53 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
clientmodel "github.com/prometheus/client_golang/model"
|
|
|
|
"github.com/prometheus/prometheus/storage/metric"
|
|
|
|
)
|
|
|
|
|
2014-09-10 16:41:52 +00:00
|
|
|
// SeriesMap maps fingerprints to memory series.
|
|
|
|
type SeriesMap map[clientmodel.Fingerprint]*memorySeries
|
|
|
|
|
2014-09-19 16:18:44 +00:00
|
|
|
// Storage ingests and manages samples, along with various indexes. All methods
|
|
|
|
// are goroutine-safe.
|
2014-06-06 09:55:53 +00:00
|
|
|
type Storage interface {
|
|
|
|
// AppendSamples stores a group of new samples. Multiple samples for the same
|
|
|
|
// fingerprint need to be submitted in chronological order, from oldest to
|
|
|
|
// newest (both in the same call to AppendSamples and across multiple calls).
|
|
|
|
AppendSamples(clientmodel.Samples)
|
|
|
|
// NewPreloader returns a new Preloader which allows preloading and pinning
|
|
|
|
// series data into memory for use within a query.
|
|
|
|
NewPreloader() Preloader
|
|
|
|
// Get all of the metric fingerprints that are associated with the
|
|
|
|
// provided label matchers.
|
|
|
|
GetFingerprintsForLabelMatchers(metric.LabelMatchers) clientmodel.Fingerprints
|
|
|
|
// Get all of the label values that are associated with a given label name.
|
|
|
|
GetLabelValuesForLabelName(clientmodel.LabelName) clientmodel.LabelValues
|
|
|
|
// Get the metric associated with the provided fingerprint.
|
|
|
|
GetMetricForFingerprint(clientmodel.Fingerprint) clientmodel.Metric
|
|
|
|
// Construct an iterator for a given fingerprint.
|
|
|
|
NewIterator(clientmodel.Fingerprint) SeriesIterator
|
|
|
|
// Run the request-serving and maintenance loop.
|
|
|
|
Serve(started chan<- bool)
|
|
|
|
// Close the MetricsStorage and releases all resources.
|
|
|
|
Close() error
|
|
|
|
}
|
|
|
|
|
2014-09-24 14:32:07 +00:00
|
|
|
// SeriesIterator enables efficient access of sample values in a series. All
|
|
|
|
// methods are goroutine-safe. A SeriesIterator iterates over a snapshot of a
|
|
|
|
// series, i.e. it is safe to continue using a SeriesIterator after modifying
|
|
|
|
// the corresponding series, but the iterator will represent the state of the
|
|
|
|
// series prior the modification.
|
2014-06-06 09:55:53 +00:00
|
|
|
type SeriesIterator interface {
|
2014-09-16 13:47:24 +00:00
|
|
|
// Gets the two values that are immediately adjacent to a given time. In
|
|
|
|
// case a value exist at precisely the given time, only that single
|
|
|
|
// value is returned. Only the first or last value is returned (as a
|
|
|
|
// single value), if the given time is before or after the first or last
|
|
|
|
// value, respectively.
|
2014-06-06 09:55:53 +00:00
|
|
|
GetValueAtTime(clientmodel.Timestamp) metric.Values
|
2014-09-16 13:47:24 +00:00
|
|
|
// Gets the boundary values of an interval: the first and last value
|
|
|
|
// within a given interval.
|
2014-06-06 09:55:53 +00:00
|
|
|
GetBoundaryValues(metric.Interval) metric.Values
|
2014-09-16 13:47:24 +00:00
|
|
|
// Gets all values contained within a given interval.
|
2014-06-06 09:55:53 +00:00
|
|
|
GetRangeValues(metric.Interval) metric.Values
|
|
|
|
}
|
|
|
|
|
2014-09-16 13:47:24 +00:00
|
|
|
// A Persistence is used by a Storage implementation to store samples
|
2014-09-24 14:32:07 +00:00
|
|
|
// persistently across restarts. The methods are generally not goroutine-safe
|
|
|
|
// unless marked otherwise. The chunk-related methods PersistChunk, DropChunks,
|
|
|
|
// LoadChunks, and LoadChunkDescs can be called concurrently with each other if
|
|
|
|
// each call refers to a different fingerprint.
|
|
|
|
//
|
|
|
|
// TODO: As a Persistence is really only used within this package, consider not
|
|
|
|
// exporting it.
|
2014-06-06 09:55:53 +00:00
|
|
|
type Persistence interface {
|
2014-09-24 14:32:07 +00:00
|
|
|
// PersistChunk persists a single chunk of a series. It is the caller's
|
|
|
|
// responsibility to not modify chunk concurrently.
|
2014-06-06 09:55:53 +00:00
|
|
|
PersistChunk(clientmodel.Fingerprint, chunk) error
|
2014-09-24 14:32:07 +00:00
|
|
|
// DropChunks deletes all chunks from a series whose last sample time is
|
|
|
|
// before beforeTime. It returns true if all chunks of the series have
|
|
|
|
// been deleted.
|
2014-09-10 16:41:52 +00:00
|
|
|
DropChunks(fp clientmodel.Fingerprint, beforeTime clientmodel.Timestamp) (allDropped bool, err error)
|
2014-06-06 09:55:53 +00:00
|
|
|
// LoadChunks loads a group of chunks of a timeseries by their index. The
|
|
|
|
// chunk with the earliest time will have index 0, the following ones will
|
|
|
|
// have incrementally larger indexes.
|
|
|
|
LoadChunks(fp clientmodel.Fingerprint, indexes []int) (chunks, error)
|
|
|
|
// LoadChunkDescs loads chunkDescs for a series up until a given time.
|
|
|
|
LoadChunkDescs(fp clientmodel.Fingerprint, beforeTime clientmodel.Timestamp) (chunkDescs, error)
|
2014-09-24 14:32:07 +00:00
|
|
|
|
|
|
|
// PersistSeriesMapAndHeads persists the fingerprint to memory-series
|
|
|
|
// mapping and all open (non-full) head chunks. It is the caller's
|
|
|
|
// responsibility to not modify SeriesMap concurrently. Do not call
|
|
|
|
// concurrently with LoadSeriesMapAndHeads.
|
|
|
|
PersistSeriesMapAndHeads(SeriesMap) error
|
2014-09-10 16:41:52 +00:00
|
|
|
// LoadSeriesMapAndHeads loads the fingerprint to memory-series mapping
|
2014-09-24 14:32:07 +00:00
|
|
|
// and all open (non-full) head chunks. Do not call
|
|
|
|
// concurrently with PersistSeriesMapAndHeads.
|
2014-09-10 16:41:52 +00:00
|
|
|
LoadSeriesMapAndHeads() (SeriesMap, error)
|
|
|
|
|
|
|
|
// GetFingerprintsForLabelPair returns the fingerprints for the given
|
2014-09-24 14:32:07 +00:00
|
|
|
// label pair. This method is goroutine-safe but take into account that
|
|
|
|
// metrics queued for indexing with IndexMetric might not yet made it
|
|
|
|
// into the index. (Same applies correspondingly to UnindexMetric.)
|
2014-09-10 16:41:52 +00:00
|
|
|
GetFingerprintsForLabelPair(metric.LabelPair) (clientmodel.Fingerprints, error)
|
|
|
|
// GetLabelValuesForLabelName returns the label values for the given
|
2014-09-24 14:32:07 +00:00
|
|
|
// label name. This method is goroutine-safe but take into account that
|
|
|
|
// metrics queued for indexing with IndexMetric might not yet made it
|
|
|
|
// into the index. (Same applies correspondingly to UnindexMetric.)
|
2014-09-10 16:41:52 +00:00
|
|
|
GetLabelValuesForLabelName(clientmodel.LabelName) (clientmodel.LabelValues, error)
|
|
|
|
|
2014-09-23 17:21:10 +00:00
|
|
|
// IndexMetric queues the given metric for addition to the indexes
|
|
|
|
// needed by GetFingerprintsForLabelPair and GetLabelValuesForLabelName.
|
|
|
|
// If the queue is full, this method blocks until the metric can be queued.
|
|
|
|
// This method is goroutine-safe.
|
|
|
|
IndexMetric(clientmodel.Metric, clientmodel.Fingerprint)
|
|
|
|
// UnindexMetric queues references to the given metric for removal from
|
|
|
|
// the indexes used for GetFingerprintsForLabelPair and
|
2014-09-10 16:41:52 +00:00
|
|
|
// GetLabelValuesForLabelName. The index of fingerprints to archived
|
2014-09-23 17:21:10 +00:00
|
|
|
// metrics is not affected by this removal. (In fact, never call this
|
2014-09-10 16:41:52 +00:00
|
|
|
// method for an archived metric. To drop an archived metric, call
|
2014-09-23 17:21:10 +00:00
|
|
|
// DropArchivedFingerprint.) If the queue is full, this method blocks
|
|
|
|
// until the metric can be queued. This method is goroutine-safe.
|
|
|
|
UnindexMetric(clientmodel.Metric, clientmodel.Fingerprint)
|
2014-09-24 12:41:38 +00:00
|
|
|
// WaitForIndexing waits until all items in the indexing queue are
|
|
|
|
// processed. If queue processing is currently on hold (to gather more
|
|
|
|
// ops for batching), this method will trigger an immediate start of
|
2014-09-24 14:32:07 +00:00
|
|
|
// processing. This method is goroutine-safe.
|
2014-09-24 12:41:38 +00:00
|
|
|
WaitForIndexing()
|
2014-09-10 16:41:52 +00:00
|
|
|
|
|
|
|
// ArchiveMetric persists the mapping of the given fingerprint to the
|
|
|
|
// given metric, together with the first and last timestamp of the
|
2014-09-24 14:32:07 +00:00
|
|
|
// series belonging to the metric. Do not call concurrently with
|
|
|
|
// UnarchiveMetric or DropArchivedMetric.
|
2014-09-10 16:41:52 +00:00
|
|
|
ArchiveMetric(
|
|
|
|
fingerprint clientmodel.Fingerprint, metric clientmodel.Metric,
|
|
|
|
firstTime, lastTime clientmodel.Timestamp,
|
|
|
|
) error
|
|
|
|
// HasArchivedMetric returns whether the archived metric for the given
|
|
|
|
// fingerprint exists and if yes, what the first and last timestamp in
|
2014-09-24 14:32:07 +00:00
|
|
|
// the corresponding series is. This method is goroutine-safe.
|
2014-09-10 16:41:52 +00:00
|
|
|
HasArchivedMetric(clientmodel.Fingerprint) (
|
|
|
|
hasMetric bool, firstTime, lastTime clientmodel.Timestamp, err error,
|
|
|
|
)
|
2014-09-23 17:21:10 +00:00
|
|
|
// GetFingerprintsModifiedBefore returns the fingerprints of archived
|
2014-09-24 14:32:07 +00:00
|
|
|
// timeseries that have live samples before the provided timestamp. This
|
|
|
|
// method is goroutine-safe (but behavior during concurrent modification
|
|
|
|
// via ArchiveMetric, UnarchiveMetric, or DropArchivedMetric is
|
|
|
|
// undefined).
|
2014-09-23 17:21:10 +00:00
|
|
|
GetFingerprintsModifiedBefore(clientmodel.Timestamp) ([]clientmodel.Fingerprint, error)
|
2014-09-10 16:41:52 +00:00
|
|
|
// GetArchivedMetric retrieves the archived metric with the given
|
2014-09-24 14:32:07 +00:00
|
|
|
// fingerprint. This method is goroutine-safe.
|
2014-09-10 16:41:52 +00:00
|
|
|
GetArchivedMetric(clientmodel.Fingerprint) (clientmodel.Metric, error)
|
|
|
|
// DropArchivedMetric deletes an archived fingerprint and its
|
2014-09-23 17:21:10 +00:00
|
|
|
// corresponding metric entirely. It also queues the metric for
|
|
|
|
// un-indexing (no need to call UnindexMetric for the deleted metric.)
|
2014-09-24 14:32:07 +00:00
|
|
|
// Do not call concurrently with UnarchiveMetric or ArchiveMetric.
|
2014-09-10 16:41:52 +00:00
|
|
|
DropArchivedMetric(clientmodel.Fingerprint) error
|
|
|
|
// UnarchiveMetric deletes an archived fingerprint and its metric, but
|
|
|
|
// (in contrast to DropArchivedMetric) does not un-index the metric.
|
2014-09-24 14:32:07 +00:00
|
|
|
// The method returns true if a metric was actually deleted. Do not call
|
|
|
|
// concurrently with DropArchivedMetric or ArchiveMetric.
|
2014-09-10 16:41:52 +00:00
|
|
|
UnarchiveMetric(clientmodel.Fingerprint) (bool, error)
|
2014-08-21 20:06:11 +00:00
|
|
|
|
2014-09-24 14:32:07 +00:00
|
|
|
// Close flushes the indexing queue and other buffered data and releases
|
|
|
|
// any held resources.
|
2014-09-09 12:36:26 +00:00
|
|
|
Close() error
|
2014-06-06 09:55:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// A Preloader preloads series data necessary for a query into memory and pins
|
2014-09-24 14:32:07 +00:00
|
|
|
// them until released via Close(). Its methods are generally not
|
|
|
|
// goroutine-safe.
|
2014-06-06 09:55:53 +00:00
|
|
|
type Preloader interface {
|
|
|
|
PreloadRange(fp clientmodel.Fingerprint, from clientmodel.Timestamp, through clientmodel.Timestamp) error
|
|
|
|
/*
|
|
|
|
// GetMetricAtTime loads and pins samples around a given time.
|
|
|
|
GetMetricAtTime(clientmodel.Fingerprint, clientmodel.Timestamp) error
|
|
|
|
// GetMetricAtInterval loads and pins samples at intervals.
|
|
|
|
GetMetricAtInterval(fp clientmodel.Fingerprint, from, through clientmodel.Timestamp, interval time.Duration) error
|
|
|
|
// GetMetricRange loads and pins a given range of samples.
|
|
|
|
GetMetricRange(fp clientmodel.Fingerprint, from, through clientmodel.Timestamp) error
|
|
|
|
// GetMetricRangeAtInterval loads and pins sample ranges at intervals.
|
|
|
|
GetMetricRangeAtInterval(fp clientmodel.Fingerprint, from, through clientmodel.Timestamp, interval, rangeDuration time.Duration) error
|
|
|
|
*/
|
|
|
|
// Close unpins any previously requested series data from memory.
|
|
|
|
Close()
|
|
|
|
}
|