mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-15 16:30:55 +01:00
lib/storage: remove possible data race when logging dropped labels
This commit is contained in:
parent
dcac849c1f
commit
e228f479a5
@ -8,10 +8,10 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/bytesutil"
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/encoding"
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/fasttime"
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompb"
|
||||
)
|
||||
@ -567,21 +567,16 @@ var (
|
||||
|
||||
func trackDroppedLabels(labels, droppedLabels []prompb.Label) {
|
||||
atomic.AddUint64(&MetricsWithDroppedLabels, 1)
|
||||
ct := fasttime.UnixTimestamp()
|
||||
if ct < atomic.LoadUint64(&droppedLabelsLogNextTimestamp) {
|
||||
return
|
||||
}
|
||||
droppedLabelsLogOnce.Do(func() {
|
||||
atomic.StoreUint64(&droppedLabelsLogNextTimestamp, ct+5)
|
||||
select {
|
||||
case <-droppedLabelsLogTicker.C:
|
||||
logger.Warnf("dropping %d labels for %s; dropped labels: %s; either reduce the number of labels for this metric "+
|
||||
"or increase -maxLabelsPerTimeseries=%d command-line flag value",
|
||||
len(droppedLabels), labelsToString(labels), labelsToString(droppedLabels), maxLabelsPerTimeseries)
|
||||
droppedLabelsLogOnce = &sync.Once{}
|
||||
})
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
var droppedLabelsLogOnce = &sync.Once{}
|
||||
var droppedLabelsLogNextTimestamp uint64
|
||||
var droppedLabelsLogTicker = time.NewTicker(5 * time.Second)
|
||||
|
||||
func labelsToString(labels []prompb.Label) string {
|
||||
labelsCopy := append([]prompb.Label{}, labels...)
|
||||
|
Loading…
Reference in New Issue
Block a user