Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only set start/end if time is not Zero #1238

Merged
merged 1 commit into from
Mar 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 30 additions & 10 deletions api/prometheus/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -949,8 +949,12 @@ func (h *httpAPI) DeleteSeries(ctx context.Context, matches []string, startTime,
q.Add("match[]", m)
}

q.Set("start", formatTime(startTime))
q.Set("end", formatTime(endTime))
if !startTime.IsZero() {
q.Set("start", formatTime(startTime))
}
if !endTime.IsZero() {
q.Set("end", formatTime(endTime))
}

u.RawQuery = q.Encode()

Expand Down Expand Up @@ -1017,8 +1021,12 @@ func (h *httpAPI) Runtimeinfo(ctx context.Context) (RuntimeinfoResult, error) {
func (h *httpAPI) LabelNames(ctx context.Context, matches []string, startTime, endTime time.Time) ([]string, Warnings, error) {
u := h.client.URL(epLabels, nil)
q := u.Query()
q.Set("start", formatTime(startTime))
q.Set("end", formatTime(endTime))
if !startTime.IsZero() {
q.Set("start", formatTime(startTime))
}
if !endTime.IsZero() {
q.Set("end", formatTime(endTime))
}
for _, m := range matches {
q.Add("match[]", m)
}
Expand All @@ -1040,8 +1048,12 @@ func (h *httpAPI) LabelNames(ctx context.Context, matches []string, startTime, e
func (h *httpAPI) LabelValues(ctx context.Context, label string, matches []string, startTime, endTime time.Time) (model.LabelValues, Warnings, error) {
u := h.client.URL(epLabelValues, map[string]string{"name": label})
q := u.Query()
q.Set("start", formatTime(startTime))
q.Set("end", formatTime(endTime))
if !startTime.IsZero() {
q.Set("start", formatTime(startTime))
}
if !endTime.IsZero() {
q.Set("end", formatTime(endTime))
}
for _, m := range matches {
q.Add("match[]", m)
}
Expand Down Expand Up @@ -1139,8 +1151,12 @@ func (h *httpAPI) Series(ctx context.Context, matches []string, startTime, endTi
q.Add("match[]", m)
}

q.Set("start", formatTime(startTime))
q.Set("end", formatTime(endTime))
if !startTime.IsZero() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add Series method comment to mention this behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can, although the Query method (which already has this behavior) doesn't document it either. Do we still want to document this up (since this would be the case for all methods with a time.Time argument (exception being Range as it is required).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do in next pr all good. Thanks

q.Set("start", formatTime(startTime))
}
if !endTime.IsZero() {
q.Set("end", formatTime(endTime))
}

u.RawQuery = q.Encode()

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

q.Set("query", query)
q.Set("start", formatTime(startTime))
q.Set("end", formatTime(endTime))
if !startTime.IsZero() {
q.Set("start", formatTime(startTime))
}
if !endTime.IsZero() {
q.Set("end", formatTime(endTime))
}
u.RawQuery = q.Encode()

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