TSDB: do not allocate exemplars buffer if exemplars are disabled (#8746)

Signed-off-by: Marco Pracucci <marco@pracucci.com>
This commit is contained in:
Marco Pracucci 2021-04-21 16:32:21 +02:00 committed by GitHub
parent 896f37f1a5
commit 52df5ef7a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1086,7 +1086,7 @@ func (a *initAppender) Append(ref uint64, lset labels.Labels, t int64, v float64
func (a *initAppender) AppendExemplar(ref uint64, l labels.Labels, e exemplar.Exemplar) (uint64, error) { func (a *initAppender) AppendExemplar(ref uint64, l labels.Labels, e exemplar.Exemplar) (uint64, error) {
// Check if exemplar storage is enabled. // Check if exemplar storage is enabled.
if a.head.opts.NumExemplars == 0 { if a.head.opts.NumExemplars <= 0 {
return 0, nil return 0, nil
} }
@ -1142,6 +1142,12 @@ func (h *Head) appender() *headAppender {
appendID := h.iso.newAppendID() appendID := h.iso.newAppendID()
cleanupAppendIDsBelow := h.iso.lowWatermark() cleanupAppendIDsBelow := h.iso.lowWatermark()
// Allocate the exemplars buffer only if exemplars are enabled.
var exemplarsBuf []exemplarWithSeriesRef
if h.opts.NumExemplars > 0 {
exemplarsBuf = h.getExemplarBuffer()
}
return &headAppender{ return &headAppender{
head: h, head: h,
minValidTime: h.appendableMinValidTime(), minValidTime: h.appendableMinValidTime(),
@ -1149,7 +1155,7 @@ func (h *Head) appender() *headAppender {
maxt: math.MinInt64, maxt: math.MinInt64,
samples: h.getAppendBuffer(), samples: h.getAppendBuffer(),
sampleSeries: h.getSeriesBuffer(), sampleSeries: h.getSeriesBuffer(),
exemplars: h.getExemplarBuffer(), exemplars: exemplarsBuf,
appendID: appendID, appendID: appendID,
cleanupAppendIDsBelow: cleanupAppendIDsBelow, cleanupAppendIDsBelow: cleanupAppendIDsBelow,
exemplarAppender: h.exemplars, exemplarAppender: h.exemplars,
@ -1204,6 +1210,10 @@ func (h *Head) getExemplarBuffer() []exemplarWithSeriesRef {
} }
func (h *Head) putExemplarBuffer(b []exemplarWithSeriesRef) { func (h *Head) putExemplarBuffer(b []exemplarWithSeriesRef) {
if b == nil {
return
}
//nolint:staticcheck // Ignore SA6002 safe to ignore and actually fixing it has some performance penalty. //nolint:staticcheck // Ignore SA6002 safe to ignore and actually fixing it has some performance penalty.
h.exemplarsPool.Put(b[:0]) h.exemplarsPool.Put(b[:0])
} }
@ -1317,7 +1327,7 @@ func (a *headAppender) Append(ref uint64, lset labels.Labels, t int64, v float64
// use getOrCreate or make any of the lset sanity checks that Append does. // use getOrCreate or make any of the lset sanity checks that Append does.
func (a *headAppender) AppendExemplar(ref uint64, _ labels.Labels, e exemplar.Exemplar) (uint64, error) { func (a *headAppender) AppendExemplar(ref uint64, _ labels.Labels, e exemplar.Exemplar) (uint64, error) {
// Check if exemplar storage is enabled. // Check if exemplar storage is enabled.
if a.head.opts.NumExemplars == 0 { if a.head.opts.NumExemplars <= 0 {
return 0, nil return 0, nil
} }