mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-13 06:47:28 -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 {
|
func (api *API) queryExemplars(r *http.Request) apiFuncResult {
|
||||||
start, err := parseTimeParam(r, "start", minTime)
|
start, err := parseTimeParam(r, "start", MinTime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return invalidParamError(err, "start")
|
return invalidParamError(err, "start")
|
||||||
}
|
}
|
||||||
end, err := parseTimeParam(r, "end", maxTime)
|
end, err := parseTimeParam(r, "end", MaxTime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return invalidParamError(err, "end")
|
return invalidParamError(err, "end")
|
||||||
}
|
}
|
||||||
|
@ -625,11 +625,11 @@ func returnAPIError(err error) *apiError {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) labelNames(r *http.Request) apiFuncResult {
|
func (api *API) labelNames(r *http.Request) apiFuncResult {
|
||||||
start, err := parseTimeParam(r, "start", minTime)
|
start, err := parseTimeParam(r, "start", MinTime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return invalidParamError(err, "start")
|
return invalidParamError(err, "start")
|
||||||
}
|
}
|
||||||
end, err := parseTimeParam(r, "end", maxTime)
|
end, err := parseTimeParam(r, "end", MaxTime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return invalidParamError(err, "end")
|
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}
|
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 {
|
if err != nil {
|
||||||
return invalidParamError(err, "start")
|
return invalidParamError(err, "start")
|
||||||
}
|
}
|
||||||
end, err := parseTimeParam(r, "end", maxTime)
|
end, err := parseTimeParam(r, "end", MaxTime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return invalidParamError(err, "end")
|
return invalidParamError(err, "end")
|
||||||
}
|
}
|
||||||
|
@ -760,11 +760,16 @@ func (api *API) labelValues(r *http.Request) (result apiFuncResult) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
minTime = time.Unix(math.MinInt64/1000+62135596801, 0).UTC()
|
// MinTime is the default timestamp used for the begin of optional time ranges.
|
||||||
maxTime = time.Unix(math.MaxInt64/1000-62135596801, 999999999).UTC()
|
// Exposed to let downstream projects to reference it.
|
||||||
|
MinTime = time.Unix(math.MinInt64/1000+62135596801, 0).UTC()
|
||||||
|
|
||||||
minTimeFormatted = minTime.Format(time.RFC3339Nano)
|
// MaxTime is the default timestamp used for the end of optional time ranges.
|
||||||
maxTimeFormatted = maxTime.Format(time.RFC3339Nano)
|
// 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) {
|
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}
|
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 {
|
if err != nil {
|
||||||
return invalidParamError(err, "start")
|
return invalidParamError(err, "start")
|
||||||
}
|
}
|
||||||
end, err := parseTimeParam(r, "end", maxTime)
|
end, err := parseTimeParam(r, "end", MaxTime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return invalidParamError(err, "end")
|
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}
|
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 {
|
if err != nil {
|
||||||
return invalidParamError(err, "start")
|
return invalidParamError(err, "start")
|
||||||
}
|
}
|
||||||
end, err := parseTimeParam(r, "end", maxTime)
|
end, err := parseTimeParam(r, "end", MaxTime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return invalidParamError(err, "end")
|
return invalidParamError(err, "end")
|
||||||
}
|
}
|
||||||
|
@ -1738,9 +1743,9 @@ func parseTime(s string) (time.Time, error) {
|
||||||
// Upstream issue: https://github.com/golang/go/issues/20555
|
// Upstream issue: https://github.com/golang/go/issues/20555
|
||||||
switch s {
|
switch s {
|
||||||
case minTimeFormatted:
|
case minTimeFormatted:
|
||||||
return minTime, nil
|
return MinTime, nil
|
||||||
case maxTimeFormatted:
|
case maxTimeFormatted:
|
||||||
return maxTime, nil
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3059,7 +3059,7 @@ func TestParseTimeParam(t *testing.T) {
|
||||||
{ // When data is valid.
|
{ // When data is valid.
|
||||||
paramName: "start",
|
paramName: "start",
|
||||||
paramValue: "1582468023986",
|
paramValue: "1582468023986",
|
||||||
defaultValue: minTime,
|
defaultValue: MinTime,
|
||||||
result: resultType{
|
result: resultType{
|
||||||
asTime: ts,
|
asTime: ts,
|
||||||
asError: nil,
|
asError: nil,
|
||||||
|
@ -3068,16 +3068,16 @@ func TestParseTimeParam(t *testing.T) {
|
||||||
{ // When data is empty string.
|
{ // When data is empty string.
|
||||||
paramName: "end",
|
paramName: "end",
|
||||||
paramValue: "",
|
paramValue: "",
|
||||||
defaultValue: maxTime,
|
defaultValue: MaxTime,
|
||||||
result: resultType{
|
result: resultType{
|
||||||
asTime: maxTime,
|
asTime: MaxTime,
|
||||||
asError: nil,
|
asError: nil,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ // When data is not valid.
|
{ // When data is not valid.
|
||||||
paramName: "foo",
|
paramName: "foo",
|
||||||
paramValue: "baz",
|
paramValue: "baz",
|
||||||
defaultValue: maxTime,
|
defaultValue: MaxTime,
|
||||||
result: resultType{
|
result: resultType{
|
||||||
asTime: time.Time{},
|
asTime: time.Time{},
|
||||||
asError: func() error {
|
asError: func() error {
|
||||||
|
@ -3148,12 +3148,12 @@ func TestParseTime(t *testing.T) {
|
||||||
result: time.Unix(1543578564, 705*1e6),
|
result: time.Unix(1543578564, 705*1e6),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
input: minTime.Format(time.RFC3339Nano),
|
input: MinTime.Format(time.RFC3339Nano),
|
||||||
result: minTime,
|
result: MinTime,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
input: maxTime.Format(time.RFC3339Nano),
|
input: MaxTime.Format(time.RFC3339Nano),
|
||||||
result: maxTime,
|
result: MaxTime,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue