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-01-09 02:04:20 -08:00
|
|
|
clientmodel "github.com/prometheus/client_golang/model"
|
|
|
|
|
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
|
|
|
|
// are goroutine-safe.
|
2014-06-06 02:55:53 -07:00
|
|
|
type Storage interface {
|
2014-10-07 10:11:24 -07:00
|
|
|
prometheus.Collector
|
2015-02-12 08:23:42 -08:00
|
|
|
// 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). When AppendSamples has returned, the appended
|
|
|
|
// samples might not be queryable immediately. (Use WaitForIndexing to
|
|
|
|
// wait for complete processing.)
|
2014-06-06 02:55:53 -07:00
|
|
|
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.
|
2014-12-08 07:55:49 -08:00
|
|
|
GetMetricForFingerprint(clientmodel.Fingerprint) clientmodel.COWMetric
|
2014-06-06 02:55:53 -07:00
|
|
|
// Construct an iterator for a given fingerprint.
|
|
|
|
NewIterator(clientmodel.Fingerprint) SeriesIterator
|
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.
|
2014-10-24 11:27:27 -07:00
|
|
|
Start()
|
|
|
|
// 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
|
|
|
|
// indexed. Indexing is needed for GetFingerprintsForLabelMatchers and
|
|
|
|
// GetLabelValuesForLabelName and may lag behind.
|
|
|
|
WaitForIndexing()
|
2014-06-06 02:55:53 -07:00
|
|
|
}
|
|
|
|
|
2014-09-24 07:32:07 -07: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 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.
|
2014-06-06 02:55:53 -07:00
|
|
|
GetValueAtTime(clientmodel.Timestamp) 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.
|
2014-06-06 02:55:53 -07:00
|
|
|
GetBoundaryValues(metric.Interval) metric.Values
|
2014-09-16 06:47:24 -07:00
|
|
|
// Gets all values contained within a given interval.
|
2014-06-06 02:55:53 -07:00
|
|
|
GetRangeValues(metric.Interval) metric.Values
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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(
|
|
|
|
fp clientmodel.Fingerprint,
|
|
|
|
from clientmodel.Timestamp, through clientmodel.Timestamp,
|
|
|
|
stalenessDelta time.Duration,
|
|
|
|
) error
|
2014-06-06 02:55:53 -07:00
|
|
|
// Close unpins any previously requested series data from memory.
|
|
|
|
Close()
|
|
|
|
}
|