mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-21 03:16:00 -08:00
Explicit schema check in [Float]Histogram.ReduceResolution
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
This commit is contained in:
parent
965e603fa7
commit
ea1862aab4
|
@ -1110,6 +1110,10 @@ func floatBucketsMatch(b1, b2 []float64) bool {
|
||||||
// ReduceResolution reduces the float histogram's spans, buckets into target schema.
|
// ReduceResolution reduces the float histogram's spans, buckets into target schema.
|
||||||
// The target schema must be smaller than the current float histogram's schema.
|
// The target schema must be smaller than the current float histogram's schema.
|
||||||
func (h *FloatHistogram) ReduceResolution(targetSchema int32) *FloatHistogram {
|
func (h *FloatHistogram) ReduceResolution(targetSchema int32) *FloatHistogram {
|
||||||
|
if targetSchema >= h.Schema {
|
||||||
|
panic(fmt.Errorf("cannot reduce resolution from schema %d to %d", h.Schema, targetSchema))
|
||||||
|
}
|
||||||
|
|
||||||
h.PositiveSpans, h.PositiveBuckets = reduceResolution(h.PositiveSpans, h.PositiveBuckets, h.Schema, targetSchema, false)
|
h.PositiveSpans, h.PositiveBuckets = reduceResolution(h.PositiveSpans, h.PositiveBuckets, h.Schema, targetSchema, false)
|
||||||
h.NegativeSpans, h.NegativeBuckets = reduceResolution(h.NegativeSpans, h.NegativeBuckets, h.Schema, targetSchema, false)
|
h.NegativeSpans, h.NegativeBuckets = reduceResolution(h.NegativeSpans, h.NegativeBuckets, h.Schema, targetSchema, false)
|
||||||
h.Schema = targetSchema
|
h.Schema = targetSchema
|
||||||
|
|
|
@ -497,6 +497,10 @@ func (c *cumulativeBucketIterator) At() Bucket[uint64] {
|
||||||
// ReduceResolution reduces the histogram's spans, buckets into target schema.
|
// ReduceResolution reduces the histogram's spans, buckets into target schema.
|
||||||
// The target schema must be smaller than the current histogram's schema.
|
// The target schema must be smaller than the current histogram's schema.
|
||||||
func (h *Histogram) ReduceResolution(targetSchema int32) *Histogram {
|
func (h *Histogram) ReduceResolution(targetSchema int32) *Histogram {
|
||||||
|
if targetSchema >= h.Schema {
|
||||||
|
panic(fmt.Errorf("cannot reduce resolution from schema %d to %d", h.Schema, targetSchema))
|
||||||
|
}
|
||||||
|
|
||||||
h.PositiveSpans, h.PositiveBuckets = reduceResolution(
|
h.PositiveSpans, h.PositiveBuckets = reduceResolution(
|
||||||
h.PositiveSpans, h.PositiveBuckets, h.Schema, targetSchema, true,
|
h.PositiveSpans, h.PositiveBuckets, h.Schema, targetSchema, true,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue