mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 05:34:05 -08:00
Merge pull request #12535 from pracucci/export-min-max-time
Expose MinTime and MaxTime
This commit is contained in:
commit
31015f83d7
|
@ -561,11 +561,11 @@ func (api *API) queryRange(r *http.Request) (result apiFuncResult) {
|
|||
}
|
||||
|
||||
func (api *API) queryExemplars(r *http.Request) apiFuncResult {
|
||||
start, err := parseTimeParam(r, "start", minTime)
|
||||
start, err := parseTimeParam(r, "start", MinTime)
|
||||
if err != nil {
|
||||
return invalidParamError(err, "start")
|
||||
}
|
||||
end, err := parseTimeParam(r, "end", maxTime)
|
||||
end, err := parseTimeParam(r, "end", MaxTime)
|
||||
if err != nil {
|
||||
return invalidParamError(err, "end")
|
||||
}
|
||||
|
@ -625,11 +625,11 @@ func returnAPIError(err error) *apiError {
|
|||
}
|
||||
|
||||
func (api *API) labelNames(r *http.Request) apiFuncResult {
|
||||
start, err := parseTimeParam(r, "start", minTime)
|
||||
start, err := parseTimeParam(r, "start", MinTime)
|
||||
if err != nil {
|
||||
return invalidParamError(err, "start")
|
||||
}
|
||||
end, err := parseTimeParam(r, "end", maxTime)
|
||||
end, err := parseTimeParam(r, "end", MaxTime)
|
||||
if err != nil {
|
||||
return invalidParamError(err, "end")
|
||||
}
|
||||
|
@ -691,11 +691,11 @@ func (api *API) labelValues(r *http.Request) (result apiFuncResult) {
|
|||
return apiFuncResult{nil, &apiError{errorBadData, errors.Errorf("invalid label name: %q", name)}, nil, nil}
|
||||
}
|
||||
|
||||
start, err := parseTimeParam(r, "start", minTime)
|
||||
start, err := parseTimeParam(r, "start", MinTime)
|
||||
if err != nil {
|
||||
return invalidParamError(err, "start")
|
||||
}
|
||||
end, err := parseTimeParam(r, "end", maxTime)
|
||||
end, err := parseTimeParam(r, "end", MaxTime)
|
||||
if err != nil {
|
||||
return invalidParamError(err, "end")
|
||||
}
|
||||
|
@ -760,11 +760,16 @@ func (api *API) labelValues(r *http.Request) (result apiFuncResult) {
|
|||
}
|
||||
|
||||
var (
|
||||
minTime = time.Unix(math.MinInt64/1000+62135596801, 0).UTC()
|
||||
maxTime = time.Unix(math.MaxInt64/1000-62135596801, 999999999).UTC()
|
||||
// MinTime is the default timestamp used for the begin of optional time ranges.
|
||||
// Exposed to let downstream projects to reference it.
|
||||
MinTime = time.Unix(math.MinInt64/1000+62135596801, 0).UTC()
|
||||
|
||||
minTimeFormatted = minTime.Format(time.RFC3339Nano)
|
||||
maxTimeFormatted = maxTime.Format(time.RFC3339Nano)
|
||||
// MaxTime is the default timestamp used for the end of optional time ranges.
|
||||
// Exposed to let downstream projects to reference it.
|
||||
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) (result apiFuncResult) {
|
||||
|
@ -775,11 +780,11 @@ func (api *API) series(r *http.Request) (result apiFuncResult) {
|
|||
return apiFuncResult{nil, &apiError{errorBadData, errors.New("no match[] parameter provided")}, nil, nil}
|
||||
}
|
||||
|
||||
start, err := parseTimeParam(r, "start", minTime)
|
||||
start, err := parseTimeParam(r, "start", MinTime)
|
||||
if err != nil {
|
||||
return invalidParamError(err, "start")
|
||||
}
|
||||
end, err := parseTimeParam(r, "end", maxTime)
|
||||
end, err := parseTimeParam(r, "end", MaxTime)
|
||||
if err != nil {
|
||||
return invalidParamError(err, "end")
|
||||
}
|
||||
|
@ -1579,11 +1584,11 @@ func (api *API) deleteSeries(r *http.Request) apiFuncResult {
|
|||
return apiFuncResult{nil, &apiError{errorBadData, errors.New("no match[] parameter provided")}, nil, nil}
|
||||
}
|
||||
|
||||
start, err := parseTimeParam(r, "start", minTime)
|
||||
start, err := parseTimeParam(r, "start", MinTime)
|
||||
if err != nil {
|
||||
return invalidParamError(err, "start")
|
||||
}
|
||||
end, err := parseTimeParam(r, "end", maxTime)
|
||||
end, err := parseTimeParam(r, "end", MaxTime)
|
||||
if err != nil {
|
||||
return invalidParamError(err, "end")
|
||||
}
|
||||
|
@ -1738,9 +1743,9 @@ func parseTime(s string) (time.Time, error) {
|
|||
// Upstream issue: https://github.com/golang/go/issues/20555
|
||||
switch s {
|
||||
case minTimeFormatted:
|
||||
return minTime, nil
|
||||
return MinTime, nil
|
||||
case maxTimeFormatted:
|
||||
return maxTime, nil
|
||||
return MaxTime, nil
|
||||
}
|
||||
return time.Time{}, errors.Errorf("cannot parse %q to a valid timestamp", s)
|
||||
}
|
||||
|
|
|
@ -3059,7 +3059,7 @@ func TestParseTimeParam(t *testing.T) {
|
|||
{ // When data is valid.
|
||||
paramName: "start",
|
||||
paramValue: "1582468023986",
|
||||
defaultValue: minTime,
|
||||
defaultValue: MinTime,
|
||||
result: resultType{
|
||||
asTime: ts,
|
||||
asError: nil,
|
||||
|
@ -3068,16 +3068,16 @@ func TestParseTimeParam(t *testing.T) {
|
|||
{ // When data is empty string.
|
||||
paramName: "end",
|
||||
paramValue: "",
|
||||
defaultValue: maxTime,
|
||||
defaultValue: MaxTime,
|
||||
result: resultType{
|
||||
asTime: maxTime,
|
||||
asTime: MaxTime,
|
||||
asError: nil,
|
||||
},
|
||||
},
|
||||
{ // When data is not valid.
|
||||
paramName: "foo",
|
||||
paramValue: "baz",
|
||||
defaultValue: maxTime,
|
||||
defaultValue: MaxTime,
|
||||
result: resultType{
|
||||
asTime: time.Time{},
|
||||
asError: func() error {
|
||||
|
@ -3148,12 +3148,12 @@ func TestParseTime(t *testing.T) {
|
|||
result: time.Unix(1543578564, 705*1e6),
|
||||
},
|
||||
{
|
||||
input: minTime.Format(time.RFC3339Nano),
|
||||
result: minTime,
|
||||
input: MinTime.Format(time.RFC3339Nano),
|
||||
result: MinTime,
|
||||
},
|
||||
{
|
||||
input: maxTime.Format(time.RFC3339Nano),
|
||||
result: maxTime,
|
||||
input: MaxTime.Format(time.RFC3339Nano),
|
||||
result: MaxTime,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue