@@ -80,18 +80,18 @@ func TestMetricCollector(t *testing.T) {
8080
8181 // First value - should not be sent
8282 now := time .Now ()
83- values := collector .handleMetric (labels , 10.0 , now .UnixNano (), "counter" )
83+ values := collector .handleMetric (labels , 10.0 , now .UnixMilli (), "counter" , 0 )
8484 assert .Empty (t , values )
8585 assert .Empty (t , testSender .getSentMetrics ())
8686
8787 // Second value in same time window - should accumulate but not send
88- values = collector .handleMetric (labels , 5.0 , now .UnixNano (), "counter" )
88+ values = collector .handleMetric (labels , 5.0 , now .UnixMilli (), "counter" , 0 )
8989 assert .Empty (t , values )
9090 assert .Empty (t , testSender .getSentMetrics ())
9191
9292 // Third value in next time window - should send accumulated value
9393 nextTime := now .Add (time .Second )
94- values = collector .handleMetric (labels , 3.0 , nextTime .UnixNano (), "counter" )
94+ values = collector .handleMetric (labels , 3.0 , nextTime .UnixMilli (), "counter" , 0 )
9595 assert .Len (t , values , 1 )
9696 assert .Equal (t , 15.0 , values [0 ].Sample .Value ) // 10 + 5
9797 })
@@ -109,16 +109,16 @@ func TestMetricCollector(t *testing.T) {
109109 now := time .Now ()
110110
111111 // First value - should not be sent
112- values := collector .handleMetric (labels , 100.0 , now .UnixNano (), "gauge" )
112+ values := collector .handleMetric (labels , 100.0 , now .UnixMilli (), "gauge" , 0 )
113113 assert .Empty (t , values )
114114
115115 // Second value in same time window - should replace but not send
116- values = collector .handleMetric (labels , 200.0 , now .UnixNano (), "gauge" )
116+ values = collector .handleMetric (labels , 200.0 , now .UnixMilli (), "gauge" , 0 )
117117 assert .Empty (t , values )
118118
119119 // Third value in next time window - should send latest value
120120 nextTime := now .Add (time .Second )
121- values = collector .handleMetric (labels , 300.0 , nextTime .UnixNano (), "gauge" )
121+ values = collector .handleMetric (labels , 300.0 , nextTime .UnixMilli (), "gauge" , 0 )
122122 assert .Len (t , values , 1 )
123123 assert .Equal (t , 200.0 , values [0 ].Sample .Value ) // Latest value before time window change
124124 })
@@ -135,7 +135,7 @@ func TestMetricCollector(t *testing.T) {
135135 }
136136
137137 // Add a metric that will timeout
138- collector .handleMetric (labels , 42.0 , time .Now ().UnixNano (), "gauge" )
138+ collector .handleMetric (labels , 42.0 , time .Now ().UnixMilli (), "gauge" , 0 )
139139
140140 // Wait for timeout + a bit more
141141 time .Sleep (shortTimeout + 50 * time .Millisecond )
@@ -168,7 +168,7 @@ func TestMetricCollector(t *testing.T) {
168168 }
169169
170170 // Add a metric that will timeout
171- sendedValues := collector .handleMetric (labels , 42.0 , time .Now ().UnixNano (), "gauge" )
171+ sendedValues := collector .handleMetric (labels , 42.0 , time .Now ().UnixMilli (), "gauge" , 0 )
172172 assert .Len (t , sendedValues , 0 )
173173
174174 // Wait for timeout + a bit more
@@ -203,8 +203,8 @@ func TestMetricCollector(t *testing.T) {
203203 }
204204
205205 // Add multiple metrics
206- collector .handleMetric (labels1 , 10.0 , time .Now ().UnixNano (), "gauge" )
207- collector .handleMetric (labels2 , 20.0 , time .Now ().UnixNano (), "gauge" )
206+ collector .handleMetric (labels1 , 10.0 , time .Now ().UnixMilli (), "gauge" , 0 )
207+ collector .handleMetric (labels2 , 20.0 , time .Now ().UnixMilli (), "gauge" , 0 )
208208
209209 collector .shutdown ()
210210
@@ -232,7 +232,7 @@ func TestMetricCollector(t *testing.T) {
232232 {Name : "worker" , Value : string (rune (workerID ))},
233233 {Name : "index" , Value : string (rune (j ))},
234234 }
235- collector .handleMetric (labels , float64 (j ), time .Now ().UnixNano (), "counter" )
235+ collector .handleMetric (labels , float64 (j ), time .Now ().UnixMilli (), "counter" , 0 )
236236 }
237237 }(i )
238238 }
@@ -260,7 +260,7 @@ func TestMetricCollector(t *testing.T) {
260260 {Name : "job" , Value : "test" },
261261 }
262262
263- collector .handleMetric (labels , 99.0 , time .Now ().UnixNano (), "gauge" )
263+ collector .handleMetric (labels , 99.0 , time .Now ().UnixMilli (), "gauge" , 0 )
264264
265265 // Wait for flush
266266 time .Sleep (150 * time .Millisecond )
@@ -274,7 +274,7 @@ func TestMetricCollector(t *testing.T) {
274274 now := time .Now ()
275275 mv := metricValue {
276276 value : 42.0 ,
277- timestamp : now .UnixNano (),
277+ timestamp : now .UnixMilli (),
278278 lastUpdateTime : now ,
279279 lastValueIsSended : false ,
280280 }
@@ -285,7 +285,7 @@ func TestMetricCollector(t *testing.T) {
285285
286286 ts := createTimeSeries (labels , mv )
287287 assert .Equal (t , 42.0 , ts .Sample .Value )
288- assert .Equal (t , now .Truncate (time .Nanosecond ), ts .Sample .Time .Truncate (time .Nanosecond ))
288+ assert .Equal (t , now .Truncate (time .Millisecond ), ts .Sample .Time .Truncate (time .Millisecond ))
289289 assert .Equal (t , labels , ts .Labels )
290290 })
291291
@@ -317,11 +317,11 @@ func TestEdgeCases(t *testing.T) {
317317
318318 // Very old timestamp
319319 oldTime := time .Now ().Add (- 1 * time .Hour )
320- collector .handleMetric (labels , 1.0 , oldTime .UnixNano (), "gauge" )
320+ collector .handleMetric (labels , 1.0 , oldTime .UnixMilli (), "gauge" , 0 )
321321
322322 now := time .Now ()
323323 // New timestamp to trigger send
324- values := collector .handleMetric (labels , 2.0 , now .UnixNano (), "gauge" )
324+ values := collector .handleMetric (labels , 2.0 , now .UnixMilli (), "gauge" , 0 )
325325
326326 // Should have sent the old value despite being very old (timestamp: 1 second before now)
327327 assert .Len (t , values , 1 )
@@ -341,8 +341,8 @@ func TestEdgeCases(t *testing.T) {
341341 now := time .Now ()
342342
343343 // Test unknown metric type (should behave like gauge)
344- collector .handleMetric (labels , 10.0 , now .UnixNano (), "unknown" )
345- values := collector .handleMetric (labels , 20.0 , now .Add (time .Second ).UnixNano (), "unknown" )
344+ collector .handleMetric (labels , 10.0 , now .UnixMilli (), "unknown" , 0 )
345+ values := collector .handleMetric (labels , 20.0 , now .Add (time .Second ).UnixMilli (), "unknown" , 0 )
346346
347347 // Should send the last value (10.0) since time window advanced
348348 if len (values ) > 0 {
@@ -356,7 +356,7 @@ func TestCreateTimeSeries(t *testing.T) {
356356 now := time .Now ()
357357 mv := metricValue {
358358 value : 123.45 ,
359- timestamp : now .UnixNano (),
359+ timestamp : now .UnixMilli (),
360360 }
361361
362362 labels := []promwrite.Label {
@@ -368,7 +368,7 @@ func TestCreateTimeSeries(t *testing.T) {
368368
369369 assert .Equal (t , labels , ts .Labels )
370370 assert .Equal (t , 123.45 , ts .Sample .Value )
371- assert .Equal (t , now .Truncate (time .Nanosecond ), ts .Sample .Time .Truncate (time .Nanosecond ))
371+ assert .Equal (t , now .Truncate (time .Millisecond ), ts .Sample .Time .Truncate (time .Millisecond ))
372372 })
373373}
374374
0 commit comments