2017-04-10 18:59:45 +00: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.
|
|
|
|
|
2017-11-30 14:34:49 +00:00
|
|
|
package chunkenc
|
2016-11-15 09:33:34 +00:00
|
|
|
|
2017-08-08 15:35:34 +00:00
|
|
|
import (
|
2020-02-06 15:58:38 +00:00
|
|
|
"math"
|
2017-08-08 15:35:34 +00:00
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2021-11-17 18:57:31 +00:00
|
|
|
|
Style cleanup of all the changes in sparsehistogram so far
A lot of this code was hacked together, literally during a
hackathon. This commit intends not to change the code substantially,
but just make the code obey the usual style practices.
A (possibly incomplete) list of areas:
* Generally address linter warnings.
* The `pgk` directory is deprecated as per dev-summit. No new packages should
be added to it. I moved the new `pkg/histogram` package to `model`
anticipating what's proposed in #9478.
* Make the naming of the Sparse Histogram more consistent. Including
abbreviations, there were just too many names for it: SparseHistogram,
Histogram, Histo, hist, his, shs, h. The idea is to call it "Histogram" in
general. Only add "Sparse" if it is needed to avoid confusion with
conventional Histograms (which is rare because the TSDB really has no notion
of conventional Histograms). Use abbreviations only in local scope, and then
really abbreviate (not just removing three out of seven letters like in
"Histo"). This is in the spirit of
https://github.com/golang/go/wiki/CodeReviewComments#variable-names
* Several other minor name changes.
* A lot of formatting of doc comments. For one, following
https://github.com/golang/go/wiki/CodeReviewComments#comment-sentences
, but also layout question, anticipating how things will look like
when rendered by `godoc` (even where `godoc` doesn't render them
right now because they are for unexported types or not a doc comment
at all but just a normal code comment - consistency is queen!).
* Re-enabled `TestQueryLog` and `TestEndopints` (they pass now,
leaving them disabled was presumably an oversight).
* Bucket iterator for histogram.Histogram is now created with a
method.
* HistogramChunk.iterator now allows iterator recycling. (I think
@dieterbe only commented it out because he was confused by the
question in the comment.)
* HistogramAppender.Append panics now because we decided to treat
staleness marker differently.
Signed-off-by: beorn7 <beorn@grafana.com>
2021-10-09 13:57:07 +00:00
|
|
|
"github.com/prometheus/prometheus/model/histogram"
|
2017-08-08 15:35:34 +00:00
|
|
|
)
|
2016-11-15 09:33:34 +00:00
|
|
|
|
2017-04-28 13:41:42 +00:00
|
|
|
// Encoding is the identifier for a chunk encoding.
|
2016-11-15 09:33:34 +00:00
|
|
|
type Encoding uint8
|
|
|
|
|
2021-11-29 07:54:23 +00:00
|
|
|
// The different available chunk encodings.
|
|
|
|
const (
|
|
|
|
EncNone Encoding = iota
|
|
|
|
EncXOR
|
|
|
|
EncHistogram
|
2022-12-20 10:03:32 +00:00
|
|
|
EncFloatHistogram
|
2021-11-29 07:54:23 +00:00
|
|
|
)
|
|
|
|
|
2016-11-15 09:33:34 +00:00
|
|
|
func (e Encoding) String() string {
|
|
|
|
switch e {
|
|
|
|
case EncNone:
|
|
|
|
return "none"
|
|
|
|
case EncXOR:
|
|
|
|
return "XOR"
|
Style cleanup of all the changes in sparsehistogram so far
A lot of this code was hacked together, literally during a
hackathon. This commit intends not to change the code substantially,
but just make the code obey the usual style practices.
A (possibly incomplete) list of areas:
* Generally address linter warnings.
* The `pgk` directory is deprecated as per dev-summit. No new packages should
be added to it. I moved the new `pkg/histogram` package to `model`
anticipating what's proposed in #9478.
* Make the naming of the Sparse Histogram more consistent. Including
abbreviations, there were just too many names for it: SparseHistogram,
Histogram, Histo, hist, his, shs, h. The idea is to call it "Histogram" in
general. Only add "Sparse" if it is needed to avoid confusion with
conventional Histograms (which is rare because the TSDB really has no notion
of conventional Histograms). Use abbreviations only in local scope, and then
really abbreviate (not just removing three out of seven letters like in
"Histo"). This is in the spirit of
https://github.com/golang/go/wiki/CodeReviewComments#variable-names
* Several other minor name changes.
* A lot of formatting of doc comments. For one, following
https://github.com/golang/go/wiki/CodeReviewComments#comment-sentences
, but also layout question, anticipating how things will look like
when rendered by `godoc` (even where `godoc` doesn't render them
right now because they are for unexported types or not a doc comment
at all but just a normal code comment - consistency is queen!).
* Re-enabled `TestQueryLog` and `TestEndopints` (they pass now,
leaving them disabled was presumably an oversight).
* Bucket iterator for histogram.Histogram is now created with a
method.
* HistogramChunk.iterator now allows iterator recycling. (I think
@dieterbe only commented it out because he was confused by the
question in the comment.)
* HistogramAppender.Append panics now because we decided to treat
staleness marker differently.
Signed-off-by: beorn7 <beorn@grafana.com>
2021-10-09 13:57:07 +00:00
|
|
|
case EncHistogram:
|
|
|
|
return "histogram"
|
2022-12-20 10:03:32 +00:00
|
|
|
case EncFloatHistogram:
|
|
|
|
return "floathistogram"
|
2016-11-15 09:33:34 +00:00
|
|
|
}
|
|
|
|
return "<unknown>"
|
|
|
|
}
|
|
|
|
|
2022-09-20 17:05:50 +00:00
|
|
|
// Chunk encodings for out-of-order chunks.
|
|
|
|
// These encodings must be only used by the Head block for its internal bookkeeping.
|
|
|
|
const (
|
|
|
|
OutOfOrderMask = 0b10000000
|
|
|
|
EncOOOXOR = EncXOR | OutOfOrderMask
|
|
|
|
)
|
|
|
|
|
|
|
|
func IsOutOfOrderChunk(e Encoding) bool {
|
|
|
|
return (e & OutOfOrderMask) != 0
|
|
|
|
}
|
|
|
|
|
2022-10-11 16:35:35 +00:00
|
|
|
// IsValidEncoding returns true for supported encodings.
|
2022-09-20 17:05:50 +00:00
|
|
|
func IsValidEncoding(e Encoding) bool {
|
2022-12-20 10:03:32 +00:00
|
|
|
return e == EncXOR || e == EncOOOXOR || e == EncHistogram || e == EncFloatHistogram
|
2022-09-20 17:05:50 +00:00
|
|
|
}
|
|
|
|
|
2016-11-15 09:33:34 +00:00
|
|
|
// Chunk holds a sequence of sample pairs that can be iterated over and appended to.
|
|
|
|
type Chunk interface {
|
2020-02-05 12:07:41 +00:00
|
|
|
// Bytes returns the underlying byte slice of the chunk.
|
2016-11-29 21:02:58 +00:00
|
|
|
Bytes() []byte
|
2020-02-05 12:07:41 +00:00
|
|
|
|
|
|
|
// Encoding returns the encoding type of the chunk.
|
2016-12-09 19:45:46 +00:00
|
|
|
Encoding() Encoding
|
2020-02-05 12:07:41 +00:00
|
|
|
|
|
|
|
// Appender returns an appender to append samples to the chunk.
|
2016-11-29 21:02:58 +00:00
|
|
|
Appender() (Appender, error)
|
2020-02-05 12:07:41 +00:00
|
|
|
|
2019-07-09 09:49:34 +00:00
|
|
|
// The iterator passed as argument is for re-use.
|
|
|
|
// Depending on implementation, the iterator can
|
|
|
|
// be re-used or a new iterator can be allocated.
|
|
|
|
Iterator(Iterator) Iterator
|
2020-02-05 12:07:41 +00:00
|
|
|
|
|
|
|
// NumSamples returns the number of samples in the chunk.
|
2017-07-12 16:31:26 +00:00
|
|
|
NumSamples() int
|
2020-02-05 12:07:41 +00:00
|
|
|
|
|
|
|
// Compact is called whenever a chunk is expected to be complete (no more
|
|
|
|
// samples appended) and the underlying implementation can eventually
|
|
|
|
// optimize the chunk.
|
|
|
|
// There's no strong guarantee that no samples will be appended once
|
|
|
|
// Compact() is called. Implementing this function is optional.
|
2020-01-24 07:44:52 +00:00
|
|
|
Compact()
|
2016-11-15 09:33:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Appender adds sample pairs to a chunk.
|
|
|
|
type Appender interface {
|
2016-12-31 09:10:27 +00:00
|
|
|
Append(int64, float64)
|
2021-11-12 18:07:41 +00:00
|
|
|
AppendHistogram(t int64, h *histogram.Histogram)
|
2022-12-20 10:03:32 +00:00
|
|
|
AppendFloatHistogram(t int64, h *histogram.FloatHistogram)
|
2016-11-15 09:33:34 +00:00
|
|
|
}
|
|
|
|
|
2016-12-31 09:10:27 +00:00
|
|
|
// Iterator is a simple iterator that can only get the next value.
|
2020-02-26 13:11:55 +00:00
|
|
|
// Iterator iterates over the samples of a time series, in timestamp-increasing order.
|
2016-12-31 09:10:27 +00:00
|
|
|
type Iterator interface {
|
2021-11-29 07:54:23 +00:00
|
|
|
// Next advances the iterator by one and returns the type of the value
|
|
|
|
// at the new position (or ValNone if the iterator is exhausted).
|
|
|
|
Next() ValueType
|
|
|
|
// Seek advances the iterator forward to the first sample with a
|
|
|
|
// timestamp equal or greater than t. If the current sample found by a
|
|
|
|
// previous `Next` or `Seek` operation already has this property, Seek
|
|
|
|
// has no effect. If a sample has been found, Seek returns the type of
|
|
|
|
// its value. Otherwise, it returns ValNone, after with the iterator is
|
|
|
|
// exhausted.
|
|
|
|
Seek(t int64) ValueType
|
|
|
|
// At returns the current timestamp/value pair if the value is a float.
|
|
|
|
// Before the iterator has advanced, the behaviour is unspecified.
|
2017-01-02 12:27:52 +00:00
|
|
|
At() (int64, float64)
|
2021-11-29 07:54:23 +00:00
|
|
|
// AtHistogram returns the current timestamp/value pair if the value is
|
|
|
|
// a histogram with integer counts. Before the iterator has advanced,
|
|
|
|
// the behaviour is unspecified.
|
2021-11-12 18:07:41 +00:00
|
|
|
AtHistogram() (int64, *histogram.Histogram)
|
2021-11-29 07:54:23 +00:00
|
|
|
// AtFloatHistogram returns the current timestamp/value pair if the
|
|
|
|
// value is a histogram with floating-point counts. It also works if the
|
|
|
|
// value is a histogram with integer counts, in which case a
|
|
|
|
// FloatHistogram copy of the histogram is returned. Before the iterator
|
|
|
|
// has advanced, the behaviour is unspecified.
|
|
|
|
AtFloatHistogram() (int64, *histogram.FloatHistogram)
|
|
|
|
// AtT returns the current timestamp.
|
|
|
|
// Before the iterator has advanced, the behaviour is unspecified.
|
|
|
|
AtT() int64
|
|
|
|
// Err returns the current error. It should be used only after the
|
|
|
|
// iterator is exhausted, i.e. `Next` or `Seek` have returned ValNone.
|
2020-02-06 15:58:38 +00:00
|
|
|
Err() error
|
2021-11-29 07:54:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ValueType defines the type of a value an Iterator points to.
|
|
|
|
type ValueType uint8
|
|
|
|
|
|
|
|
// Possible values for ValueType.
|
|
|
|
const (
|
|
|
|
ValNone ValueType = iota // No value at the current position.
|
|
|
|
ValFloat // A simple float, retrieved with At.
|
|
|
|
ValHistogram // A histogram, retrieve with AtHistogram, but AtFloatHistogram works, too.
|
2022-03-22 15:02:13 +00:00
|
|
|
ValFloatHistogram // A floating-point histogram, retrieve with AtFloatHistogram.
|
2021-11-29 07:54:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (v ValueType) String() string {
|
|
|
|
switch v {
|
|
|
|
case ValNone:
|
|
|
|
return "none"
|
|
|
|
case ValFloat:
|
|
|
|
return "float"
|
|
|
|
case ValHistogram:
|
|
|
|
return "histogram"
|
|
|
|
case ValFloatHistogram:
|
|
|
|
return "floathistogram"
|
|
|
|
default:
|
|
|
|
return "unknown"
|
|
|
|
}
|
2016-11-15 09:33:34 +00:00
|
|
|
}
|
2017-08-08 15:35:34 +00:00
|
|
|
|
2022-08-22 13:34:39 +00:00
|
|
|
func (v ValueType) ChunkEncoding() Encoding {
|
|
|
|
switch v {
|
|
|
|
case ValFloat:
|
|
|
|
return EncXOR
|
|
|
|
case ValHistogram:
|
|
|
|
return EncHistogram
|
2022-12-20 10:03:32 +00:00
|
|
|
case ValFloatHistogram:
|
|
|
|
return EncFloatHistogram
|
2022-08-22 13:34:39 +00:00
|
|
|
default:
|
|
|
|
return EncNone
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-29 00:16:46 +00:00
|
|
|
// MockSeriesIterator returns an iterator for a mock series with custom timeStamps and values.
|
|
|
|
func MockSeriesIterator(timestamps []int64, values []float64) Iterator {
|
|
|
|
return &mockSeriesIterator{
|
|
|
|
timeStamps: timestamps,
|
|
|
|
values: values,
|
|
|
|
currIndex: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type mockSeriesIterator struct {
|
|
|
|
timeStamps []int64
|
|
|
|
values []float64
|
|
|
|
currIndex int
|
|
|
|
}
|
|
|
|
|
2022-04-05 16:31:19 +00:00
|
|
|
func (it *mockSeriesIterator) Seek(int64) ValueType { return ValNone }
|
|
|
|
|
2022-03-29 00:16:46 +00:00
|
|
|
func (it *mockSeriesIterator) At() (int64, float64) {
|
|
|
|
return it.timeStamps[it.currIndex], it.values[it.currIndex]
|
|
|
|
}
|
|
|
|
|
2022-04-05 16:31:19 +00:00
|
|
|
func (it *mockSeriesIterator) AtHistogram() (int64, *histogram.Histogram) { return math.MinInt64, nil }
|
|
|
|
|
|
|
|
func (it *mockSeriesIterator) AtFloatHistogram() (int64, *histogram.FloatHistogram) {
|
|
|
|
return math.MinInt64, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (it *mockSeriesIterator) AtT() int64 {
|
|
|
|
return it.timeStamps[it.currIndex]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (it *mockSeriesIterator) Next() ValueType {
|
2022-03-29 00:16:46 +00:00
|
|
|
if it.currIndex < len(it.timeStamps)-1 {
|
|
|
|
it.currIndex++
|
2022-04-05 16:31:19 +00:00
|
|
|
return ValFloat
|
2022-03-29 00:16:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 16:31:19 +00:00
|
|
|
return ValNone
|
2022-03-29 00:16:46 +00:00
|
|
|
}
|
|
|
|
func (it *mockSeriesIterator) Err() error { return nil }
|
|
|
|
|
2017-10-20 07:43:52 +00:00
|
|
|
// NewNopIterator returns a new chunk iterator that does not hold any data.
|
|
|
|
func NewNopIterator() Iterator {
|
|
|
|
return nopIterator{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type nopIterator struct{}
|
|
|
|
|
2021-11-29 07:54:23 +00:00
|
|
|
func (nopIterator) Next() ValueType { return ValNone }
|
|
|
|
func (nopIterator) Seek(int64) ValueType { return ValNone }
|
|
|
|
func (nopIterator) At() (int64, float64) { return math.MinInt64, 0 }
|
|
|
|
func (nopIterator) AtHistogram() (int64, *histogram.Histogram) { return math.MinInt64, nil }
|
|
|
|
func (nopIterator) AtFloatHistogram() (int64, *histogram.FloatHistogram) { return math.MinInt64, nil }
|
|
|
|
func (nopIterator) AtT() int64 { return math.MinInt64 }
|
|
|
|
func (nopIterator) Err() error { return nil }
|
2017-10-20 07:43:52 +00:00
|
|
|
|
2019-05-06 13:47:26 +00:00
|
|
|
// Pool is used to create and reuse chunk references to avoid allocations.
|
2017-08-08 15:35:34 +00:00
|
|
|
type Pool interface {
|
|
|
|
Put(Chunk) error
|
|
|
|
Get(e Encoding, b []byte) (Chunk, error)
|
|
|
|
}
|
|
|
|
|
2019-05-06 13:47:26 +00:00
|
|
|
// pool is a memory pool of chunk objects.
|
2017-08-08 15:35:34 +00:00
|
|
|
type pool struct {
|
2022-12-20 10:03:32 +00:00
|
|
|
xor sync.Pool
|
|
|
|
histogram sync.Pool
|
|
|
|
floatHistogram sync.Pool
|
2017-08-08 15:35:34 +00:00
|
|
|
}
|
|
|
|
|
2019-05-06 13:47:26 +00:00
|
|
|
// NewPool returns a new pool.
|
2017-08-08 15:35:34 +00:00
|
|
|
func NewPool() Pool {
|
|
|
|
return &pool{
|
|
|
|
xor: sync.Pool{
|
|
|
|
New: func() interface{} {
|
2019-02-13 22:41:12 +00:00
|
|
|
return &XORChunk{b: bstream{}}
|
2017-08-08 15:35:34 +00:00
|
|
|
},
|
|
|
|
},
|
Style cleanup of all the changes in sparsehistogram so far
A lot of this code was hacked together, literally during a
hackathon. This commit intends not to change the code substantially,
but just make the code obey the usual style practices.
A (possibly incomplete) list of areas:
* Generally address linter warnings.
* The `pgk` directory is deprecated as per dev-summit. No new packages should
be added to it. I moved the new `pkg/histogram` package to `model`
anticipating what's proposed in #9478.
* Make the naming of the Sparse Histogram more consistent. Including
abbreviations, there were just too many names for it: SparseHistogram,
Histogram, Histo, hist, his, shs, h. The idea is to call it "Histogram" in
general. Only add "Sparse" if it is needed to avoid confusion with
conventional Histograms (which is rare because the TSDB really has no notion
of conventional Histograms). Use abbreviations only in local scope, and then
really abbreviate (not just removing three out of seven letters like in
"Histo"). This is in the spirit of
https://github.com/golang/go/wiki/CodeReviewComments#variable-names
* Several other minor name changes.
* A lot of formatting of doc comments. For one, following
https://github.com/golang/go/wiki/CodeReviewComments#comment-sentences
, but also layout question, anticipating how things will look like
when rendered by `godoc` (even where `godoc` doesn't render them
right now because they are for unexported types or not a doc comment
at all but just a normal code comment - consistency is queen!).
* Re-enabled `TestQueryLog` and `TestEndopints` (they pass now,
leaving them disabled was presumably an oversight).
* Bucket iterator for histogram.Histogram is now created with a
method.
* HistogramChunk.iterator now allows iterator recycling. (I think
@dieterbe only commented it out because he was confused by the
question in the comment.)
* HistogramAppender.Append panics now because we decided to treat
staleness marker differently.
Signed-off-by: beorn7 <beorn@grafana.com>
2021-10-09 13:57:07 +00:00
|
|
|
histogram: sync.Pool{
|
2021-06-29 14:38:46 +00:00
|
|
|
New: func() interface{} {
|
Style cleanup of all the changes in sparsehistogram so far
A lot of this code was hacked together, literally during a
hackathon. This commit intends not to change the code substantially,
but just make the code obey the usual style practices.
A (possibly incomplete) list of areas:
* Generally address linter warnings.
* The `pgk` directory is deprecated as per dev-summit. No new packages should
be added to it. I moved the new `pkg/histogram` package to `model`
anticipating what's proposed in #9478.
* Make the naming of the Sparse Histogram more consistent. Including
abbreviations, there were just too many names for it: SparseHistogram,
Histogram, Histo, hist, his, shs, h. The idea is to call it "Histogram" in
general. Only add "Sparse" if it is needed to avoid confusion with
conventional Histograms (which is rare because the TSDB really has no notion
of conventional Histograms). Use abbreviations only in local scope, and then
really abbreviate (not just removing three out of seven letters like in
"Histo"). This is in the spirit of
https://github.com/golang/go/wiki/CodeReviewComments#variable-names
* Several other minor name changes.
* A lot of formatting of doc comments. For one, following
https://github.com/golang/go/wiki/CodeReviewComments#comment-sentences
, but also layout question, anticipating how things will look like
when rendered by `godoc` (even where `godoc` doesn't render them
right now because they are for unexported types or not a doc comment
at all but just a normal code comment - consistency is queen!).
* Re-enabled `TestQueryLog` and `TestEndopints` (they pass now,
leaving them disabled was presumably an oversight).
* Bucket iterator for histogram.Histogram is now created with a
method.
* HistogramChunk.iterator now allows iterator recycling. (I think
@dieterbe only commented it out because he was confused by the
question in the comment.)
* HistogramAppender.Append panics now because we decided to treat
staleness marker differently.
Signed-off-by: beorn7 <beorn@grafana.com>
2021-10-09 13:57:07 +00:00
|
|
|
return &HistogramChunk{b: bstream{}}
|
2021-06-29 14:38:46 +00:00
|
|
|
},
|
|
|
|
},
|
2022-12-20 10:03:32 +00:00
|
|
|
floatHistogram: sync.Pool{
|
|
|
|
New: func() interface{} {
|
|
|
|
return &FloatHistogramChunk{b: bstream{}}
|
|
|
|
},
|
|
|
|
},
|
2017-08-08 15:35:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *pool) Get(e Encoding, b []byte) (Chunk, error) {
|
|
|
|
switch e {
|
2022-09-20 17:05:50 +00:00
|
|
|
case EncXOR, EncOOOXOR:
|
2017-08-08 15:35:34 +00:00
|
|
|
c := p.xor.Get().(*XORChunk)
|
|
|
|
c.b.stream = b
|
|
|
|
c.b.count = 0
|
|
|
|
return c, nil
|
Style cleanup of all the changes in sparsehistogram so far
A lot of this code was hacked together, literally during a
hackathon. This commit intends not to change the code substantially,
but just make the code obey the usual style practices.
A (possibly incomplete) list of areas:
* Generally address linter warnings.
* The `pgk` directory is deprecated as per dev-summit. No new packages should
be added to it. I moved the new `pkg/histogram` package to `model`
anticipating what's proposed in #9478.
* Make the naming of the Sparse Histogram more consistent. Including
abbreviations, there were just too many names for it: SparseHistogram,
Histogram, Histo, hist, his, shs, h. The idea is to call it "Histogram" in
general. Only add "Sparse" if it is needed to avoid confusion with
conventional Histograms (which is rare because the TSDB really has no notion
of conventional Histograms). Use abbreviations only in local scope, and then
really abbreviate (not just removing three out of seven letters like in
"Histo"). This is in the spirit of
https://github.com/golang/go/wiki/CodeReviewComments#variable-names
* Several other minor name changes.
* A lot of formatting of doc comments. For one, following
https://github.com/golang/go/wiki/CodeReviewComments#comment-sentences
, but also layout question, anticipating how things will look like
when rendered by `godoc` (even where `godoc` doesn't render them
right now because they are for unexported types or not a doc comment
at all but just a normal code comment - consistency is queen!).
* Re-enabled `TestQueryLog` and `TestEndopints` (they pass now,
leaving them disabled was presumably an oversight).
* Bucket iterator for histogram.Histogram is now created with a
method.
* HistogramChunk.iterator now allows iterator recycling. (I think
@dieterbe only commented it out because he was confused by the
question in the comment.)
* HistogramAppender.Append panics now because we decided to treat
staleness marker differently.
Signed-off-by: beorn7 <beorn@grafana.com>
2021-10-09 13:57:07 +00:00
|
|
|
case EncHistogram:
|
|
|
|
c := p.histogram.Get().(*HistogramChunk)
|
2021-06-29 14:38:46 +00:00
|
|
|
c.b.stream = b
|
|
|
|
c.b.count = 0
|
|
|
|
return c, nil
|
2022-12-20 10:03:32 +00:00
|
|
|
case EncFloatHistogram:
|
|
|
|
c := p.floatHistogram.Get().(*FloatHistogramChunk)
|
|
|
|
c.b.stream = b
|
|
|
|
c.b.count = 0
|
|
|
|
return c, nil
|
2017-08-08 15:35:34 +00:00
|
|
|
}
|
2020-10-28 12:03:11 +00:00
|
|
|
return nil, errors.Errorf("invalid chunk encoding %q", e)
|
2017-08-08 15:35:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *pool) Put(c Chunk) error {
|
|
|
|
switch c.Encoding() {
|
2022-09-20 17:05:50 +00:00
|
|
|
case EncXOR, EncOOOXOR:
|
2017-08-08 15:35:34 +00:00
|
|
|
xc, ok := c.(*XORChunk)
|
2017-08-09 09:10:29 +00:00
|
|
|
// This may happen often with wrapped chunks. Nothing we can really do about
|
|
|
|
// it but returning an error would cause a lot of allocations again. Thus,
|
|
|
|
// we just skip it.
|
2017-08-08 15:35:34 +00:00
|
|
|
if !ok {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
xc.b.stream = nil
|
|
|
|
xc.b.count = 0
|
|
|
|
p.xor.Put(c)
|
Style cleanup of all the changes in sparsehistogram so far
A lot of this code was hacked together, literally during a
hackathon. This commit intends not to change the code substantially,
but just make the code obey the usual style practices.
A (possibly incomplete) list of areas:
* Generally address linter warnings.
* The `pgk` directory is deprecated as per dev-summit. No new packages should
be added to it. I moved the new `pkg/histogram` package to `model`
anticipating what's proposed in #9478.
* Make the naming of the Sparse Histogram more consistent. Including
abbreviations, there were just too many names for it: SparseHistogram,
Histogram, Histo, hist, his, shs, h. The idea is to call it "Histogram" in
general. Only add "Sparse" if it is needed to avoid confusion with
conventional Histograms (which is rare because the TSDB really has no notion
of conventional Histograms). Use abbreviations only in local scope, and then
really abbreviate (not just removing three out of seven letters like in
"Histo"). This is in the spirit of
https://github.com/golang/go/wiki/CodeReviewComments#variable-names
* Several other minor name changes.
* A lot of formatting of doc comments. For one, following
https://github.com/golang/go/wiki/CodeReviewComments#comment-sentences
, but also layout question, anticipating how things will look like
when rendered by `godoc` (even where `godoc` doesn't render them
right now because they are for unexported types or not a doc comment
at all but just a normal code comment - consistency is queen!).
* Re-enabled `TestQueryLog` and `TestEndopints` (they pass now,
leaving them disabled was presumably an oversight).
* Bucket iterator for histogram.Histogram is now created with a
method.
* HistogramChunk.iterator now allows iterator recycling. (I think
@dieterbe only commented it out because he was confused by the
question in the comment.)
* HistogramAppender.Append panics now because we decided to treat
staleness marker differently.
Signed-off-by: beorn7 <beorn@grafana.com>
2021-10-09 13:57:07 +00:00
|
|
|
case EncHistogram:
|
|
|
|
sh, ok := c.(*HistogramChunk)
|
2021-06-29 14:38:46 +00:00
|
|
|
// This may happen often with wrapped chunks. Nothing we can really do about
|
|
|
|
// it but returning an error would cause a lot of allocations again. Thus,
|
|
|
|
// we just skip it.
|
|
|
|
if !ok {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
sh.b.stream = nil
|
|
|
|
sh.b.count = 0
|
Style cleanup of all the changes in sparsehistogram so far
A lot of this code was hacked together, literally during a
hackathon. This commit intends not to change the code substantially,
but just make the code obey the usual style practices.
A (possibly incomplete) list of areas:
* Generally address linter warnings.
* The `pgk` directory is deprecated as per dev-summit. No new packages should
be added to it. I moved the new `pkg/histogram` package to `model`
anticipating what's proposed in #9478.
* Make the naming of the Sparse Histogram more consistent. Including
abbreviations, there were just too many names for it: SparseHistogram,
Histogram, Histo, hist, his, shs, h. The idea is to call it "Histogram" in
general. Only add "Sparse" if it is needed to avoid confusion with
conventional Histograms (which is rare because the TSDB really has no notion
of conventional Histograms). Use abbreviations only in local scope, and then
really abbreviate (not just removing three out of seven letters like in
"Histo"). This is in the spirit of
https://github.com/golang/go/wiki/CodeReviewComments#variable-names
* Several other minor name changes.
* A lot of formatting of doc comments. For one, following
https://github.com/golang/go/wiki/CodeReviewComments#comment-sentences
, but also layout question, anticipating how things will look like
when rendered by `godoc` (even where `godoc` doesn't render them
right now because they are for unexported types or not a doc comment
at all but just a normal code comment - consistency is queen!).
* Re-enabled `TestQueryLog` and `TestEndopints` (they pass now,
leaving them disabled was presumably an oversight).
* Bucket iterator for histogram.Histogram is now created with a
method.
* HistogramChunk.iterator now allows iterator recycling. (I think
@dieterbe only commented it out because he was confused by the
question in the comment.)
* HistogramAppender.Append panics now because we decided to treat
staleness marker differently.
Signed-off-by: beorn7 <beorn@grafana.com>
2021-10-09 13:57:07 +00:00
|
|
|
p.histogram.Put(c)
|
2022-12-20 10:03:32 +00:00
|
|
|
case EncFloatHistogram:
|
|
|
|
sh, ok := c.(*FloatHistogramChunk)
|
|
|
|
// This may happen often with wrapped chunks. Nothing we can really do about
|
|
|
|
// it but returning an error would cause a lot of allocations again. Thus,
|
|
|
|
// we just skip it.
|
|
|
|
if !ok {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
sh.b.stream = nil
|
|
|
|
sh.b.count = 0
|
|
|
|
p.floatHistogram.Put(c)
|
2017-08-08 15:35:34 +00:00
|
|
|
default:
|
2020-10-28 12:03:11 +00:00
|
|
|
return errors.Errorf("invalid chunk encoding %q", c.Encoding())
|
2017-08-08 15:35:34 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2019-05-06 13:47:26 +00:00
|
|
|
|
|
|
|
// FromData returns a chunk from a byte slice of chunk data.
|
|
|
|
// This is there so that users of the library can easily create chunks from
|
|
|
|
// bytes.
|
|
|
|
func FromData(e Encoding, d []byte) (Chunk, error) {
|
|
|
|
switch e {
|
2022-09-20 17:05:50 +00:00
|
|
|
case EncXOR, EncOOOXOR:
|
2019-05-06 13:47:26 +00:00
|
|
|
return &XORChunk{b: bstream{count: 0, stream: d}}, nil
|
Style cleanup of all the changes in sparsehistogram so far
A lot of this code was hacked together, literally during a
hackathon. This commit intends not to change the code substantially,
but just make the code obey the usual style practices.
A (possibly incomplete) list of areas:
* Generally address linter warnings.
* The `pgk` directory is deprecated as per dev-summit. No new packages should
be added to it. I moved the new `pkg/histogram` package to `model`
anticipating what's proposed in #9478.
* Make the naming of the Sparse Histogram more consistent. Including
abbreviations, there were just too many names for it: SparseHistogram,
Histogram, Histo, hist, his, shs, h. The idea is to call it "Histogram" in
general. Only add "Sparse" if it is needed to avoid confusion with
conventional Histograms (which is rare because the TSDB really has no notion
of conventional Histograms). Use abbreviations only in local scope, and then
really abbreviate (not just removing three out of seven letters like in
"Histo"). This is in the spirit of
https://github.com/golang/go/wiki/CodeReviewComments#variable-names
* Several other minor name changes.
* A lot of formatting of doc comments. For one, following
https://github.com/golang/go/wiki/CodeReviewComments#comment-sentences
, but also layout question, anticipating how things will look like
when rendered by `godoc` (even where `godoc` doesn't render them
right now because they are for unexported types or not a doc comment
at all but just a normal code comment - consistency is queen!).
* Re-enabled `TestQueryLog` and `TestEndopints` (they pass now,
leaving them disabled was presumably an oversight).
* Bucket iterator for histogram.Histogram is now created with a
method.
* HistogramChunk.iterator now allows iterator recycling. (I think
@dieterbe only commented it out because he was confused by the
question in the comment.)
* HistogramAppender.Append panics now because we decided to treat
staleness marker differently.
Signed-off-by: beorn7 <beorn@grafana.com>
2021-10-09 13:57:07 +00:00
|
|
|
case EncHistogram:
|
|
|
|
return &HistogramChunk{b: bstream{count: 0, stream: d}}, nil
|
2022-12-20 10:03:32 +00:00
|
|
|
case EncFloatHistogram:
|
|
|
|
return &FloatHistogramChunk{b: bstream{count: 0, stream: d}}, nil
|
2021-06-29 14:38:46 +00:00
|
|
|
}
|
|
|
|
return nil, errors.Errorf("invalid chunk encoding %q", e)
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewEmptyChunk returns an empty chunk for the given encoding.
|
|
|
|
func NewEmptyChunk(e Encoding) (Chunk, error) {
|
|
|
|
switch e {
|
|
|
|
case EncXOR:
|
|
|
|
return NewXORChunk(), nil
|
Style cleanup of all the changes in sparsehistogram so far
A lot of this code was hacked together, literally during a
hackathon. This commit intends not to change the code substantially,
but just make the code obey the usual style practices.
A (possibly incomplete) list of areas:
* Generally address linter warnings.
* The `pgk` directory is deprecated as per dev-summit. No new packages should
be added to it. I moved the new `pkg/histogram` package to `model`
anticipating what's proposed in #9478.
* Make the naming of the Sparse Histogram more consistent. Including
abbreviations, there were just too many names for it: SparseHistogram,
Histogram, Histo, hist, his, shs, h. The idea is to call it "Histogram" in
general. Only add "Sparse" if it is needed to avoid confusion with
conventional Histograms (which is rare because the TSDB really has no notion
of conventional Histograms). Use abbreviations only in local scope, and then
really abbreviate (not just removing three out of seven letters like in
"Histo"). This is in the spirit of
https://github.com/golang/go/wiki/CodeReviewComments#variable-names
* Several other minor name changes.
* A lot of formatting of doc comments. For one, following
https://github.com/golang/go/wiki/CodeReviewComments#comment-sentences
, but also layout question, anticipating how things will look like
when rendered by `godoc` (even where `godoc` doesn't render them
right now because they are for unexported types or not a doc comment
at all but just a normal code comment - consistency is queen!).
* Re-enabled `TestQueryLog` and `TestEndopints` (they pass now,
leaving them disabled was presumably an oversight).
* Bucket iterator for histogram.Histogram is now created with a
method.
* HistogramChunk.iterator now allows iterator recycling. (I think
@dieterbe only commented it out because he was confused by the
question in the comment.)
* HistogramAppender.Append panics now because we decided to treat
staleness marker differently.
Signed-off-by: beorn7 <beorn@grafana.com>
2021-10-09 13:57:07 +00:00
|
|
|
case EncHistogram:
|
|
|
|
return NewHistogramChunk(), nil
|
2022-12-20 10:03:32 +00:00
|
|
|
case EncFloatHistogram:
|
|
|
|
return NewFloatHistogramChunk(), nil
|
2019-05-06 13:47:26 +00:00
|
|
|
}
|
2020-10-28 12:03:11 +00:00
|
|
|
return nil, errors.Errorf("invalid chunk encoding %q", e)
|
2019-05-06 13:47:26 +00:00
|
|
|
}
|