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