mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Remote: Do not collect non-initialized timestamp metrics (#8060)
* Remote: Do not collect non-initialized timestamp metrics Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
parent
9981b3f3ee
commit
8c9850c2bb
|
@ -19,13 +19,13 @@ import (
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
type maxGauge struct {
|
type maxTimestamp struct {
|
||||||
mtx sync.Mutex
|
mtx sync.Mutex
|
||||||
value float64
|
value float64
|
||||||
prometheus.Gauge
|
prometheus.Gauge
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *maxGauge) Set(value float64) {
|
func (m *maxTimestamp) Set(value float64) {
|
||||||
m.mtx.Lock()
|
m.mtx.Lock()
|
||||||
defer m.mtx.Unlock()
|
defer m.mtx.Unlock()
|
||||||
if value > m.value {
|
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()
|
m.mtx.Lock()
|
||||||
defer m.mtx.Unlock()
|
defer m.mtx.Unlock()
|
||||||
return m.value
|
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
|
droppedSamplesTotal prometheus.Counter
|
||||||
enqueueRetriesTotal prometheus.Counter
|
enqueueRetriesTotal prometheus.Counter
|
||||||
sentBatchDuration prometheus.Histogram
|
sentBatchDuration prometheus.Histogram
|
||||||
highestSentTimestamp *maxGauge
|
highestSentTimestamp *maxTimestamp
|
||||||
pendingSamples prometheus.Gauge
|
pendingSamples prometheus.Gauge
|
||||||
shardCapacity prometheus.Gauge
|
shardCapacity prometheus.Gauge
|
||||||
numShards 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),
|
Buckets: append(prometheus.DefBuckets, 25, 60, 120, 300),
|
||||||
ConstLabels: constLabels,
|
ConstLabels: constLabels,
|
||||||
})
|
})
|
||||||
m.highestSentTimestamp = &maxGauge{
|
m.highestSentTimestamp = &maxTimestamp{
|
||||||
Gauge: prometheus.NewGauge(prometheus.GaugeOpts{
|
Gauge: prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
Subsystem: subsystem,
|
Subsystem: subsystem,
|
||||||
|
@ -262,7 +262,7 @@ type QueueManager struct {
|
||||||
|
|
||||||
metrics *queueManagerMetrics
|
metrics *queueManagerMetrics
|
||||||
interner *pool
|
interner *pool
|
||||||
highestRecvTimestamp *maxGauge
|
highestRecvTimestamp *maxTimestamp
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewQueueManager builds a new QueueManager.
|
// NewQueueManager builds a new QueueManager.
|
||||||
|
@ -279,7 +279,7 @@ func NewQueueManager(
|
||||||
client WriteClient,
|
client WriteClient,
|
||||||
flushDeadline time.Duration,
|
flushDeadline time.Duration,
|
||||||
interner *pool,
|
interner *pool,
|
||||||
highestRecvTimestamp *maxGauge,
|
highestRecvTimestamp *maxTimestamp,
|
||||||
) *QueueManager {
|
) *QueueManager {
|
||||||
if logger == nil {
|
if logger == nil {
|
||||||
logger = log.NewNopLogger()
|
logger = log.NewNopLogger()
|
||||||
|
|
|
@ -47,8 +47,8 @@ import (
|
||||||
|
|
||||||
const defaultFlushDeadline = 1 * time.Minute
|
const defaultFlushDeadline = 1 * time.Minute
|
||||||
|
|
||||||
func newHighestTimestampMetric() *maxGauge {
|
func newHighestTimestampMetric() *maxTimestamp {
|
||||||
return &maxGauge{
|
return &maxTimestamp{
|
||||||
Gauge: prometheus.NewGauge(prometheus.GaugeOpts{
|
Gauge: prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
Subsystem: subsystem,
|
Subsystem: subsystem,
|
||||||
|
|
|
@ -53,7 +53,7 @@ type WriteStorage struct {
|
||||||
interner *pool
|
interner *pool
|
||||||
|
|
||||||
// For timestampTracker.
|
// For timestampTracker.
|
||||||
highestTimestamp *maxGauge
|
highestTimestamp *maxTimestamp
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWriteStorage creates and runs a WriteStorage.
|
// NewWriteStorage creates and runs a WriteStorage.
|
||||||
|
@ -71,7 +71,7 @@ func NewWriteStorage(logger log.Logger, reg prometheus.Registerer, walDir string
|
||||||
samplesIn: newEWMARate(ewmaWeight, shardUpdateDuration),
|
samplesIn: newEWMARate(ewmaWeight, shardUpdateDuration),
|
||||||
walDir: walDir,
|
walDir: walDir,
|
||||||
interner: newPool(),
|
interner: newPool(),
|
||||||
highestTimestamp: &maxGauge{
|
highestTimestamp: &maxTimestamp{
|
||||||
Gauge: prometheus.NewGauge(prometheus.GaugeOpts{
|
Gauge: prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
Subsystem: subsystem,
|
Subsystem: subsystem,
|
||||||
|
@ -202,7 +202,7 @@ type timestampTracker struct {
|
||||||
writeStorage *WriteStorage
|
writeStorage *WriteStorage
|
||||||
samples int64
|
samples int64
|
||||||
highestTimestamp int64
|
highestTimestamp int64
|
||||||
highestRecvTimestamp *maxGauge
|
highestRecvTimestamp *maxTimestamp
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add implements storage.Appender.
|
// Add implements storage.Appender.
|
||||||
|
|
Loading…
Reference in a new issue