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

Switch to POST for LabelNames, Series, and QueryExemplars to DoGetFallback #1252

Merged
merged 1 commit into from
Apr 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions api/prometheus/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1031,13 +1031,7 @@ func (h *httpAPI) LabelNames(ctx context.Context, matches []string, startTime, e
q.Add("match[]", m)
}

u.RawQuery = q.Encode()

req, err := http.NewRequest(http.MethodGet, u.String(), nil)
if err != nil {
return nil, nil, err
}
_, body, w, err := h.client.Do(ctx, req)
_, body, w, err := h.client.DoGetFallback(ctx, u, q)
if err != nil {
return nil, w, err
}
Expand Down Expand Up @@ -1158,14 +1152,7 @@ func (h *httpAPI) Series(ctx context.Context, matches []string, startTime, endTi
q.Set("end", formatTime(endTime))
}

u.RawQuery = q.Encode()

req, err := http.NewRequest(http.MethodGet, u.String(), nil)
if err != nil {
return nil, nil, err
}

_, body, warnings, err := h.client.Do(ctx, req)
_, body, warnings, err := h.client.DoGetFallback(ctx, u, q)
if err != nil {
return nil, warnings, err
}
Expand Down Expand Up @@ -1322,14 +1309,8 @@ func (h *httpAPI) QueryExemplars(ctx context.Context, query string, startTime, e
if !endTime.IsZero() {
q.Set("end", formatTime(endTime))
}
u.RawQuery = q.Encode()

req, err := http.NewRequest(http.MethodGet, u.String(), nil)
if err != nil {
return nil, err
}

_, body, _, err := h.client.Do(ctx, req)
_, body, _, err := h.client.DoGetFallback(ctx, u, q)
if err != nil {
return nil, err
}
Expand Down
22 changes: 11 additions & 11 deletions api/prometheus/v1/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,38 +346,38 @@ func TestAPIs(t *testing.T) {
{
do: doLabelNames(nil, testTime.Add(-100*time.Hour), testTime),
inRes: []string{"val1", "val2"},
reqMethod: "GET",
reqMethod: "POST",
reqPath: "/api/v1/labels",
res: []string{"val1", "val2"},
},
{
do: doLabelNames(nil, testTime.Add(-100*time.Hour), testTime),
inRes: []string{"val1", "val2"},
inWarnings: []string{"a"},
reqMethod: "GET",
reqMethod: "POST",
reqPath: "/api/v1/labels",
res: []string{"val1", "val2"},
},

{
do: doLabelNames(nil, testTime.Add(-100*time.Hour), testTime),
inErr: fmt.Errorf("some error"),
reqMethod: "GET",
reqMethod: "POST",
reqPath: "/api/v1/labels",
err: errors.New("some error"),
},
{
do: doLabelNames(nil, testTime.Add(-100*time.Hour), testTime),
inErr: fmt.Errorf("some error"),
inWarnings: []string{"a"},
reqMethod: "GET",
reqMethod: "POST",
reqPath: "/api/v1/labels",
err: errors.New("some error"),
},
{
do: doLabelNames([]string{"up"}, testTime.Add(-100*time.Hour), testTime),
inRes: []string{"val1", "val2"},
reqMethod: "GET",
reqMethod: "POST",
reqPath: "/api/v1/labels",
res: []string{"val1", "val2"},
},
Expand Down Expand Up @@ -430,7 +430,7 @@ func TestAPIs(t *testing.T) {
"instance": "localhost:9090",
},
},
reqMethod: "GET",
reqMethod: "POST",
reqPath: "/api/v1/series",
res: []model.LabelSet{
{
Expand All @@ -451,7 +451,7 @@ func TestAPIs(t *testing.T) {
},
},
inWarnings: []string{"a"},
reqMethod: "GET",
reqMethod: "POST",
reqPath: "/api/v1/series",
res: []model.LabelSet{
{
Expand All @@ -465,7 +465,7 @@ func TestAPIs(t *testing.T) {
{
do: doSeries("up", testTime.Add(-time.Minute), testTime),
inErr: fmt.Errorf("some error"),
reqMethod: "GET",
reqMethod: "POST",
reqPath: "/api/v1/series",
err: errors.New("some error"),
},
Expand All @@ -474,7 +474,7 @@ func TestAPIs(t *testing.T) {
do: doSeries("up", testTime.Add(-time.Minute), testTime),
inErr: fmt.Errorf("some error"),
inWarnings: []string{"a"},
reqMethod: "GET",
reqMethod: "POST",
reqPath: "/api/v1/series",
err: errors.New("some error"),
},
Expand Down Expand Up @@ -1149,15 +1149,15 @@ func TestAPIs(t *testing.T) {

{
do: doQueryExemplars("tns_request_duration_seconds_bucket", testTime.Add(-1*time.Minute), testTime),
reqMethod: "GET",
reqMethod: "POST",
reqPath: "/api/v1/query_exemplars",
inErr: errors.New("some error"),
err: errors.New("some error"),
},

{
do: doQueryExemplars("tns_request_duration_seconds_bucket", testTime.Add(-1*time.Minute), testTime),
reqMethod: "GET",
reqMethod: "POST",
reqPath: "/api/v1/query_exemplars",
inRes: []interface{}{
map[string]interface{}{
Expand Down