未验证 提交 8c9850c2 编写于 作者: J Julien Pivotto 提交者: GitHub

Remote: Do not collect non-initialized timestamp metrics (#8060)

* Remote: Do not collect non-initialized timestamp metrics
Signed-off-by: NJulien Pivotto <roidelapluie@inuits.eu>
上级 9981b3f3
......@@ -19,13 +19,13 @@ import (
"github.com/prometheus/client_golang/prometheus"
)
type maxGauge struct {
type maxTimestamp struct {
mtx sync.Mutex
value float64
prometheus.Gauge
}
func (m *maxGauge) Set(value float64) {
func (m *maxTimestamp) Set(value float64) {
m.mtx.Lock()
defer m.mtx.Unlock()
if value > m.value {
......@@ -34,8 +34,14 @@ func (m *maxGauge) Set(value float64) {
}
}
func (m *maxGauge) Get() float64 {
func (m *maxTimestamp) Get() float64 {
m.mtx.Lock()
defer m.mtx.Unlock()
return m.value
}
func (m *maxTimestamp) Collect(c chan<- prometheus.Metric) {
if m.Get() > 0 {
m.Gauge.Collect(c)
}
}
......@@ -56,7 +56,7 @@ type queueManagerMetrics struct {
droppedSamplesTotal prometheus.Counter
enqueueRetriesTotal prometheus.Counter
sentBatchDuration prometheus.Histogram
highestSentTimestamp *maxGauge
highestSentTimestamp *maxTimestamp
pendingSamples prometheus.Gauge
shardCapacity prometheus.Gauge
numShards prometheus.Gauge
......@@ -118,7 +118,7 @@ func newQueueManagerMetrics(r prometheus.Registerer, rn, e string) *queueManager
Buckets: append(prometheus.DefBuckets, 25, 60, 120, 300),
ConstLabels: constLabels,
})
m.highestSentTimestamp = &maxGauge{
m.highestSentTimestamp = &maxTimestamp{
Gauge: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subsystem,
......@@ -262,7 +262,7 @@ type QueueManager struct {
metrics *queueManagerMetrics
interner *pool
highestRecvTimestamp *maxGauge
highestRecvTimestamp *maxTimestamp
}
// NewQueueManager builds a new QueueManager.
......@@ -279,7 +279,7 @@ func NewQueueManager(
client WriteClient,
flushDeadline time.Duration,
interner *pool,
highestRecvTimestamp *maxGauge,
highestRecvTimestamp *maxTimestamp,
) *QueueManager {
if logger == nil {
logger = log.NewNopLogger()
......
......@@ -47,8 +47,8 @@ import (
const defaultFlushDeadline = 1 * time.Minute
func newHighestTimestampMetric() *maxGauge {
return &maxGauge{
func newHighestTimestampMetric() *maxTimestamp {
return &maxTimestamp{
Gauge: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subsystem,
......
......@@ -53,7 +53,7 @@ type WriteStorage struct {
interner *pool
// For timestampTracker.
highestTimestamp *maxGauge
highestTimestamp *maxTimestamp
}
// NewWriteStorage creates and runs a WriteStorage.
......@@ -71,7 +71,7 @@ func NewWriteStorage(logger log.Logger, reg prometheus.Registerer, walDir string
samplesIn: newEWMARate(ewmaWeight, shardUpdateDuration),
walDir: walDir,
interner: newPool(),
highestTimestamp: &maxGauge{
highestTimestamp: &maxTimestamp{
Gauge: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subsystem,
......@@ -202,7 +202,7 @@ type timestampTracker struct {
writeStorage *WriteStorage
samples int64
highestTimestamp int64
highestRecvTimestamp *maxGauge
highestRecvTimestamp *maxTimestamp
}
// Add implements storage.Appender.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册