mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-18 11:34:05 -08:00
e6d7cc5fa4
* tsdb: Added ChunkQueryable implementations to db; unified compactor, querier and fanout block iterating. Chained to https://github.com/prometheus/prometheus/pull/7059 * NewMerge(Chunk)Querier now takies multiple primaries allowing tsdb DB code to use it. * Added single SeriesEntry / ChunkEntry for all series implementations. * Unified all vertical, and non vertical for compact and querying to single merge series / chunk sets by reusing VerticalSeriesMergeFunc for overlapping algorithm (same logic as before) * Added block (Base/Chunk/)Querier for block querying. We then use populateAndTomb(Base/Chunk/) to iterate over chunks or samples. * Refactored endpoint tests and querier tests to include subtests. Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com> * Addressed comments from Brian and Beorn. Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com> * Fixed snapshot test and added chunk iterator support for DBReadOnly. Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com> * Fixed race when iterating over Ats first. Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com> * Fixed tests. Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com> * Fixed populate block tests. Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com> * Fixed endpoints test. Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com> * Fixed test. Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com> * Added test & fixed case of head open chunk. Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com> * Fixed DBReadOnly tests and bug producing 1 sample chunks. Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com> * Added cases for partial block overlap for multiple full chunks. Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com> * Added extra tests for chunk meta after compaction. Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com> * Fixed small vertical merge bug and added more tests for that. Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
141 lines
3.6 KiB
Go
141 lines
3.6 KiB
Go
// Copyright 2020 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.
|
|
|
|
// This file holds boilerplate adapters for generic MergeSeriesSet and MergeQuerier functions, so we can have one optimized
|
|
// solution that works for both ChunkSeriesSet as well as SeriesSet.
|
|
|
|
package storage
|
|
|
|
import (
|
|
"github.com/prometheus/prometheus/pkg/labels"
|
|
)
|
|
|
|
type genericQuerier interface {
|
|
LabelQuerier
|
|
Select(bool, *SelectHints, ...*labels.Matcher) genericSeriesSet
|
|
}
|
|
|
|
type genericSeriesSet interface {
|
|
Next() bool
|
|
At() Labels
|
|
Err() error
|
|
Warnings() Warnings
|
|
}
|
|
|
|
type genericSeriesMergeFunc func(...Labels) Labels
|
|
|
|
type genericSeriesSetAdapter struct {
|
|
SeriesSet
|
|
}
|
|
|
|
func (a *genericSeriesSetAdapter) At() Labels {
|
|
return a.SeriesSet.At()
|
|
}
|
|
|
|
type genericChunkSeriesSetAdapter struct {
|
|
ChunkSeriesSet
|
|
}
|
|
|
|
func (a *genericChunkSeriesSetAdapter) At() Labels {
|
|
return a.ChunkSeriesSet.At()
|
|
}
|
|
|
|
type genericQuerierAdapter struct {
|
|
LabelQuerier
|
|
|
|
// One-of. If both are set, Querier will be used.
|
|
q Querier
|
|
cq ChunkQuerier
|
|
}
|
|
|
|
func (q *genericQuerierAdapter) Select(sortSeries bool, hints *SelectHints, matchers ...*labels.Matcher) genericSeriesSet {
|
|
if q.q != nil {
|
|
return &genericSeriesSetAdapter{q.q.Select(sortSeries, hints, matchers...)}
|
|
}
|
|
return &genericChunkSeriesSetAdapter{q.cq.Select(sortSeries, hints, matchers...)}
|
|
}
|
|
|
|
func newGenericQuerierFrom(q Querier) genericQuerier {
|
|
return &genericQuerierAdapter{LabelQuerier: q, q: q}
|
|
}
|
|
|
|
func newGenericQuerierFromChunk(cq ChunkQuerier) genericQuerier {
|
|
return &genericQuerierAdapter{LabelQuerier: cq, cq: cq}
|
|
}
|
|
|
|
type querierAdapter struct {
|
|
genericQuerier
|
|
}
|
|
|
|
type seriesSetAdapter struct {
|
|
genericSeriesSet
|
|
}
|
|
|
|
func (a *seriesSetAdapter) At() Series {
|
|
return a.genericSeriesSet.At().(Series)
|
|
}
|
|
|
|
func (q *querierAdapter) Select(sortSeries bool, hints *SelectHints, matchers ...*labels.Matcher) SeriesSet {
|
|
return &seriesSetAdapter{q.genericQuerier.Select(sortSeries, hints, matchers...)}
|
|
}
|
|
|
|
type chunkQuerierAdapter struct {
|
|
genericQuerier
|
|
}
|
|
|
|
type chunkSeriesSetAdapter struct {
|
|
genericSeriesSet
|
|
}
|
|
|
|
func (a *chunkSeriesSetAdapter) At() ChunkSeries {
|
|
return a.genericSeriesSet.At().(ChunkSeries)
|
|
}
|
|
|
|
func (q *chunkQuerierAdapter) Select(sortSeries bool, hints *SelectHints, matchers ...*labels.Matcher) ChunkSeriesSet {
|
|
return &chunkSeriesSetAdapter{q.genericQuerier.Select(sortSeries, hints, matchers...)}
|
|
}
|
|
|
|
type seriesMergerAdapter struct {
|
|
VerticalSeriesMergeFunc
|
|
}
|
|
|
|
func (a *seriesMergerAdapter) Merge(s ...Labels) Labels {
|
|
buf := make([]Series, 0, len(s))
|
|
for _, ser := range s {
|
|
buf = append(buf, ser.(Series))
|
|
}
|
|
return a.VerticalSeriesMergeFunc(buf...)
|
|
}
|
|
|
|
type chunkSeriesMergerAdapter struct {
|
|
VerticalChunkSeriesMergeFunc
|
|
}
|
|
|
|
func (a *chunkSeriesMergerAdapter) Merge(s ...Labels) Labels {
|
|
buf := make([]ChunkSeries, 0, len(s))
|
|
for _, ser := range s {
|
|
buf = append(buf, ser.(ChunkSeries))
|
|
}
|
|
return a.VerticalChunkSeriesMergeFunc(buf...)
|
|
}
|
|
|
|
type noopGenericSeriesSet struct{}
|
|
|
|
func (noopGenericSeriesSet) Next() bool { return false }
|
|
|
|
func (noopGenericSeriesSet) At() Labels { return nil }
|
|
|
|
func (noopGenericSeriesSet) Err() error { return nil }
|
|
|
|
func (noopGenericSeriesSet) Warnings() Warnings { return nil }
|