2015-01-21 11:07:45 -08:00
|
|
|
// Copyright 2014 The Prometheus Authors
|
2014-09-19 09:18:44 -07: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 06:47:24 -07:00
|
|
|
package local
|
2014-06-06 02:55:53 -07: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 07:10:31 -08:00
|
|
|
"time"
|
2015-01-09 02:04:20 -08:00
|
|
|
|
2014-10-07 10:11:24 -07:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
|
2015-08-20 08:18:46 -07:00
|
|
|
"github.com/prometheus/common/model"
|
2015-01-09 02:04:20 -08:00
|
|
|
|
2014-06-06 02:55:53 -07:00
|
|
|
"github.com/prometheus/prometheus/storage/metric"
|
|
|
|
)
|
|
|
|
|
2014-09-19 09:18:44 -07:00
|
|
|
// Storage ingests and manages samples, along with various indexes. All methods
|
2015-03-14 19:36:15 -07:00
|
|
|
// are goroutine-safe. Storage implements storage.SampleAppender.
|
2014-06-06 02:55:53 -07:00
|
|
|
type Storage interface {
|
2014-10-07 10:11:24 -07:00
|
|
|
prometheus.Collector
|
2015-03-14 19:36:15 -07: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
|
2015-06-23 06:58:43 -07:00
|
|
|
// processing.) The implementation might remove labels with empty value
|
|
|
|
// from the provided Sample as those labels are considered equivalent to
|
|
|
|
// a label not present at all.
|
2015-08-20 08:18:46 -07:00
|
|
|
Append(*model.Sample)
|
2014-06-06 02:55:53 -07: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 09:25:31 -07: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.
|
2015-08-20 08:18:46 -07:00
|
|
|
MetricsForLabelMatchers(...*metric.LabelMatcher) map[model.Fingerprint]model.COWMetric
|
2015-06-23 06:58:43 -07:00
|
|
|
// LastSamplePairForFingerprint returns the last sample pair for the
|
|
|
|
// provided fingerprint. If the respective time series does not exist or
|
|
|
|
// has an evicted head chunk, nil is returned.
|
2015-08-20 08:18:46 -07:00
|
|
|
LastSamplePairForFingerprint(model.Fingerprint) *metric.SamplePair
|
2014-06-06 02:55:53 -07:00
|
|
|
// Get all of the label values that are associated with a given label name.
|
2015-08-20 08:18:46 -07:00
|
|
|
LabelValuesForLabelName(model.LabelName) model.LabelValues
|
2014-06-06 02:55:53 -07:00
|
|
|
// Get the metric associated with the provided fingerprint.
|
2015-08-20 08:18:46 -07:00
|
|
|
MetricForFingerprint(model.Fingerprint) model.COWMetric
|
2014-06-06 02:55:53 -07:00
|
|
|
// Construct an iterator for a given fingerprint.
|
2015-05-27 02:24:56 -07:00
|
|
|
// The iterator will never return samples older than retention time,
|
|
|
|
// relative to the time NewIterator was called.
|
2015-08-20 08:18:46 -07:00
|
|
|
NewIterator(model.Fingerprint) SeriesIterator
|
2015-05-27 08:41:57 -07:00
|
|
|
// Drop all time series associated with the given fingerprints. This operation
|
|
|
|
// will not show up in the series operations metrics.
|
2015-08-20 08:18:46 -07:00
|
|
|
DropMetricsForFingerprints(...model.Fingerprint)
|
2014-10-24 11:27:27 -07: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 12:03:51 -08:00
|
|
|
// until Stop is called.
|
2015-05-18 10:26:28 -07:00
|
|
|
Start() error
|
2014-10-24 11:27:27 -07:00
|
|
|
// Stop shuts down the Storage gracefully, flushes all pending
|
|
|
|
// operations, stops all maintenance loops,and frees all resources.
|
|
|
|
Stop() error
|
2014-10-08 07:22:54 -07:00
|
|
|
// WaitForIndexing returns once all samples in the storage are
|
2015-05-20 10:13:06 -07:00
|
|
|
// indexed. Indexing is needed for FingerprintsForLabelMatchers and
|
|
|
|
// LabelValuesForLabelName and may lag behind.
|
2014-10-08 07:22:54 -07:00
|
|
|
WaitForIndexing()
|
2014-06-06 02:55:53 -07:00
|
|
|
}
|
|
|
|
|
2015-05-04 11:16:01 -07: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 02:55:53 -07:00
|
|
|
type SeriesIterator interface {
|
2014-09-16 06:47:24 -07: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-08-20 08:18:46 -07:00
|
|
|
ValueAtTime(model.Time) metric.Values
|
2014-09-16 06:47:24 -07:00
|
|
|
// Gets the boundary values of an interval: the first and last value
|
|
|
|
// within a given interval.
|
2015-05-20 10:13:06 -07:00
|
|
|
BoundaryValues(metric.Interval) metric.Values
|
2014-09-16 06:47:24 -07:00
|
|
|
// Gets all values contained within a given interval.
|
2015-05-20 10:13:06 -07:00
|
|
|
RangeValues(metric.Interval) metric.Values
|
2014-06-06 02:55:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// A Preloader preloads series data necessary for a query into memory and pins
|
2014-09-24 07:32:07 -07:00
|
|
|
// them until released via Close(). Its methods are generally not
|
|
|
|
// goroutine-safe.
|
2014-06-06 02:55:53 -07:00
|
|
|
type Preloader interface {
|
2014-10-15 06:53:05 -07:00
|
|
|
PreloadRange(
|
2015-08-20 08:18:46 -07:00
|
|
|
fp model.Fingerprint,
|
|
|
|
from model.Time, through model.Time,
|
2014-10-15 06:53:05 -07:00
|
|
|
stalenessDelta time.Duration,
|
|
|
|
) error
|
2014-06-06 02:55:53 -07:00
|
|
|
// Close unpins any previously requested series data from memory.
|
|
|
|
Close()
|
|
|
|
}
|