@@ -50,7 +50,7 @@ func newCollector(timeout time.Duration, sender storageSender, logger *zap.Logge
5050func (p * metricCollector ) handleMetric (labels []promwrite.Label , value float64 , timestamp int64 , metricType string , ttl int64 ) []promwrite.TimeSeries {
5151 labelsKey := labelsToKey (labels )
5252 now := time .Now ()
53- currentTimestampSec := timestamp / 1_000_000_000
53+ currentTimestampSec := timestamp / 1_000
5454
5555 var values []promwrite.TimeSeries
5656 var shouldSend bool
@@ -59,7 +59,7 @@ func (p *metricCollector) handleMetric(labels []promwrite.Label, value float64,
5959
6060 if prev , ok := p .collector .Load (labelsKey ); ok {
6161 prevMetric = prev .(metricValue )
62- prevTimestampSec := prevMetric .timestamp / 1_000_000_000
62+ prevTimestampSec := prevMetric .timestamp / 1_000
6363
6464 // For counters, accumulate values
6565 currentValue = value
@@ -71,7 +71,7 @@ func (p *metricCollector) handleMetric(labels []promwrite.Label, value float64,
7171 shouldSend = prevTimestampSec < currentTimestampSec
7272
7373 if shouldSend {
74- prevMetric .timestamp = max (prevMetric .timestamp , timestamp - 1_000_000_000 )
74+ prevMetric .timestamp = max (prevMetric .timestamp , timestamp - 1_000 )
7575 values = append (values , createTimeSeries (labels , prevMetric ))
7676 }
7777 } else {
@@ -84,7 +84,7 @@ func (p *metricCollector) handleMetric(labels []promwrite.Label, value float64,
8484 value : currentValue ,
8585 timestamp : timestamp ,
8686 lastUpdateTime : now ,
87- expiredAt : now .Add (time .Duration (ttl )),
87+ expiredAt : now .Add (time .Duration (ttl ) * time . Millisecond ),
8888 lastValueIsSended : shouldSend ,
8989 })
9090
@@ -132,7 +132,7 @@ func (p *metricCollector) flushOldMetrics() {
132132func (p * metricCollector ) repeatOldMetrics () {
133133 var toSend []promwrite.TimeSeries
134134 now := time .Now ()
135- nowUnixtime := now .UnixNano ()
135+ nowUnixtime := now .UnixMilli ()
136136
137137 p .collector .Range (func (key , value interface {}) bool {
138138 metric := value .(metricValue )
@@ -174,7 +174,7 @@ func createTimeSeries(labels []promwrite.Label, metric metricValue) promwrite.Ti
174174 return promwrite.TimeSeries {
175175 Labels : labels ,
176176 Sample : promwrite.Sample {
177- Time : time .Unix (0 , metric .timestamp ),
177+ Time : time .Unix (0 , metric .timestamp * int64 ( time . Millisecond ) ),
178178 Value : metric .value ,
179179 },
180180 }
0 commit comments