@@ -472,15 +472,14 @@ func newWriteResponse(seriesIDs []int, err error, er endpointReplica) writeRespo
472472 }
473473}
474474
475- func secondsSinceOldestSample (ts prompb.TimeSeries ) float64 {
476- now := time .Now ().UnixNano () / int64 (time .Millisecond )
477- oldestTs := now
475+ func secondsSinceOldestSample (toMS int64 , ts prompb.TimeSeries ) float64 {
476+ fromMS := toMS
478477 for _ , s := range ts .Samples {
479- if s .Timestamp < oldestTs {
480- oldestTs = s .Timestamp
478+ if s .Timestamp < fromMS {
479+ fromMS = s .Timestamp
481480 }
482481 }
483- return float64 (now - oldestTs ) / 1000
482+ return float64 (toMS - fromMS ) / 1000
484483}
485484
486485func (h * Handler ) receiveHTTP (w http.ResponseWriter , r * http.Request ) {
@@ -627,9 +626,10 @@ func (h *Handler) receiveHTTP(w http.ResponseWriter, r *http.Request) {
627626 h .writeTimeseriesTotal .WithLabelValues (strconv .Itoa (responseStatusCode ), tenant ).Observe (float64 (stats .timeseries ))
628627 h .writeSamplesTotal .WithLabelValues (strconv .Itoa (responseStatusCode ), tenant ).Observe (float64 (stats .totalSamples ))
629628 }
629+ nowMS := time .Now ().UnixNano () / int64 (time .Millisecond )
630630 for _ , ts := range wreq .Timeseries {
631- if lat := secondsSinceOldestSample (ts ); lat > 0 {
632- h .writeE2eLatency .WithLabelValues (strconv .Itoa (responseStatusCode ), tenantHTTP ).Observe (secondsSinceOldestSample ( ts ) )
631+ if lat := secondsSinceOldestSample (nowMS , ts ); lat > 0 {
632+ h .writeE2eLatency .WithLabelValues (strconv .Itoa (responseStatusCode ), tenantHTTP ).Observe (lat )
633633 }
634634 }
635635}
0 commit comments