2015-01-21 19:07:45 +00:00
|
|
|
// Copyright 2014 The Prometheus Authors
|
2014-09-19 16:18:44 +00:00
|
|
|
// 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 (
|
Fix a bug handling freshly unarchived series.
Usually, if you unarchive a series, it is to add something to it,
which will create a new head chunk. However, if a series in
unarchived, and before anything is added to it, it is handled by the
maintenance loop, it will be archived again. In that case, we have to
load the chunkDescs to know the lastTime of the series to be
archived. Usually, this case will happen only rarely (as a race, has
never happened so far, possibly because the locking around unarchiving
and the subsequent sample append is smart enough). However, during
crash recovery, we sometimes treat series as "freshly unarchived"
without directly appending a sample. We might add more cases of that
type later, so better deal with archiving properly and load chunkDescs
if required.
2015-01-08 15:10:31 +00:00
|
|
|
"time"
|
2015-01-09 10:04:20 +00:00
|
|
|
|
2014-10-07 17:11:24 +00:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
|
2015-01-09 10:04:20 +00:00
|
|
|
clientmodel "github.com/prometheus/client_golang/model"
|
|
|
|
|
2014-06-06 09:55:53 +00:00
|
|
|
"github.com/prometheus/prometheus/storage/metric"
|
|
|
|
)
|
|
|
|
|
2014-09-19 16:18:44 +00:00
|
|
|
// Storage ingests and manages samples, along with various indexes. All methods
|
2015-03-15 02:36:15 +00:00
|
|
|
// are goroutine-safe. Storage implements storage.SampleAppender.
|
2014-06-06 09:55:53 +00:00
|
|
|
type Storage interface {
|
2014-10-07 17:11:24 +00:00
|
|
|
prometheus.Collector
|
2015-03-15 02:36:15 +00:00
|
|
|
// Append stores a sample in the Storage. Multiple samples for the same
|
|
|
|
// fingerprint need to be submitted in chronological order, from oldest
|
|
|
|
// to newest. When Append has returned, the appended sample might not be
|
|
|
|
// queryable immediately. (Use WaitForIndexing to wait for complete
|
|
|
|
// processing.)
|
|
|
|
Append(*clientmodel.Sample)
|
2014-06-06 09:55:53 +00:00
|
|
|
// NewPreloader returns a new Preloader which allows preloading and pinning
|
|
|
|
// series data into memory for use within a query.
|
|
|
|
NewPreloader() Preloader
|
2015-06-15 16:25:31 +00:00
|
|
|
// MetricsForLabelMatchers returns the metrics from storage that satisfy the given
|
|
|
|
// label matchers. At least one label matcher must be specified that does not
|
|
|
|
// match the empty string.
|
|
|
|
MetricsForLabelMatchers(matchers ...*metric.LabelMatcher) map[clientmodel.Fingerprint]clientmodel.COWMetric
|
2015-06-22 20:50:47 +00:00
|
|
|
// LastSamplePairForFingerprint returns the last sample pair for the provided fingerprint.
|
|
|
|
// If the respective time series is evicted, nil is returned.
|
|
|
|
LastSamplePairForFingerprint(clientmodel.Fingerprint) *metric.SamplePair
|
2014-06-06 09:55:53 +00:00
|
|
|
// Get all of the label values that are associated with a given label name.
|
2015-05-20 17:13:06 +00:00
|
|
|
LabelValuesForLabelName(clientmodel.LabelName) clientmodel.LabelValues
|
2014-06-06 09:55:53 +00:00
|
|
|
// Get the metric associated with the provided fingerprint.
|
2015-05-20 17:13:06 +00:00
|
|
|
MetricForFingerprint(clientmodel.Fingerprint) clientmodel.COWMetric
|
2014-06-06 09:55:53 +00:00
|
|
|
// Construct an iterator for a given fingerprint.
|
2015-05-27 09:24:56 +00:00
|
|
|
// The iterator will never return samples older than retention time,
|
|
|
|
// relative to the time NewIterator was called.
|
2014-06-06 09:55:53 +00:00
|
|
|
NewIterator(clientmodel.Fingerprint) SeriesIterator
|
2015-05-27 15:41:57 +00:00
|
|
|
// Drop all time series associated with the given fingerprints. This operation
|
|
|
|
// will not show up in the series operations metrics.
|
|
|
|
DropMetricsForFingerprints(...clientmodel.Fingerprint)
|
2014-10-24 18:27:27 +00:00
|
|
|
// Run the various maintenance loops in goroutines. Returns when the
|
|
|
|
// storage is ready to use. Keeps everything running in the background
|
2014-11-20 20:03:51 +00:00
|
|
|
// until Stop is called.
|
2015-05-18 17:26:28 +00:00
|
|
|
Start() error
|
2014-10-24 18:27:27 +00:00
|
|
|
// Stop shuts down the Storage gracefully, flushes all pending
|
|
|
|
// operations, stops all maintenance loops,and frees all resources.
|
|
|
|
Stop() error
|
2014-10-08 14:22:54 +00:00
|
|
|
// WaitForIndexing returns once all samples in the storage are
|
2015-05-20 17:13:06 +00:00
|
|
|
// indexed. Indexing is needed for FingerprintsForLabelMatchers and
|
|
|
|
// LabelValuesForLabelName and may lag behind.
|
2014-10-08 14:22:54 +00:00
|
|
|
WaitForIndexing()
|
2014-06-06 09:55:53 +00:00
|
|
|
}
|
|
|
|
|
2015-05-04 18:16:01 +00:00
|
|
|
// SeriesIterator enables efficient access of sample values in a series. Its
|
|
|
|
// methods are not goroutine-safe. A SeriesIterator iterates over a snapshot of
|
|
|
|
// a series, i.e. it is safe to continue using a SeriesIterator after or during
|
|
|
|
// 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.
|
2015-05-20 17:13:06 +00:00
|
|
|
ValueAtTime(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.
|
2015-05-20 17:13:06 +00:00
|
|
|
BoundaryValues(metric.Interval) metric.Values
|
2014-09-16 13:47:24 +00:00
|
|
|
// Gets all values contained within a given interval.
|
2015-05-20 17:13:06 +00:00
|
|
|
RangeValues(metric.Interval) metric.Values
|
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 {
|
2014-10-15 13:53:05 +00:00
|
|
|
PreloadRange(
|
|
|
|
fp clientmodel.Fingerprint,
|
|
|
|
from clientmodel.Timestamp, through clientmodel.Timestamp,
|
|
|
|
stalenessDelta time.Duration,
|
|
|
|
) error
|
2014-06-06 09:55:53 +00:00
|
|
|
// Close unpins any previously requested series data from memory.
|
|
|
|
Close()
|
|
|
|
}
|