Skip to content

Commit

Permalink
Switch to POST for LabelNames, Series, and QueryExemplars to DoGetFal…
Browse files Browse the repository at this point in the history
…lback (#1252)

The upstream prometheus HTTP API supports POSTS for these methods (the
same as Query and QueryRange). Similar to the original issue
(#428) we can hit 414
errors with these other APIs. This change simply duplicates the logic to
these other endpoints

Related to: jacksontj/promxy#588

Signed-off-by: Thomas Jackson <jacksontj.89@gmail.com>
  • Loading branch information
jacksontj committed Apr 16, 2023
1 parent e3b6de8 commit 0392dff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 33 deletions.
25 changes: 3 additions & 22 deletions api/prometheus/v1/api.go
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
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

0 comments on commit 0392dff

Please sign in to comment.