2020-02-23 11:35:47 +00:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
|
2020-11-07 14:16:56 +00:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promrelabel"
|
2020-02-23 11:35:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// PushCtx is a context used for populating WriteRequest.
|
|
|
|
type PushCtx struct {
|
2024-04-20 19:27:03 +00:00
|
|
|
// WriteRequest contains the WriteRequest, which must be pushed later to remote storage.
|
|
|
|
//
|
|
|
|
// The actual labels and samples for the time series are stored in Labels and Samples fields.
|
2020-02-23 11:35:47 +00:00
|
|
|
WriteRequest prompbmarshal.WriteRequest
|
|
|
|
|
|
|
|
// Labels contains flat list of all the labels used in WriteRequest.
|
|
|
|
Labels []prompbmarshal.Label
|
|
|
|
|
|
|
|
// Samples contains flat list of all the samples used in WriteRequest.
|
|
|
|
Samples []prompbmarshal.Sample
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset resets ctx.
|
|
|
|
func (ctx *PushCtx) Reset() {
|
2024-04-20 19:00:00 +00:00
|
|
|
ctx.WriteRequest.Reset()
|
2020-02-23 11:35:47 +00:00
|
|
|
|
2020-11-07 14:16:56 +00:00
|
|
|
promrelabel.CleanLabels(ctx.Labels)
|
2020-02-23 11:35:47 +00:00
|
|
|
ctx.Labels = ctx.Labels[:0]
|
|
|
|
|
|
|
|
ctx.Samples = ctx.Samples[:0]
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetPushCtx returns PushCtx from pool.
|
|
|
|
//
|
|
|
|
// Call PutPushCtx when the ctx is no longer needed.
|
|
|
|
func GetPushCtx() *PushCtx {
|
2024-04-20 19:27:03 +00:00
|
|
|
if v := pushCtxPool.Get(); v != nil {
|
|
|
|
return v.(*PushCtx)
|
2020-02-23 11:35:47 +00:00
|
|
|
}
|
2024-04-20 19:27:03 +00:00
|
|
|
return &PushCtx{}
|
2020-02-23 11:35:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// PutPushCtx returns ctx to the pool.
|
|
|
|
//
|
|
|
|
// ctx mustn't be used after returning to the pool.
|
|
|
|
func PutPushCtx(ctx *PushCtx) {
|
|
|
|
ctx.Reset()
|
2024-04-20 19:27:03 +00:00
|
|
|
pushCtxPool.Put(ctx)
|
2020-02-23 11:35:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var pushCtxPool sync.Pool
|