Skip to content

Commit dfdae23

Browse files
committed
add debug logs && fix too old sample
1 parent e3601c8 commit dfdae23

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

plugin/output/prometheus/metric_collector.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,28 @@ func (p *metricCollector) handleMetric(labels []promwrite.Label, value float64,
6868
shouldSend = prevTimestampSec < currentTimestampSec
6969

7070
if shouldSend {
71+
prevMetric.timestamp = max(prevMetric.timestamp, timestamp-1_000_000_000)
72+
73+
zapLabels := make([]zap.Field, 0, len(labels)+2)
74+
timeMetric := time.Unix(0, prevMetric.timestamp)
75+
76+
zapLabels = append(zapLabels, zap.Time("prom_timestamp", timeMetric))
77+
zapLabels = append(zapLabels, zap.Time("current_timestamp", time.Unix(0, timestamp)))
78+
for i := range labels {
79+
zapLabels = append(zapLabels, zap.String("prom_label_"+labels[i].Name, labels[i].Value))
80+
}
81+
p.logger.Info(
82+
"send metric",
83+
zapLabels...,
84+
)
85+
86+
if time.Since(timeMetric) > 5*time.Minute {
87+
p.logger.Error(
88+
"too old sample",
89+
zapLabels...,
90+
)
91+
}
92+
7193
values = append(values, createTimeSeries(labels, prevMetric))
7294
}
7395
} else {
@@ -97,6 +119,26 @@ func (p *metricCollector) flushOldMetrics() {
97119
metric := value.(metricValue)
98120
if now.Sub(metric.lastUpdateTime) > p.timeout && !metric.lastValueIsSended {
99121
labels := keyToLabels(key.(string))
122+
123+
zapLabels := make([]zap.Field, 0, len(labels)+2)
124+
timeMetric := time.Unix(0, metric.timestamp)
125+
zapLabels = append(zapLabels, zap.Time("prom_timestamp", timeMetric))
126+
zapLabels = append(zapLabels, zap.Bool("flush_old_metric", true))
127+
for i := range labels {
128+
zapLabels = append(zapLabels, zap.String("prom_label_"+labels[i].Name, labels[i].Value))
129+
}
130+
p.logger.Info(
131+
"send metric",
132+
zapLabels...,
133+
)
134+
135+
if time.Since(timeMetric) > 10*time.Minute {
136+
p.logger.Error(
137+
"too old sample",
138+
zapLabels...,
139+
)
140+
}
141+
100142
toSend = append(toSend, createTimeSeries(labels, metric))
101143

102144
metric.lastValueIsSended = true

0 commit comments

Comments
 (0)