Skip to content

Commit 1d609e3

Browse files
committed
add metric_collector_test
1 parent 5418016 commit 1d609e3

File tree

3 files changed

+401
-46
lines changed

3 files changed

+401
-46
lines changed

plugin/output/prometheus/metric_collector.go

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -69,27 +69,6 @@ func (p *metricCollector) handleMetric(labels []promwrite.Label, value float64,
6969

7070
if shouldSend {
7171
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-
9372
values = append(values, createTimeSeries(labels, prevMetric))
9473
}
9574
} else {
@@ -119,28 +98,7 @@ func (p *metricCollector) flushOldMetrics() {
11998
metric := value.(metricValue)
12099
if now.Sub(metric.lastUpdateTime) > p.timeout && !metric.lastValueIsSended {
121100
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-
142101
toSend = append(toSend, createTimeSeries(labels, metric))
143-
144102
metric.lastValueIsSended = true
145103
p.collector.Store(key, metric)
146104
}

0 commit comments

Comments
 (0)