mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Fix histogram append errors (#13201)
* Fix histogram append errors We should check counterReset condition rather than okToAppend because if there's a counter reset, okToAppend is always set to false. Signed-off-by: Fiona Liao <fiona.y.liao@gmail.com>
This commit is contained in:
parent
ce126230e7
commit
b8bcaef14d
|
@ -605,10 +605,10 @@ func (a *FloatHistogramAppender) AppendFloatHistogram(prev *FloatHistogramAppend
|
||||||
pForwardInserts, nForwardInserts, okToAppend, counterReset := a.appendable(h)
|
pForwardInserts, nForwardInserts, okToAppend, counterReset := a.appendable(h)
|
||||||
if !okToAppend || counterReset {
|
if !okToAppend || counterReset {
|
||||||
if appendOnly {
|
if appendOnly {
|
||||||
if !okToAppend {
|
if counterReset {
|
||||||
return nil, false, a, fmt.Errorf("float histogram schema change")
|
return nil, false, a, fmt.Errorf("float histogram counter reset")
|
||||||
}
|
}
|
||||||
return nil, false, a, fmt.Errorf("float histogram counter reset")
|
return nil, false, a, fmt.Errorf("float histogram schema change")
|
||||||
}
|
}
|
||||||
newChunk := NewFloatHistogramChunk()
|
newChunk := NewFloatHistogramChunk()
|
||||||
app, err := newChunk.Appender()
|
app, err := newChunk.Appender()
|
||||||
|
|
|
@ -19,6 +19,7 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/prometheus/prometheus/model/histogram"
|
"github.com/prometheus/prometheus/model/histogram"
|
||||||
|
"github.com/prometheus/prometheus/tsdb/tsdbutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
type floatResult struct {
|
type floatResult struct {
|
||||||
|
@ -928,3 +929,50 @@ func TestFloatHistogramChunkAppendableGauge(t *testing.T) {
|
||||||
assertRecodedFloatHistogramChunkOnAppend(t, c, hApp, ts+1, h2, GaugeType)
|
assertRecodedFloatHistogramChunkOnAppend(t, c, hApp, ts+1, h2, GaugeType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFloatHistogramAppendOnlyErrors(t *testing.T) {
|
||||||
|
t.Run("schema change error", func(t *testing.T) {
|
||||||
|
c := Chunk(NewFloatHistogramChunk())
|
||||||
|
|
||||||
|
// Create fresh appender and add the first histogram.
|
||||||
|
app, err := c.Appender()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
h := tsdbutil.GenerateTestFloatHistogram(0)
|
||||||
|
var isRecoded bool
|
||||||
|
c, isRecoded, app, err = app.AppendFloatHistogram(nil, 1, h, true)
|
||||||
|
require.Nil(t, c)
|
||||||
|
require.False(t, isRecoded)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Add erroring histogram.
|
||||||
|
h2 := h.Copy()
|
||||||
|
h2.Schema++
|
||||||
|
c, isRecoded, _, err = app.AppendFloatHistogram(nil, 2, h2, true)
|
||||||
|
require.Nil(t, c)
|
||||||
|
require.False(t, isRecoded)
|
||||||
|
require.EqualError(t, err, "float histogram schema change")
|
||||||
|
})
|
||||||
|
t.Run("counter reset error", func(t *testing.T) {
|
||||||
|
c := Chunk(NewFloatHistogramChunk())
|
||||||
|
|
||||||
|
// Create fresh appender and add the first histogram.
|
||||||
|
app, err := c.Appender()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
h := tsdbutil.GenerateTestFloatHistogram(0)
|
||||||
|
var isRecoded bool
|
||||||
|
c, isRecoded, app, err = app.AppendFloatHistogram(nil, 1, h, true)
|
||||||
|
require.Nil(t, c)
|
||||||
|
require.False(t, isRecoded)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Add erroring histogram.
|
||||||
|
h2 := h.Copy()
|
||||||
|
h2.CounterResetHint = histogram.CounterReset
|
||||||
|
c, isRecoded, _, err = app.AppendFloatHistogram(nil, 2, h2, true)
|
||||||
|
require.Nil(t, c)
|
||||||
|
require.False(t, isRecoded)
|
||||||
|
require.EqualError(t, err, "float histogram counter reset")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -640,10 +640,10 @@ func (a *HistogramAppender) AppendHistogram(prev *HistogramAppender, t int64, h
|
||||||
pForwardInserts, nForwardInserts, okToAppend, counterReset := a.appendable(h)
|
pForwardInserts, nForwardInserts, okToAppend, counterReset := a.appendable(h)
|
||||||
if !okToAppend || counterReset {
|
if !okToAppend || counterReset {
|
||||||
if appendOnly {
|
if appendOnly {
|
||||||
if !okToAppend {
|
if counterReset {
|
||||||
return nil, false, a, fmt.Errorf("histogram schema change")
|
return nil, false, a, fmt.Errorf("histogram counter reset")
|
||||||
}
|
}
|
||||||
return nil, false, a, fmt.Errorf("histogram counter reset")
|
return nil, false, a, fmt.Errorf("histogram schema change")
|
||||||
}
|
}
|
||||||
newChunk := NewHistogramChunk()
|
newChunk := NewHistogramChunk()
|
||||||
app, err := newChunk.Appender()
|
app, err := newChunk.Appender()
|
||||||
|
|
|
@ -19,6 +19,7 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/prometheus/prometheus/model/histogram"
|
"github.com/prometheus/prometheus/model/histogram"
|
||||||
|
"github.com/prometheus/prometheus/tsdb/tsdbutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
type result struct {
|
type result struct {
|
||||||
|
@ -1129,3 +1130,50 @@ func TestHistogramChunkAppendableGauge(t *testing.T) {
|
||||||
require.Equal(t, GaugeType, c.(*HistogramChunk).GetCounterResetHeader())
|
require.Equal(t, GaugeType, c.(*HistogramChunk).GetCounterResetHeader())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHistogramAppendOnlyErrors(t *testing.T) {
|
||||||
|
t.Run("schema change error", func(t *testing.T) {
|
||||||
|
c := Chunk(NewHistogramChunk())
|
||||||
|
|
||||||
|
// Create fresh appender and add the first histogram.
|
||||||
|
app, err := c.Appender()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
h := tsdbutil.GenerateTestHistogram(0)
|
||||||
|
var isRecoded bool
|
||||||
|
c, isRecoded, app, err = app.AppendHistogram(nil, 1, h, true)
|
||||||
|
require.Nil(t, c)
|
||||||
|
require.False(t, isRecoded)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Add erroring histogram.
|
||||||
|
h2 := h.Copy()
|
||||||
|
h2.Schema++
|
||||||
|
c, isRecoded, _, err = app.AppendHistogram(nil, 2, h2, true)
|
||||||
|
require.Nil(t, c)
|
||||||
|
require.False(t, isRecoded)
|
||||||
|
require.EqualError(t, err, "histogram schema change")
|
||||||
|
})
|
||||||
|
t.Run("counter reset error", func(t *testing.T) {
|
||||||
|
c := Chunk(NewHistogramChunk())
|
||||||
|
|
||||||
|
// Create fresh appender and add the first histogram.
|
||||||
|
app, err := c.Appender()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
h := tsdbutil.GenerateTestHistogram(0)
|
||||||
|
var isRecoded bool
|
||||||
|
c, isRecoded, app, err = app.AppendHistogram(nil, 1, h, true)
|
||||||
|
require.Nil(t, c)
|
||||||
|
require.False(t, isRecoded)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Add erroring histogram.
|
||||||
|
h2 := h.Copy()
|
||||||
|
h2.CounterResetHint = histogram.CounterReset
|
||||||
|
c, isRecoded, _, err = app.AppendHistogram(nil, 2, h2, true)
|
||||||
|
require.Nil(t, c)
|
||||||
|
require.False(t, isRecoded)
|
||||||
|
require.EqualError(t, err, "histogram counter reset")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue