Skip to content

Commit 6037863

Browse files
committed
Only set start/end if time is not Zero
This is an updated PR of #615 -- based on discussion in #621 Fixes #621 Signed-off-by: Thomas Jackson <jacksontj.89@gmail.com>
1 parent e79d7e7 commit 6037863

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

api/prometheus/v1/api.go

+30-10
Original file line numberDiff line numberDiff line change
@@ -949,8 +949,12 @@ func (h *httpAPI) DeleteSeries(ctx context.Context, matches []string, startTime,
949949
q.Add("match[]", m)
950950
}
951951

952-
q.Set("start", formatTime(startTime))
953-
q.Set("end", formatTime(endTime))
952+
if !startTime.IsZero() {
953+
q.Set("start", formatTime(startTime))
954+
}
955+
if !endTime.IsZero() {
956+
q.Set("end", formatTime(endTime))
957+
}
954958

955959
u.RawQuery = q.Encode()
956960

@@ -1017,8 +1021,12 @@ func (h *httpAPI) Runtimeinfo(ctx context.Context) (RuntimeinfoResult, error) {
10171021
func (h *httpAPI) LabelNames(ctx context.Context, matches []string, startTime, endTime time.Time) ([]string, Warnings, error) {
10181022
u := h.client.URL(epLabels, nil)
10191023
q := u.Query()
1020-
q.Set("start", formatTime(startTime))
1021-
q.Set("end", formatTime(endTime))
1024+
if !startTime.IsZero() {
1025+
q.Set("start", formatTime(startTime))
1026+
}
1027+
if !endTime.IsZero() {
1028+
q.Set("end", formatTime(endTime))
1029+
}
10221030
for _, m := range matches {
10231031
q.Add("match[]", m)
10241032
}
@@ -1040,8 +1048,12 @@ func (h *httpAPI) LabelNames(ctx context.Context, matches []string, startTime, e
10401048
func (h *httpAPI) LabelValues(ctx context.Context, label string, matches []string, startTime, endTime time.Time) (model.LabelValues, Warnings, error) {
10411049
u := h.client.URL(epLabelValues, map[string]string{"name": label})
10421050
q := u.Query()
1043-
q.Set("start", formatTime(startTime))
1044-
q.Set("end", formatTime(endTime))
1051+
if !startTime.IsZero() {
1052+
q.Set("start", formatTime(startTime))
1053+
}
1054+
if !endTime.IsZero() {
1055+
q.Set("end", formatTime(endTime))
1056+
}
10451057
for _, m := range matches {
10461058
q.Add("match[]", m)
10471059
}
@@ -1139,8 +1151,12 @@ func (h *httpAPI) Series(ctx context.Context, matches []string, startTime, endTi
11391151
q.Add("match[]", m)
11401152
}
11411153

1142-
q.Set("start", formatTime(startTime))
1143-
q.Set("end", formatTime(endTime))
1154+
if !startTime.IsZero() {
1155+
q.Set("start", formatTime(startTime))
1156+
}
1157+
if !endTime.IsZero() {
1158+
q.Set("end", formatTime(endTime))
1159+
}
11441160

11451161
u.RawQuery = q.Encode()
11461162

@@ -1300,8 +1316,12 @@ func (h *httpAPI) QueryExemplars(ctx context.Context, query string, startTime, e
13001316
q := u.Query()
13011317

13021318
q.Set("query", query)
1303-
q.Set("start", formatTime(startTime))
1304-
q.Set("end", formatTime(endTime))
1319+
if !startTime.IsZero() {
1320+
q.Set("start", formatTime(startTime))
1321+
}
1322+
if !endTime.IsZero() {
1323+
q.Set("end", formatTime(endTime))
1324+
}
13051325
u.RawQuery = q.Encode()
13061326

13071327
req, err := http.NewRequest(http.MethodGet, u.String(), nil)

0 commit comments

Comments
 (0)