2017-04-10 11:59:45 -07:00
|
|
|
// Copyright 2017 The Prometheus Authors
|
|
|
|
// 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.
|
|
|
|
|
2016-12-10 09:08:50 -08:00
|
|
|
package tsdb
|
|
|
|
|
2016-12-13 06:26:58 -08:00
|
|
|
import (
|
|
|
|
"fmt"
|
2017-08-05 04:31:48 -07:00
|
|
|
"sort"
|
2016-12-14 06:39:23 -08:00
|
|
|
"strings"
|
2016-12-13 06:26:58 -08:00
|
|
|
|
2017-10-09 06:21:46 -07:00
|
|
|
"github.com/pkg/errors"
|
2017-11-30 06:34:49 -08:00
|
|
|
"github.com/prometheus/tsdb/chunkenc"
|
2017-04-04 02:27:26 -07:00
|
|
|
"github.com/prometheus/tsdb/chunks"
|
2017-11-30 06:34:49 -08:00
|
|
|
"github.com/prometheus/tsdb/index"
|
2017-04-04 02:27:26 -07:00
|
|
|
"github.com/prometheus/tsdb/labels"
|
2016-12-13 06:26:58 -08:00
|
|
|
)
|
2016-12-12 10:12:55 -08:00
|
|
|
|
2016-12-10 09:08:50 -08:00
|
|
|
// Querier provides querying access over time series data of a fixed
|
|
|
|
// time range.
|
|
|
|
type Querier interface {
|
2016-12-14 06:39:23 -08:00
|
|
|
// Select returns a set of series that matches the given label matchers.
|
2017-11-13 03:16:58 -08:00
|
|
|
Select(...labels.Matcher) (SeriesSet, error)
|
2016-12-10 09:08:50 -08:00
|
|
|
|
|
|
|
// LabelValues returns all potential values for a label name.
|
2016-12-13 06:26:58 -08:00
|
|
|
LabelValues(string) ([]string, error)
|
2016-12-10 09:08:50 -08:00
|
|
|
// LabelValuesFor returns all potential values for a label name.
|
|
|
|
// under the constraint of another label.
|
2016-12-21 00:39:01 -08:00
|
|
|
LabelValuesFor(string, labels.Label) ([]string, error)
|
2016-12-10 09:08:50 -08:00
|
|
|
|
|
|
|
// Close releases the resources of the Querier.
|
|
|
|
Close() error
|
|
|
|
}
|
|
|
|
|
2017-06-25 10:02:02 -07:00
|
|
|
// Series exposes a single time series.
|
2016-12-10 09:08:50 -08:00
|
|
|
type Series interface {
|
2016-12-13 06:26:58 -08:00
|
|
|
// Labels returns the complete set of labels identifying the series.
|
2016-12-21 00:39:01 -08:00
|
|
|
Labels() labels.Labels
|
2016-12-16 03:13:17 -08:00
|
|
|
|
2016-12-10 09:08:50 -08:00
|
|
|
// Iterator returns a new iterator of the data of the series.
|
2016-12-13 06:26:58 -08:00
|
|
|
Iterator() SeriesIterator
|
|
|
|
}
|
|
|
|
|
2017-01-06 03:37:28 -08:00
|
|
|
// querier aggregates querying results from time blocks within
|
2017-01-05 23:08:02 -08:00
|
|
|
// a single partition.
|
2017-01-06 03:37:28 -08:00
|
|
|
type querier struct {
|
|
|
|
blocks []Querier
|
2016-12-13 06:26:58 -08:00
|
|
|
}
|
|
|
|
|
2017-01-06 03:37:28 -08:00
|
|
|
func (q *querier) LabelValues(n string) ([]string, error) {
|
2017-06-12 23:25:13 -07:00
|
|
|
return q.lvals(q.blocks, n)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *querier) lvals(qs []Querier, n string) ([]string, error) {
|
|
|
|
if len(qs) == 0 {
|
2017-03-07 02:29:20 -08:00
|
|
|
return nil, nil
|
|
|
|
}
|
2017-06-12 23:25:13 -07:00
|
|
|
if len(qs) == 1 {
|
|
|
|
return qs[0].LabelValues(n)
|
|
|
|
}
|
|
|
|
l := len(qs) / 2
|
|
|
|
s1, err := q.lvals(qs[:l], n)
|
2016-12-19 03:26:25 -08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-06-12 23:25:13 -07:00
|
|
|
s2, err := q.lvals(qs[l:], n)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2016-12-19 03:26:25 -08:00
|
|
|
}
|
2017-06-12 23:25:13 -07:00
|
|
|
return mergeStrings(s1, s2), nil
|
2016-12-14 09:38:46 -08:00
|
|
|
}
|
|
|
|
|
2017-01-06 03:37:28 -08:00
|
|
|
func (q *querier) LabelValuesFor(string, labels.Label) ([]string, error) {
|
2016-12-14 09:38:46 -08:00
|
|
|
return nil, fmt.Errorf("not implemented")
|
|
|
|
}
|
|
|
|
|
2017-11-13 03:16:58 -08:00
|
|
|
func (q *querier) Select(ms ...labels.Matcher) (SeriesSet, error) {
|
2017-06-12 23:25:13 -07:00
|
|
|
return q.sel(q.blocks, ms)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-11-13 03:16:58 -08:00
|
|
|
func (q *querier) sel(qs []Querier, ms []labels.Matcher) (SeriesSet, error) {
|
2017-06-12 23:25:13 -07:00
|
|
|
if len(qs) == 0 {
|
2017-11-13 03:16:58 -08:00
|
|
|
return EmptySeriesSet(), nil
|
2016-12-20 04:10:37 -08:00
|
|
|
}
|
2017-06-12 23:25:13 -07:00
|
|
|
if len(qs) == 1 {
|
|
|
|
return qs[0].Select(ms...)
|
2016-12-20 04:10:37 -08:00
|
|
|
}
|
2017-06-12 23:25:13 -07:00
|
|
|
l := len(qs) / 2
|
2017-11-13 03:16:58 -08:00
|
|
|
|
|
|
|
a, err := q.sel(qs[:l], ms)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
b, err := q.sel(qs[l:], ms)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return newMergedSeriesSet(a, b), nil
|
2016-12-20 04:10:37 -08:00
|
|
|
}
|
|
|
|
|
2017-01-06 03:37:28 -08:00
|
|
|
func (q *querier) Close() error {
|
2016-12-28 02:41:44 -08:00
|
|
|
var merr MultiError
|
|
|
|
|
|
|
|
for _, bq := range q.blocks {
|
|
|
|
merr.Add(bq.Close())
|
|
|
|
}
|
|
|
|
return merr.Err()
|
2016-12-14 09:38:46 -08:00
|
|
|
}
|
|
|
|
|
2018-01-09 07:40:31 -08:00
|
|
|
// NewBlockQuerier returns a querier against the reader.
|
2017-10-09 06:21:46 -07:00
|
|
|
func NewBlockQuerier(b BlockReader, mint, maxt int64) (Querier, error) {
|
|
|
|
indexr, err := b.Index()
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrapf(err, "open index reader")
|
2017-08-25 01:32:54 -07:00
|
|
|
}
|
2017-10-09 06:21:46 -07:00
|
|
|
chunkr, err := b.Chunks()
|
|
|
|
if err != nil {
|
2017-10-23 11:30:03 -07:00
|
|
|
indexr.Close()
|
2017-10-09 06:21:46 -07:00
|
|
|
return nil, errors.Wrapf(err, "open chunk reader")
|
|
|
|
}
|
|
|
|
tombsr, err := b.Tombstones()
|
|
|
|
if err != nil {
|
2017-10-23 11:30:03 -07:00
|
|
|
indexr.Close()
|
|
|
|
chunkr.Close()
|
2017-10-09 06:21:46 -07:00
|
|
|
return nil, errors.Wrapf(err, "open tombstone reader")
|
|
|
|
}
|
|
|
|
return &blockQuerier{
|
|
|
|
mint: mint,
|
|
|
|
maxt: maxt,
|
|
|
|
index: indexr,
|
|
|
|
chunks: chunkr,
|
|
|
|
tombstones: tombsr,
|
|
|
|
}, nil
|
2017-08-25 01:32:54 -07:00
|
|
|
}
|
|
|
|
|
2016-12-14 09:38:46 -08:00
|
|
|
// blockQuerier provides querying access to a single block database.
|
|
|
|
type blockQuerier struct {
|
2017-05-16 07:18:28 -07:00
|
|
|
index IndexReader
|
|
|
|
chunks ChunkReader
|
|
|
|
tombstones TombstoneReader
|
2016-12-14 09:38:46 -08:00
|
|
|
|
|
|
|
mint, maxt int64
|
|
|
|
}
|
|
|
|
|
2017-11-13 03:16:58 -08:00
|
|
|
func (q *blockQuerier) Select(ms ...labels.Matcher) (SeriesSet, error) {
|
2017-11-13 04:57:10 -08:00
|
|
|
base, err := LookupChunkSeries(q.index, q.tombstones, ms...)
|
2017-11-13 03:16:58 -08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-01-05 06:13:01 -08:00
|
|
|
return &blockSeriesSet{
|
2017-03-07 02:29:20 -08:00
|
|
|
set: &populatedChunkSeries{
|
2017-11-13 04:57:10 -08:00
|
|
|
set: base,
|
2017-03-07 02:29:20 -08:00
|
|
|
chunks: q.chunks,
|
|
|
|
mint: q.mint,
|
|
|
|
maxt: q.maxt,
|
|
|
|
},
|
2017-04-13 12:06:14 -07:00
|
|
|
|
|
|
|
mint: q.mint,
|
|
|
|
maxt: q.maxt,
|
2017-11-13 03:16:58 -08:00
|
|
|
}, nil
|
2016-12-14 09:38:46 -08:00
|
|
|
}
|
|
|
|
|
2017-05-13 08:43:25 -07:00
|
|
|
func (q *blockQuerier) LabelValues(name string) ([]string, error) {
|
|
|
|
tpls, err := q.index.LabelValues(name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
res := make([]string, 0, tpls.Len())
|
|
|
|
|
|
|
|
for i := 0; i < tpls.Len(); i++ {
|
|
|
|
vals, err := tpls.At(i)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
res = append(res, vals[0])
|
|
|
|
}
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *blockQuerier) LabelValuesFor(string, labels.Label) ([]string, error) {
|
|
|
|
return nil, fmt.Errorf("not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *blockQuerier) Close() error {
|
2017-10-09 06:21:46 -07:00
|
|
|
var merr MultiError
|
|
|
|
|
|
|
|
merr.Add(q.index.Close())
|
|
|
|
merr.Add(q.chunks.Close())
|
|
|
|
merr.Add(q.tombstones.Close())
|
|
|
|
|
|
|
|
return merr.Err()
|
2017-05-13 08:43:25 -07:00
|
|
|
}
|
|
|
|
|
2017-11-13 04:57:10 -08:00
|
|
|
// PostingsForMatchers assembles a single postings iterator against the index reader
|
|
|
|
// based on the given matchers. It returns a list of label names that must be manually
|
|
|
|
// checked to not exist in series the postings list points to.
|
2017-11-30 06:34:49 -08:00
|
|
|
func PostingsForMatchers(ix IndexReader, ms ...labels.Matcher) (index.Postings, error) {
|
|
|
|
var its []index.Postings
|
|
|
|
|
2017-05-13 08:43:25 -07:00
|
|
|
for _, m := range ms {
|
2017-11-30 06:34:49 -08:00
|
|
|
it, err := postingsForMatcher(ix, m)
|
2017-11-13 03:16:58 -08:00
|
|
|
if err != nil {
|
2017-12-17 10:08:21 -08:00
|
|
|
return nil, err
|
2017-11-13 03:16:58 -08:00
|
|
|
}
|
|
|
|
its = append(its, it)
|
2017-05-13 08:43:25 -07:00
|
|
|
}
|
2017-11-30 06:34:49 -08:00
|
|
|
return ix.SortedPostings(index.Intersect(its...)), nil
|
2017-05-13 08:43:25 -07:00
|
|
|
}
|
|
|
|
|
2017-07-21 01:37:52 -07:00
|
|
|
// tuplesByPrefix uses binary search to find prefix matches within ts.
|
|
|
|
func tuplesByPrefix(m *labels.PrefixMatcher, ts StringTuples) ([]string, error) {
|
|
|
|
var outErr error
|
|
|
|
tslen := ts.Len()
|
|
|
|
i := sort.Search(tslen, func(i int) bool {
|
|
|
|
vs, err := ts.At(i)
|
|
|
|
if err != nil {
|
|
|
|
outErr = fmt.Errorf("Failed to read tuple %d/%d: %v", i, tslen, err)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
val := vs[0]
|
|
|
|
l := len(m.Prefix())
|
|
|
|
if l > len(vs) {
|
|
|
|
l = len(val)
|
|
|
|
}
|
|
|
|
return val[:l] >= m.Prefix()
|
|
|
|
})
|
|
|
|
if outErr != nil {
|
|
|
|
return nil, outErr
|
|
|
|
}
|
|
|
|
var matches []string
|
|
|
|
for ; i < tslen; i++ {
|
|
|
|
vs, err := ts.At(i)
|
|
|
|
if err != nil || !m.Matches(vs[0]) {
|
|
|
|
return matches, err
|
|
|
|
}
|
|
|
|
matches = append(matches, vs[0])
|
|
|
|
}
|
|
|
|
return matches, nil
|
|
|
|
}
|
|
|
|
|
2017-11-30 06:34:49 -08:00
|
|
|
func postingsForMatcher(ix IndexReader, m labels.Matcher) (index.Postings, error) {
|
2018-10-31 04:49:57 -07:00
|
|
|
// If the matcher selects an empty value, it selects all the series which don't
|
2017-12-17 10:08:21 -08:00
|
|
|
// have the label name set too. See: https://github.com/prometheus/prometheus/issues/3575
|
|
|
|
// and https://github.com/prometheus/prometheus/pull/3578#issuecomment-351653555
|
|
|
|
if m.Matches("") {
|
2017-11-30 06:34:49 -08:00
|
|
|
return postingsForUnsetLabelMatcher(ix, m)
|
2017-12-17 10:08:21 -08:00
|
|
|
}
|
|
|
|
|
2017-04-05 05:14:30 -07:00
|
|
|
// Fast-path for equal matching.
|
|
|
|
if em, ok := m.(*labels.EqualMatcher); ok {
|
2017-11-30 06:34:49 -08:00
|
|
|
it, err := ix.Postings(em.Name(), em.Value())
|
2017-04-05 05:14:30 -07:00
|
|
|
if err != nil {
|
2017-11-13 03:16:58 -08:00
|
|
|
return nil, err
|
2017-04-05 05:14:30 -07:00
|
|
|
}
|
2017-11-13 03:16:58 -08:00
|
|
|
return it, nil
|
2017-04-05 05:14:30 -07:00
|
|
|
}
|
|
|
|
|
2017-11-30 06:34:49 -08:00
|
|
|
tpls, err := ix.LabelValues(m.Name())
|
2016-12-14 09:38:46 -08:00
|
|
|
if err != nil {
|
2017-11-13 03:16:58 -08:00
|
|
|
return nil, err
|
2016-12-14 09:38:46 -08:00
|
|
|
}
|
2017-05-13 08:43:25 -07:00
|
|
|
|
2016-12-14 09:38:46 -08:00
|
|
|
var res []string
|
2017-07-21 01:37:52 -07:00
|
|
|
if pm, ok := m.(*labels.PrefixMatcher); ok {
|
|
|
|
res, err = tuplesByPrefix(pm, tpls)
|
2016-12-14 09:38:46 -08:00
|
|
|
if err != nil {
|
2017-11-13 03:16:58 -08:00
|
|
|
return nil, err
|
2016-12-14 09:38:46 -08:00
|
|
|
}
|
2017-07-21 01:37:52 -07:00
|
|
|
|
|
|
|
} else {
|
|
|
|
for i := 0; i < tpls.Len(); i++ {
|
|
|
|
vals, err := tpls.At(i)
|
|
|
|
if err != nil {
|
2017-11-13 03:16:58 -08:00
|
|
|
return nil, err
|
2017-07-21 01:37:52 -07:00
|
|
|
}
|
|
|
|
if m.Matches(vals[0]) {
|
|
|
|
res = append(res, vals[0])
|
|
|
|
}
|
2016-12-14 09:38:46 -08:00
|
|
|
}
|
|
|
|
}
|
2017-05-13 08:43:25 -07:00
|
|
|
|
2016-12-14 09:38:46 -08:00
|
|
|
if len(res) == 0 {
|
2017-11-30 06:34:49 -08:00
|
|
|
return index.EmptyPostings(), nil
|
2016-12-14 09:38:46 -08:00
|
|
|
}
|
|
|
|
|
2017-11-30 06:34:49 -08:00
|
|
|
var rit []index.Postings
|
2016-12-14 09:38:46 -08:00
|
|
|
|
|
|
|
for _, v := range res {
|
2017-11-30 06:34:49 -08:00
|
|
|
it, err := ix.Postings(m.Name(), v)
|
2016-12-14 09:38:46 -08:00
|
|
|
if err != nil {
|
2017-11-13 03:16:58 -08:00
|
|
|
return nil, err
|
2016-12-14 09:38:46 -08:00
|
|
|
}
|
|
|
|
rit = append(rit, it)
|
|
|
|
}
|
|
|
|
|
2017-11-30 06:34:49 -08:00
|
|
|
return index.Merge(rit...), nil
|
2016-12-14 09:38:46 -08:00
|
|
|
}
|
|
|
|
|
2017-11-30 06:34:49 -08:00
|
|
|
func postingsForUnsetLabelMatcher(ix IndexReader, m labels.Matcher) (index.Postings, error) {
|
|
|
|
tpls, err := ix.LabelValues(m.Name())
|
2017-12-17 10:08:21 -08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var res []string
|
|
|
|
for i := 0; i < tpls.Len(); i++ {
|
|
|
|
vals, err := tpls.At(i)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if !m.Matches(vals[0]) {
|
|
|
|
res = append(res, vals[0])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-30 06:34:49 -08:00
|
|
|
var rit []index.Postings
|
2017-12-17 10:08:21 -08:00
|
|
|
for _, v := range res {
|
2017-11-30 06:34:49 -08:00
|
|
|
it, err := ix.Postings(m.Name(), v)
|
2017-12-17 10:08:21 -08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
rit = append(rit, it)
|
|
|
|
}
|
|
|
|
|
2017-12-22 00:43:34 -08:00
|
|
|
allPostings, err := ix.Postings(index.AllPostingsKey())
|
2017-12-17 10:08:21 -08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-11-30 06:34:49 -08:00
|
|
|
return index.Without(allPostings, index.Merge(rit...)), nil
|
2017-12-17 10:08:21 -08:00
|
|
|
}
|
|
|
|
|
2017-01-06 03:37:28 -08:00
|
|
|
func mergeStrings(a, b []string) []string {
|
|
|
|
maxl := len(a)
|
|
|
|
if len(b) > len(a) {
|
|
|
|
maxl = len(b)
|
|
|
|
}
|
|
|
|
res := make([]string, 0, maxl*10/9)
|
|
|
|
|
|
|
|
for len(a) > 0 && len(b) > 0 {
|
|
|
|
d := strings.Compare(a[0], b[0])
|
|
|
|
|
|
|
|
if d == 0 {
|
|
|
|
res = append(res, a[0])
|
|
|
|
a, b = a[1:], b[1:]
|
|
|
|
} else if d < 0 {
|
|
|
|
res = append(res, a[0])
|
|
|
|
a = a[1:]
|
|
|
|
} else if d > 0 {
|
|
|
|
res = append(res, b[0])
|
|
|
|
b = b[1:]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append all remaining elements.
|
|
|
|
res = append(res, a...)
|
|
|
|
res = append(res, b...)
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
2016-12-14 09:38:46 -08:00
|
|
|
// SeriesSet contains a set of series.
|
|
|
|
type SeriesSet interface {
|
|
|
|
Next() bool
|
2017-01-02 04:27:52 -08:00
|
|
|
At() Series
|
2016-12-14 09:38:46 -08:00
|
|
|
Err() error
|
|
|
|
}
|
|
|
|
|
2017-11-13 03:16:58 -08:00
|
|
|
var emptySeriesSet = errSeriesSet{}
|
2016-12-14 09:38:46 -08:00
|
|
|
|
2017-11-13 03:16:58 -08:00
|
|
|
// EmptySeriesSet returns a series set that's always empty.
|
|
|
|
func EmptySeriesSet() SeriesSet {
|
|
|
|
return emptySeriesSet
|
|
|
|
}
|
2016-12-14 09:38:46 -08:00
|
|
|
|
2017-04-04 02:21:19 -07:00
|
|
|
// mergedSeriesSet takes two series sets as a single series set. The input series sets
|
|
|
|
// must be sorted and sequential in time, i.e. if they have the same label set,
|
|
|
|
// the datapoints of a must be before the datapoints of b.
|
2016-12-14 06:39:23 -08:00
|
|
|
type mergedSeriesSet struct {
|
|
|
|
a, b SeriesSet
|
|
|
|
|
2017-01-02 03:05:52 -08:00
|
|
|
cur Series
|
|
|
|
adone, bdone bool
|
2016-12-14 06:39:23 -08:00
|
|
|
}
|
|
|
|
|
2017-08-25 07:06:24 -07:00
|
|
|
// NewMergedSeriesSet takes two series sets as a single series set. The input series sets
|
|
|
|
// must be sorted and sequential in time, i.e. if they have the same label set,
|
|
|
|
// the datapoints of a must be before the datapoints of b.
|
|
|
|
func NewMergedSeriesSet(a, b SeriesSet) SeriesSet {
|
|
|
|
return newMergedSeriesSet(a, b)
|
|
|
|
}
|
|
|
|
|
2017-03-14 07:24:08 -07:00
|
|
|
func newMergedSeriesSet(a, b SeriesSet) *mergedSeriesSet {
|
|
|
|
s := &mergedSeriesSet{a: a, b: b}
|
2016-12-14 06:39:23 -08:00
|
|
|
// Initialize first elements of both sets as Next() needs
|
|
|
|
// one element look-ahead.
|
2017-01-02 03:05:52 -08:00
|
|
|
s.adone = !s.a.Next()
|
|
|
|
s.bdone = !s.b.Next()
|
2016-12-14 06:39:23 -08:00
|
|
|
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2017-03-14 07:24:08 -07:00
|
|
|
func (s *mergedSeriesSet) At() Series {
|
2016-12-14 06:39:23 -08:00
|
|
|
return s.cur
|
2016-12-13 06:26:58 -08:00
|
|
|
}
|
|
|
|
|
2017-03-14 07:24:08 -07:00
|
|
|
func (s *mergedSeriesSet) Err() error {
|
2016-12-14 06:39:23 -08:00
|
|
|
if s.a.Err() != nil {
|
|
|
|
return s.a.Err()
|
|
|
|
}
|
|
|
|
return s.b.Err()
|
|
|
|
}
|
2016-12-13 06:26:58 -08:00
|
|
|
|
2017-03-14 07:24:08 -07:00
|
|
|
func (s *mergedSeriesSet) compare() int {
|
2017-01-02 03:05:52 -08:00
|
|
|
if s.adone {
|
2016-12-14 06:39:23 -08:00
|
|
|
return 1
|
|
|
|
}
|
2017-01-02 03:05:52 -08:00
|
|
|
if s.bdone {
|
2016-12-14 06:39:23 -08:00
|
|
|
return -1
|
|
|
|
}
|
2017-01-03 10:02:42 -08:00
|
|
|
return labels.Compare(s.a.At().Labels(), s.b.At().Labels())
|
2016-12-14 06:39:23 -08:00
|
|
|
}
|
|
|
|
|
2017-03-14 07:24:08 -07:00
|
|
|
func (s *mergedSeriesSet) Next() bool {
|
2017-01-02 03:05:52 -08:00
|
|
|
if s.adone && s.bdone || s.Err() != nil {
|
2016-12-14 06:39:23 -08:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
d := s.compare()
|
2017-01-04 00:47:20 -08:00
|
|
|
|
2016-12-14 06:39:23 -08:00
|
|
|
// Both sets contain the current series. Chain them into a single one.
|
|
|
|
if d > 0 {
|
2017-01-02 04:27:52 -08:00
|
|
|
s.cur = s.b.At()
|
2017-01-02 03:05:52 -08:00
|
|
|
s.bdone = !s.b.Next()
|
2016-12-14 06:39:23 -08:00
|
|
|
} else if d < 0 {
|
2017-01-02 04:27:52 -08:00
|
|
|
s.cur = s.a.At()
|
2017-01-02 03:05:52 -08:00
|
|
|
s.adone = !s.a.Next()
|
2016-12-14 06:39:23 -08:00
|
|
|
} else {
|
2017-01-02 04:27:52 -08:00
|
|
|
s.cur = &chainedSeries{series: []Series{s.a.At(), s.b.At()}}
|
2017-01-02 03:05:52 -08:00
|
|
|
s.adone = !s.a.Next()
|
|
|
|
s.bdone = !s.b.Next()
|
2016-12-14 06:39:23 -08:00
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2017-12-17 10:08:21 -08:00
|
|
|
// ChunkSeriesSet exposes the chunks and intervals of a series instead of the
|
|
|
|
// actual series itself.
|
2017-11-13 04:57:10 -08:00
|
|
|
type ChunkSeriesSet interface {
|
2017-03-07 02:29:20 -08:00
|
|
|
Next() bool
|
2017-11-30 06:34:49 -08:00
|
|
|
At() (labels.Labels, []chunks.Meta, Intervals)
|
2017-03-07 02:29:20 -08:00
|
|
|
Err() error
|
|
|
|
}
|
2016-12-14 06:39:23 -08:00
|
|
|
|
2017-03-07 02:29:20 -08:00
|
|
|
// baseChunkSeries loads the label set and chunk references for a postings
|
|
|
|
// list from an index. It filters out series that have labels set that should be unset.
|
|
|
|
type baseChunkSeries struct {
|
2017-11-30 06:34:49 -08:00
|
|
|
p index.Postings
|
2017-05-17 02:19:42 -07:00
|
|
|
index IndexReader
|
|
|
|
tombstones TombstoneReader
|
|
|
|
|
2017-05-22 04:12:36 -07:00
|
|
|
lset labels.Labels
|
2017-11-30 06:34:49 -08:00
|
|
|
chks []chunks.Meta
|
2017-08-25 01:11:46 -07:00
|
|
|
intervals Intervals
|
2017-05-22 04:12:36 -07:00
|
|
|
err error
|
2017-05-17 02:19:42 -07:00
|
|
|
}
|
2017-03-07 02:29:20 -08:00
|
|
|
|
2017-11-13 04:57:10 -08:00
|
|
|
// LookupChunkSeries retrieves all series for the given matchers and returns a ChunkSeriesSet
|
|
|
|
// over them. It drops chunks based on tombstones in the given reader.
|
|
|
|
func LookupChunkSeries(ir IndexReader, tr TombstoneReader, ms ...labels.Matcher) (ChunkSeriesSet, error) {
|
|
|
|
if tr == nil {
|
2018-06-08 04:52:01 -07:00
|
|
|
tr = NewMemTombstones()
|
2017-11-13 04:57:10 -08:00
|
|
|
}
|
2017-12-17 10:08:21 -08:00
|
|
|
p, err := PostingsForMatchers(ir, ms...)
|
2017-11-13 04:57:10 -08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &baseChunkSeries{
|
|
|
|
p: p,
|
|
|
|
index: ir,
|
|
|
|
tombstones: tr,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2017-11-30 06:34:49 -08:00
|
|
|
func (s *baseChunkSeries) At() (labels.Labels, []chunks.Meta, Intervals) {
|
2017-05-22 04:12:36 -07:00
|
|
|
return s.lset, s.chks, s.intervals
|
2016-12-14 06:39:23 -08:00
|
|
|
}
|
|
|
|
|
2017-05-17 02:19:42 -07:00
|
|
|
func (s *baseChunkSeries) Err() error { return s.err }
|
2017-03-07 02:29:20 -08:00
|
|
|
|
|
|
|
func (s *baseChunkSeries) Next() bool {
|
2017-08-05 04:31:48 -07:00
|
|
|
var (
|
2018-11-09 05:54:56 -08:00
|
|
|
lset = make(labels.Labels, len(s.lset))
|
|
|
|
chkMetas = make([]chunks.Meta, len(s.chks))
|
2017-11-30 06:34:49 -08:00
|
|
|
err error
|
2017-08-05 04:31:48 -07:00
|
|
|
)
|
2017-12-17 10:08:21 -08:00
|
|
|
|
2017-03-07 02:29:20 -08:00
|
|
|
for s.p.Next() {
|
2017-05-17 02:19:42 -07:00
|
|
|
ref := s.p.At()
|
2017-11-30 06:34:49 -08:00
|
|
|
if err := s.index.Series(ref, &lset, &chkMetas); err != nil {
|
2017-10-11 00:33:35 -07:00
|
|
|
// Postings may be stale. Skip if no underlying series exists.
|
|
|
|
if errors.Cause(err) == ErrNotFound {
|
|
|
|
continue
|
|
|
|
}
|
2016-12-16 03:13:17 -08:00
|
|
|
s.err = err
|
|
|
|
return false
|
|
|
|
}
|
2016-12-31 06:35:08 -08:00
|
|
|
|
2017-03-07 02:29:20 -08:00
|
|
|
s.lset = lset
|
2017-11-30 06:34:49 -08:00
|
|
|
s.chks = chkMetas
|
2017-11-13 04:32:24 -08:00
|
|
|
s.intervals, err = s.tombstones.Get(s.p.At())
|
|
|
|
if err != nil {
|
|
|
|
s.err = errors.Wrap(err, "get tombstones")
|
|
|
|
return false
|
|
|
|
}
|
2017-05-17 02:19:42 -07:00
|
|
|
|
2017-05-23 22:54:24 -07:00
|
|
|
if len(s.intervals) > 0 {
|
2017-05-17 02:19:42 -07:00
|
|
|
// Only those chunks that are not entirely deleted.
|
2017-11-30 06:34:49 -08:00
|
|
|
chks := make([]chunks.Meta, 0, len(s.chks))
|
2017-05-17 02:19:42 -07:00
|
|
|
for _, chk := range s.chks {
|
2017-08-25 01:11:46 -07:00
|
|
|
if !(Interval{chk.MinTime, chk.MaxTime}.isSubrange(s.intervals)) {
|
2017-05-17 02:19:42 -07:00
|
|
|
chks = append(chks, chk)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s.chks = chks
|
|
|
|
}
|
2017-03-07 02:29:20 -08:00
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if err := s.p.Err(); err != nil {
|
|
|
|
s.err = err
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// populatedChunkSeries loads chunk data from a store for a set of series
|
|
|
|
// with known chunk references. It filters out chunks that do not fit the
|
|
|
|
// given time range.
|
|
|
|
type populatedChunkSeries struct {
|
2017-11-13 04:57:10 -08:00
|
|
|
set ChunkSeriesSet
|
2017-03-07 02:29:20 -08:00
|
|
|
chunks ChunkReader
|
|
|
|
mint, maxt int64
|
|
|
|
|
2017-05-22 04:12:36 -07:00
|
|
|
err error
|
2017-11-30 06:34:49 -08:00
|
|
|
chks []chunks.Meta
|
2017-05-22 04:12:36 -07:00
|
|
|
lset labels.Labels
|
2017-08-25 01:11:46 -07:00
|
|
|
intervals Intervals
|
2017-03-07 02:29:20 -08:00
|
|
|
}
|
|
|
|
|
2017-11-30 06:34:49 -08:00
|
|
|
func (s *populatedChunkSeries) At() (labels.Labels, []chunks.Meta, Intervals) {
|
2017-05-22 04:12:36 -07:00
|
|
|
return s.lset, s.chks, s.intervals
|
2017-05-17 02:19:42 -07:00
|
|
|
}
|
2017-12-13 12:58:21 -08:00
|
|
|
|
2017-05-17 02:19:42 -07:00
|
|
|
func (s *populatedChunkSeries) Err() error { return s.err }
|
2017-03-07 02:29:20 -08:00
|
|
|
|
|
|
|
func (s *populatedChunkSeries) Next() bool {
|
|
|
|
for s.set.Next() {
|
2017-05-22 04:12:36 -07:00
|
|
|
lset, chks, dranges := s.set.At()
|
2017-03-07 02:29:20 -08:00
|
|
|
|
2017-05-05 07:04:59 -07:00
|
|
|
for len(chks) > 0 {
|
|
|
|
if chks[0].MaxTime >= s.mint {
|
|
|
|
break
|
2016-12-31 06:35:08 -08:00
|
|
|
}
|
2017-05-05 07:04:59 -07:00
|
|
|
chks = chks[1:]
|
|
|
|
}
|
|
|
|
|
2017-12-13 12:58:21 -08:00
|
|
|
// This is to delete in place while iterating.
|
|
|
|
for i, rlen := 0, len(chks); i < rlen; i++ {
|
|
|
|
j := i - (rlen - len(chks))
|
|
|
|
c := &chks[j]
|
2017-08-06 11:41:24 -07:00
|
|
|
|
|
|
|
// Break out at the first chunk that has no overlap with mint, maxt.
|
2016-12-31 06:35:08 -08:00
|
|
|
if c.MinTime > s.maxt {
|
2017-12-13 12:58:21 -08:00
|
|
|
chks = chks[:j]
|
2016-12-31 06:35:08 -08:00
|
|
|
break
|
|
|
|
}
|
2017-12-13 12:58:21 -08:00
|
|
|
|
2017-03-07 02:29:20 -08:00
|
|
|
c.Chunk, s.err = s.chunks.Chunk(c.Ref)
|
|
|
|
if s.err != nil {
|
2017-12-13 12:58:21 -08:00
|
|
|
// This means that the chunk has be garbage collected. Remove it from the list.
|
|
|
|
if s.err == ErrNotFound {
|
|
|
|
s.err = nil
|
|
|
|
|
|
|
|
// Delete in-place.
|
|
|
|
chks = append(chks[:j], chks[j+1:]...)
|
|
|
|
}
|
|
|
|
|
2017-03-07 02:29:20 -08:00
|
|
|
return false
|
|
|
|
}
|
2016-12-31 06:35:08 -08:00
|
|
|
}
|
2017-12-13 12:58:21 -08:00
|
|
|
|
2017-03-07 02:29:20 -08:00
|
|
|
if len(chks) == 0 {
|
2016-12-31 06:35:08 -08:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2017-03-07 02:29:20 -08:00
|
|
|
s.lset = lset
|
|
|
|
s.chks = chks
|
2017-05-22 04:12:36 -07:00
|
|
|
s.intervals = dranges
|
2017-03-07 02:29:20 -08:00
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if err := s.set.Err(); err != nil {
|
|
|
|
s.err = err
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// blockSeriesSet is a set of series from an inverted index query.
|
|
|
|
type blockSeriesSet struct {
|
2017-11-13 04:57:10 -08:00
|
|
|
set ChunkSeriesSet
|
2017-03-07 02:29:20 -08:00
|
|
|
err error
|
|
|
|
cur Series
|
2017-04-13 12:06:14 -07:00
|
|
|
|
|
|
|
mint, maxt int64
|
2017-03-07 02:29:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *blockSeriesSet) Next() bool {
|
|
|
|
for s.set.Next() {
|
2017-05-22 04:12:36 -07:00
|
|
|
lset, chunks, dranges := s.set.At()
|
2017-05-17 02:19:42 -07:00
|
|
|
s.cur = &chunkSeries{
|
|
|
|
labels: lset,
|
|
|
|
chunks: chunks,
|
|
|
|
mint: s.mint,
|
|
|
|
maxt: s.maxt,
|
|
|
|
|
2017-05-22 04:12:36 -07:00
|
|
|
intervals: dranges,
|
2017-05-17 02:19:42 -07:00
|
|
|
}
|
2016-12-30 10:36:28 -08:00
|
|
|
return true
|
2016-12-14 06:39:23 -08:00
|
|
|
}
|
2017-03-07 02:29:20 -08:00
|
|
|
if s.set.Err() != nil {
|
|
|
|
s.err = s.set.Err()
|
2016-12-14 06:39:23 -08:00
|
|
|
}
|
2016-12-16 03:13:17 -08:00
|
|
|
return false
|
2016-12-14 06:39:23 -08:00
|
|
|
}
|
|
|
|
|
2017-01-02 04:27:52 -08:00
|
|
|
func (s *blockSeriesSet) At() Series { return s.cur }
|
|
|
|
func (s *blockSeriesSet) Err() error { return s.err }
|
2016-12-14 06:39:23 -08:00
|
|
|
|
2016-12-19 03:26:25 -08:00
|
|
|
// chunkSeries is a series that is backed by a sequence of chunks holding
|
|
|
|
// time series data.
|
|
|
|
type chunkSeries struct {
|
2016-12-21 00:39:01 -08:00
|
|
|
labels labels.Labels
|
2017-11-30 06:34:49 -08:00
|
|
|
chunks []chunks.Meta // in-order chunk refs
|
2017-04-13 12:06:14 -07:00
|
|
|
|
|
|
|
mint, maxt int64
|
2017-05-17 02:19:42 -07:00
|
|
|
|
2017-08-25 01:11:46 -07:00
|
|
|
intervals Intervals
|
2016-12-16 03:13:17 -08:00
|
|
|
}
|
|
|
|
|
2016-12-21 00:39:01 -08:00
|
|
|
func (s *chunkSeries) Labels() labels.Labels {
|
2016-12-16 03:13:17 -08:00
|
|
|
return s.labels
|
|
|
|
}
|
|
|
|
|
2016-12-19 03:26:25 -08:00
|
|
|
func (s *chunkSeries) Iterator() SeriesIterator {
|
2017-05-22 04:12:36 -07:00
|
|
|
return newChunkSeriesIterator(s.chunks, s.intervals, s.mint, s.maxt)
|
2016-12-16 03:13:17 -08:00
|
|
|
}
|
|
|
|
|
2016-12-10 09:08:50 -08:00
|
|
|
// SeriesIterator iterates over the data of a time series.
|
|
|
|
type SeriesIterator interface {
|
|
|
|
// Seek advances the iterator forward to the given timestamp.
|
2017-04-09 07:00:25 -07:00
|
|
|
// If there's no value exactly at t, it advances to the first value
|
|
|
|
// after t.
|
2016-12-10 09:08:50 -08:00
|
|
|
Seek(t int64) bool
|
2017-03-19 09:05:01 -07:00
|
|
|
// At returns the current timestamp/value pair.
|
2017-01-02 04:27:52 -08:00
|
|
|
At() (t int64, v float64)
|
2016-12-10 09:08:50 -08:00
|
|
|
// Next advances the iterator by one.
|
|
|
|
Next() bool
|
|
|
|
// Err returns the current error.
|
|
|
|
Err() error
|
|
|
|
}
|
2016-12-12 10:12:55 -08:00
|
|
|
|
2016-12-16 03:13:17 -08:00
|
|
|
// chainedSeries implements a series for a list of time-sorted series.
|
2016-12-19 03:26:25 -08:00
|
|
|
// They all must have the same labels.
|
2016-12-14 06:39:23 -08:00
|
|
|
type chainedSeries struct {
|
|
|
|
series []Series
|
|
|
|
}
|
|
|
|
|
2016-12-21 00:39:01 -08:00
|
|
|
func (s *chainedSeries) Labels() labels.Labels {
|
2016-12-14 06:39:23 -08:00
|
|
|
return s.series[0].Labels()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *chainedSeries) Iterator() SeriesIterator {
|
2017-04-09 07:00:25 -07:00
|
|
|
return newChainedSeriesIterator(s.series...)
|
2016-12-14 06:39:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// chainedSeriesIterator implements a series iterater over a list
|
2016-12-15 06:23:15 -08:00
|
|
|
// of time-sorted, non-overlapping iterators.
|
2016-12-14 06:39:23 -08:00
|
|
|
type chainedSeriesIterator struct {
|
2016-12-16 03:13:17 -08:00
|
|
|
series []Series // series in time order
|
2016-12-15 06:23:15 -08:00
|
|
|
|
|
|
|
i int
|
|
|
|
cur SeriesIterator
|
2016-12-14 06:39:23 -08:00
|
|
|
}
|
|
|
|
|
2017-04-09 07:00:25 -07:00
|
|
|
func newChainedSeriesIterator(s ...Series) *chainedSeriesIterator {
|
|
|
|
return &chainedSeriesIterator{
|
|
|
|
series: s,
|
|
|
|
i: 0,
|
|
|
|
cur: s[0].Iterator(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-14 06:39:23 -08:00
|
|
|
func (it *chainedSeriesIterator) Seek(t int64) bool {
|
2016-12-16 03:13:17 -08:00
|
|
|
// We just scan the chained series sequentially as they are already
|
|
|
|
// pre-selected by relevant time and should be accessed sequentially anyway.
|
|
|
|
for i, s := range it.series[it.i:] {
|
|
|
|
cur := s.Iterator()
|
|
|
|
if !cur.Seek(t) {
|
|
|
|
continue
|
2016-12-15 06:23:15 -08:00
|
|
|
}
|
2016-12-16 03:13:17 -08:00
|
|
|
it.cur = cur
|
|
|
|
it.i += i
|
|
|
|
return true
|
2016-12-15 06:23:15 -08:00
|
|
|
}
|
2016-12-14 06:39:23 -08:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2016-12-15 06:23:15 -08:00
|
|
|
func (it *chainedSeriesIterator) Next() bool {
|
|
|
|
if it.cur.Next() {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if err := it.cur.Err(); err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if it.i == len(it.series)-1 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
it.i++
|
2016-12-16 03:13:17 -08:00
|
|
|
it.cur = it.series[it.i].Iterator()
|
2016-12-15 06:23:15 -08:00
|
|
|
|
|
|
|
return it.Next()
|
2016-12-14 06:39:23 -08:00
|
|
|
}
|
|
|
|
|
2017-01-02 04:27:52 -08:00
|
|
|
func (it *chainedSeriesIterator) At() (t int64, v float64) {
|
|
|
|
return it.cur.At()
|
2016-12-14 06:39:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (it *chainedSeriesIterator) Err() error {
|
2016-12-15 06:23:15 -08:00
|
|
|
return it.cur.Err()
|
2016-12-14 06:39:23 -08:00
|
|
|
}
|
|
|
|
|
2016-12-12 10:12:55 -08:00
|
|
|
// chunkSeriesIterator implements a series iterator on top
|
|
|
|
// of a list of time-sorted, non-overlapping chunks.
|
|
|
|
type chunkSeriesIterator struct {
|
2017-11-30 06:34:49 -08:00
|
|
|
chunks []chunks.Meta
|
2016-12-12 10:12:55 -08:00
|
|
|
|
|
|
|
i int
|
2017-11-30 06:34:49 -08:00
|
|
|
cur chunkenc.Iterator
|
2017-04-13 12:06:14 -07:00
|
|
|
|
|
|
|
maxt, mint int64
|
2017-05-17 02:19:42 -07:00
|
|
|
|
2017-08-25 01:11:46 -07:00
|
|
|
intervals Intervals
|
2016-12-12 10:12:55 -08:00
|
|
|
}
|
|
|
|
|
2017-11-30 06:34:49 -08:00
|
|
|
func newChunkSeriesIterator(cs []chunks.Meta, dranges Intervals, mint, maxt int64) *chunkSeriesIterator {
|
2017-05-17 02:19:42 -07:00
|
|
|
it := cs[0].Chunk.Iterator()
|
2017-08-28 15:39:17 -07:00
|
|
|
|
2017-05-22 04:12:36 -07:00
|
|
|
if len(dranges) > 0 {
|
|
|
|
it = &deletedIterator{it: it, intervals: dranges}
|
2017-05-17 02:19:42 -07:00
|
|
|
}
|
2016-12-12 10:12:55 -08:00
|
|
|
return &chunkSeriesIterator{
|
|
|
|
chunks: cs,
|
|
|
|
i: 0,
|
2017-05-17 02:19:42 -07:00
|
|
|
cur: it,
|
2017-04-13 12:06:14 -07:00
|
|
|
|
|
|
|
mint: mint,
|
|
|
|
maxt: maxt,
|
2017-05-17 02:19:42 -07:00
|
|
|
|
2017-05-22 04:12:36 -07:00
|
|
|
intervals: dranges,
|
2016-12-12 10:12:55 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (it *chunkSeriesIterator) Seek(t int64) (ok bool) {
|
2017-04-13 12:07:21 -07:00
|
|
|
if t > it.maxt {
|
2017-04-13 12:06:14 -07:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-04-13 12:07:21 -07:00
|
|
|
// Seek to the first valid value after t.
|
|
|
|
if t < it.mint {
|
|
|
|
t = it.mint
|
|
|
|
}
|
|
|
|
|
2017-06-30 06:06:27 -07:00
|
|
|
for ; it.chunks[it.i].MaxTime < t; it.i++ {
|
|
|
|
if it.i == len(it.chunks)-1 {
|
|
|
|
return false
|
|
|
|
}
|
2016-12-15 06:23:15 -08:00
|
|
|
}
|
|
|
|
|
2017-06-30 06:06:27 -07:00
|
|
|
it.cur = it.chunks[it.i].Chunk.Iterator()
|
2017-05-22 04:12:36 -07:00
|
|
|
if len(it.intervals) > 0 {
|
|
|
|
it.cur = &deletedIterator{it: it.cur, intervals: it.intervals}
|
2017-05-17 02:19:42 -07:00
|
|
|
}
|
2016-12-15 06:23:15 -08:00
|
|
|
|
|
|
|
for it.cur.Next() {
|
2017-01-02 04:27:52 -08:00
|
|
|
t0, _ := it.cur.At()
|
2016-12-15 06:23:15 -08:00
|
|
|
if t0 >= t {
|
2016-12-16 03:13:17 -08:00
|
|
|
return true
|
2016-12-12 10:12:55 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-01-02 04:27:52 -08:00
|
|
|
func (it *chunkSeriesIterator) At() (t int64, v float64) {
|
|
|
|
return it.cur.At()
|
2016-12-12 10:12:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (it *chunkSeriesIterator) Next() bool {
|
2017-08-28 15:39:17 -07:00
|
|
|
if it.cur.Next() {
|
2017-04-13 12:06:14 -07:00
|
|
|
t, _ := it.cur.At()
|
2017-08-28 15:39:17 -07:00
|
|
|
|
2017-06-12 22:54:04 -07:00
|
|
|
if t < it.mint {
|
2017-08-28 15:39:17 -07:00
|
|
|
if !it.Seek(it.mint) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
t, _ = it.At()
|
2017-06-12 22:54:04 -07:00
|
|
|
|
2017-08-28 15:39:17 -07:00
|
|
|
return t <= it.maxt
|
|
|
|
}
|
2017-06-12 22:54:04 -07:00
|
|
|
if t > it.maxt {
|
|
|
|
return false
|
2017-04-13 12:06:14 -07:00
|
|
|
}
|
2017-06-12 22:54:04 -07:00
|
|
|
return true
|
2016-12-12 10:12:55 -08:00
|
|
|
}
|
|
|
|
if err := it.cur.Err(); err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if it.i == len(it.chunks)-1 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
it.i++
|
2017-03-07 02:29:20 -08:00
|
|
|
it.cur = it.chunks[it.i].Chunk.Iterator()
|
2017-05-22 04:12:36 -07:00
|
|
|
if len(it.intervals) > 0 {
|
|
|
|
it.cur = &deletedIterator{it: it.cur, intervals: it.intervals}
|
2017-05-17 02:19:42 -07:00
|
|
|
}
|
2016-12-12 10:12:55 -08:00
|
|
|
|
|
|
|
return it.Next()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (it *chunkSeriesIterator) Err() error {
|
|
|
|
return it.cur.Err()
|
|
|
|
}
|
|
|
|
|
2017-11-30 06:34:49 -08:00
|
|
|
// deletedIterator wraps an Iterator and makes sure any deleted metrics are not
|
|
|
|
// returned.
|
|
|
|
type deletedIterator struct {
|
|
|
|
it chunkenc.Iterator
|
|
|
|
|
|
|
|
intervals Intervals
|
|
|
|
}
|
|
|
|
|
|
|
|
func (it *deletedIterator) At() (int64, float64) {
|
|
|
|
return it.it.At()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (it *deletedIterator) Next() bool {
|
|
|
|
Outer:
|
|
|
|
for it.it.Next() {
|
|
|
|
ts, _ := it.it.At()
|
|
|
|
|
|
|
|
for _, tr := range it.intervals {
|
|
|
|
if tr.inBounds(ts) {
|
|
|
|
continue Outer
|
|
|
|
}
|
|
|
|
|
|
|
|
if ts > tr.Maxt {
|
|
|
|
it.intervals = it.intervals[1:]
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (it *deletedIterator) Err() error {
|
|
|
|
return it.it.Err()
|
|
|
|
}
|
|
|
|
|
2017-01-04 00:47:20 -08:00
|
|
|
type errSeriesSet struct {
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s errSeriesSet) Next() bool { return false }
|
|
|
|
func (s errSeriesSet) At() Series { return nil }
|
|
|
|
func (s errSeriesSet) Err() error { return s.err }
|