TimeToMilliseconds returns the input time as milliseconds, using the same formula used by Prometheus in order to get the same timestamp when asserting on query results. The formula we're mimicking here is Prometheus parseTime(). See: https://github.com/prometheus/prometheus/blob/df80dc4d3970121f2f76
(t time.Time)
| 102 | // on query results. The formula we're mimicking here is Prometheus parseTime(). |
| 103 | // See: https://github.com/prometheus/prometheus/blob/df80dc4d3970121f2f76cba79050983ffb3cdbb0/web/api/v1/api.go#L1690-L1694 |
| 104 | func TimeToMilliseconds(t time.Time) int64 { |
| 105 | // Convert to seconds. |
| 106 | sec := float64(t.Unix()) + float64(t.Nanosecond())/1e9 |
| 107 | |
| 108 | // Parse seconds. |
| 109 | s, ns := math.Modf(sec) |
| 110 | |
| 111 | // Round nanoseconds part. |
| 112 | ns = math.Round(ns*1000) / 1000 |
| 113 | |
| 114 | // Convert to millis. |
| 115 | return (int64(s) * 1e3) + (int64(ns * 1e3)) |
| 116 | } |
| 117 | |
| 118 | func GenerateSeries(name string, ts time.Time, additionalLabels ...prompb.Label) (series []prompb.TimeSeries, vector model.Vector) { |
| 119 | tsMillis := TimeToMilliseconds(ts) |
no outgoing calls