mirror of
https://github.com/prometheus/prometheus.git
synced 2026-05-28 04:02:21 -04:00
[BUGFIX] Agent: fix crash from invalid type in pool (#17802)
We have separate pools for Appender and AppenderV2 objects, and must not put another kind of object into them. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
cd875bd8c9
commit
f1719fa1d4
4 changed files with 29 additions and 4 deletions
|
|
@ -1124,13 +1124,22 @@ func (a *appender) AppendSTZeroSample(ref storage.SeriesRef, l labels.Labels, t,
|
|||
}
|
||||
|
||||
// Commit submits the collected samples and purges the batch.
|
||||
func (a *appenderBase) Commit() error {
|
||||
func (a *appender) Commit() error {
|
||||
defer a.appenderPool.Put(a)
|
||||
return a.commit()
|
||||
}
|
||||
|
||||
func (a *appender) Rollback() error {
|
||||
defer a.appenderPool.Put(a)
|
||||
return a.rollback()
|
||||
}
|
||||
|
||||
func (a *appenderBase) commit() error {
|
||||
if err := a.log(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
a.clearData()
|
||||
a.appenderPool.Put(a)
|
||||
|
||||
if a.writeNotified != nil {
|
||||
a.writeNotified.Notify()
|
||||
|
|
@ -1244,7 +1253,7 @@ func (a *appenderBase) clearData() {
|
|||
a.floatHistogramSeries = a.floatHistogramSeries[:0]
|
||||
}
|
||||
|
||||
func (a *appenderBase) Rollback() error {
|
||||
func (a *appenderBase) rollback() error {
|
||||
// Series are created in-memory regardless of rollback. This means we must
|
||||
// log them to the WAL, otherwise subsequent commits may reference a series
|
||||
// which was never written to the WAL.
|
||||
|
|
@ -1253,7 +1262,6 @@ func (a *appenderBase) Rollback() error {
|
|||
}
|
||||
|
||||
a.clearData()
|
||||
a.appenderPool.Put(a)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -127,6 +127,16 @@ func (a *appenderV2) Append(ref storage.SeriesRef, ls labels.Labels, st, t int64
|
|||
return storage.SeriesRef(s.ref), partialErr
|
||||
}
|
||||
|
||||
func (a *appenderV2) Commit() error {
|
||||
defer a.appenderV2Pool.Put(a)
|
||||
return a.commit()
|
||||
}
|
||||
|
||||
func (a *appenderV2) Rollback() error {
|
||||
defer a.appenderV2Pool.Put(a)
|
||||
return a.rollback()
|
||||
}
|
||||
|
||||
func (a *appenderV2) appendExemplars(s *memSeries, exemplar []exemplar.Exemplar) error {
|
||||
var errs []error
|
||||
for _, e := range exemplar {
|
||||
|
|
|
|||
|
|
@ -224,6 +224,10 @@ func TestCommit_AppendV2(t *testing.T) {
|
|||
require.Equal(t, numSeries*numDatapoints, walExemplarsCount, "unexpected number of exemplars")
|
||||
require.Equal(t, numSeries*numHistograms*2, walHistogramCount, "unexpected number of histograms")
|
||||
require.Equal(t, numSeries*numHistograms*2, walFloatHistogramCount, "unexpected number of float histograms")
|
||||
|
||||
// Check that we can still create both kinds of Appender - see https://github.com/prometheus/prometheus/issues/17800.
|
||||
_ = s.Appender(context.TODO())
|
||||
_ = s.AppenderV2(context.TODO())
|
||||
}
|
||||
|
||||
func TestRollback_AppendV2(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -259,6 +259,9 @@ func TestCommit(t *testing.T) {
|
|||
require.Equal(t, numSeries*numDatapoints, walExemplarsCount, "unexpected number of exemplars")
|
||||
require.Equal(t, numSeries*numHistograms*2, walHistogramCount, "unexpected number of histograms")
|
||||
require.Equal(t, numSeries*numHistograms*2, walFloatHistogramCount, "unexpected number of float histograms")
|
||||
|
||||
// Check that we can get another appender after this - see https://github.com/prometheus/prometheus/issues/17800.
|
||||
_ = s.Appender(context.TODO())
|
||||
}
|
||||
|
||||
func TestRollback(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue