MCPcopy Create free account
hub / github.com/cortexproject/cortex / TimeToMilliseconds

Function TimeToMilliseconds

integration/e2e/util.go:104–116  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
104func 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
118func GenerateSeries(name string, ts time.Time, additionalLabels ...prompb.Label) (series []prompb.TimeSeries, vector model.Vector) {
119 tsMillis := TimeToMilliseconds(ts)

Callers 9

TestExemplarFunction · 0.92
TestTimeToMillisecondsFunction · 0.85
GenerateSeriesFunction · 0.85
GenerateHistogramSeriesFunction · 0.85
GenerateSeriesV2Function · 0.85

Calls

no outgoing calls

Tested by 3

TestExemplarFunction · 0.74
TestTimeToMillisecondsFunction · 0.68