mirror of
https://github.com/prometheus/prometheus
synced 2025-01-15 19:32:05 +00:00
Add tests to ensure we can marshal and unmarshal our min/max times (#5734)
* Add tests to ensure we can marshal and unmarshal our min/max times Related to https://github.com/prometheus/client_golang/issues/614 Instead of implementing all the time parsing, we can special-case handle these 2 times. This means if times in this format show up that time.Parse can't handle they will still error, but we can marshal/parse our own min/max time Signed-off-by: Thomas Jackson <jacksontj.89@gmail.com>
This commit is contained in:
parent
2ccc48adc6
commit
fef150f1b5
@ -439,8 +439,11 @@ func (api *API) labelValues(r *http.Request) apiFuncResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
minTime = time.Unix(math.MinInt64/1000+62135596801, 0)
|
minTime = time.Unix(math.MinInt64/1000+62135596801, 0).UTC()
|
||||||
maxTime = time.Unix(math.MaxInt64/1000-62135596801, 999999999)
|
maxTime = time.Unix(math.MaxInt64/1000-62135596801, 999999999).UTC()
|
||||||
|
|
||||||
|
minTimeFormatted = minTime.Format(time.RFC3339Nano)
|
||||||
|
maxTimeFormatted = maxTime.Format(time.RFC3339Nano)
|
||||||
)
|
)
|
||||||
|
|
||||||
func (api *API) series(r *http.Request) apiFuncResult {
|
func (api *API) series(r *http.Request) apiFuncResult {
|
||||||
@ -1162,6 +1165,17 @@ func parseTime(s string) (time.Time, error) {
|
|||||||
if t, err := time.Parse(time.RFC3339Nano, s); err == nil {
|
if t, err := time.Parse(time.RFC3339Nano, s); err == nil {
|
||||||
return t, nil
|
return t, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stdlib's time parser can only handle 4 digit years. As a workaround until
|
||||||
|
// that is fixed we want to at least support our own boundary times.
|
||||||
|
// Context: https://github.com/prometheus/client_golang/issues/614
|
||||||
|
// Upstream issue: https://github.com/golang/go/issues/20555
|
||||||
|
switch s {
|
||||||
|
case minTimeFormatted:
|
||||||
|
return minTime, nil
|
||||||
|
case maxTimeFormatted:
|
||||||
|
return maxTime, nil
|
||||||
|
}
|
||||||
return time.Time{}, errors.Errorf("cannot parse %q to a valid timestamp", s)
|
return time.Time{}, errors.Errorf("cannot parse %q to a valid timestamp", s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1331,6 +1331,14 @@ func TestParseTime(t *testing.T) {
|
|||||||
input: "1543578564.705",
|
input: "1543578564.705",
|
||||||
result: time.Unix(1543578564, 705*1e6),
|
result: time.Unix(1543578564, 705*1e6),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
input: minTime.Format(time.RFC3339Nano),
|
||||||
|
result: minTime,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: maxTime.Format(time.RFC3339Nano),
|
||||||
|
result: maxTime,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
Loading…
Reference in New Issue
Block a user