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

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

Related to: https://github.com/jacksontj/promxy/issues/588

Signed-off-by: Thomas Jackson <jacksontj.89@gmail.com>
This commit is contained in:
Thomas Jackson 2023-04-16 05:41:34 -07:00 committed by GitHub
parent e3b6de8c3d
commit 0392dffd0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 33 deletions

View File

@ -1031,13 +1031,7 @@ func (h *httpAPI) LabelNames(ctx context.Context, matches []string, startTime, e
q.Add("match[]", m) q.Add("match[]", m)
} }
u.RawQuery = q.Encode() _, body, w, err := h.client.DoGetFallback(ctx, u, q)
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
if err != nil {
return nil, nil, err
}
_, body, w, err := h.client.Do(ctx, req)
if err != nil { if err != nil {
return nil, w, err return nil, w, err
} }
@ -1158,14 +1152,7 @@ func (h *httpAPI) Series(ctx context.Context, matches []string, startTime, endTi
q.Set("end", formatTime(endTime)) q.Set("end", formatTime(endTime))
} }
u.RawQuery = q.Encode() _, body, warnings, err := h.client.DoGetFallback(ctx, u, q)
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
if err != nil {
return nil, nil, err
}
_, body, warnings, err := h.client.Do(ctx, req)
if err != nil { if err != nil {
return nil, warnings, err return nil, warnings, err
} }
@ -1322,14 +1309,8 @@ func (h *httpAPI) QueryExemplars(ctx context.Context, query string, startTime, e
if !endTime.IsZero() { if !endTime.IsZero() {
q.Set("end", formatTime(endTime)) q.Set("end", formatTime(endTime))
} }
u.RawQuery = q.Encode()
req, err := http.NewRequest(http.MethodGet, u.String(), nil) _, body, _, err := h.client.DoGetFallback(ctx, u, q)
if err != nil {
return nil, err
}
_, body, _, err := h.client.Do(ctx, req)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -346,7 +346,7 @@ func TestAPIs(t *testing.T) {
{ {
do: doLabelNames(nil, testTime.Add(-100*time.Hour), testTime), do: doLabelNames(nil, testTime.Add(-100*time.Hour), testTime),
inRes: []string{"val1", "val2"}, inRes: []string{"val1", "val2"},
reqMethod: "GET", reqMethod: "POST",
reqPath: "/api/v1/labels", reqPath: "/api/v1/labels",
res: []string{"val1", "val2"}, res: []string{"val1", "val2"},
}, },
@ -354,7 +354,7 @@ func TestAPIs(t *testing.T) {
do: doLabelNames(nil, testTime.Add(-100*time.Hour), testTime), do: doLabelNames(nil, testTime.Add(-100*time.Hour), testTime),
inRes: []string{"val1", "val2"}, inRes: []string{"val1", "val2"},
inWarnings: []string{"a"}, inWarnings: []string{"a"},
reqMethod: "GET", reqMethod: "POST",
reqPath: "/api/v1/labels", reqPath: "/api/v1/labels",
res: []string{"val1", "val2"}, res: []string{"val1", "val2"},
}, },
@ -362,7 +362,7 @@ func TestAPIs(t *testing.T) {
{ {
do: doLabelNames(nil, testTime.Add(-100*time.Hour), testTime), do: doLabelNames(nil, testTime.Add(-100*time.Hour), testTime),
inErr: fmt.Errorf("some error"), inErr: fmt.Errorf("some error"),
reqMethod: "GET", reqMethod: "POST",
reqPath: "/api/v1/labels", reqPath: "/api/v1/labels",
err: errors.New("some error"), err: errors.New("some error"),
}, },
@ -370,14 +370,14 @@ func TestAPIs(t *testing.T) {
do: doLabelNames(nil, testTime.Add(-100*time.Hour), testTime), do: doLabelNames(nil, testTime.Add(-100*time.Hour), testTime),
inErr: fmt.Errorf("some error"), inErr: fmt.Errorf("some error"),
inWarnings: []string{"a"}, inWarnings: []string{"a"},
reqMethod: "GET", reqMethod: "POST",
reqPath: "/api/v1/labels", reqPath: "/api/v1/labels",
err: errors.New("some error"), err: errors.New("some error"),
}, },
{ {
do: doLabelNames([]string{"up"}, testTime.Add(-100*time.Hour), testTime), do: doLabelNames([]string{"up"}, testTime.Add(-100*time.Hour), testTime),
inRes: []string{"val1", "val2"}, inRes: []string{"val1", "val2"},
reqMethod: "GET", reqMethod: "POST",
reqPath: "/api/v1/labels", reqPath: "/api/v1/labels",
res: []string{"val1", "val2"}, res: []string{"val1", "val2"},
}, },
@ -430,7 +430,7 @@ func TestAPIs(t *testing.T) {
"instance": "localhost:9090", "instance": "localhost:9090",
}, },
}, },
reqMethod: "GET", reqMethod: "POST",
reqPath: "/api/v1/series", reqPath: "/api/v1/series",
res: []model.LabelSet{ res: []model.LabelSet{
{ {
@ -451,7 +451,7 @@ func TestAPIs(t *testing.T) {
}, },
}, },
inWarnings: []string{"a"}, inWarnings: []string{"a"},
reqMethod: "GET", reqMethod: "POST",
reqPath: "/api/v1/series", reqPath: "/api/v1/series",
res: []model.LabelSet{ res: []model.LabelSet{
{ {
@ -465,7 +465,7 @@ func TestAPIs(t *testing.T) {
{ {
do: doSeries("up", testTime.Add(-time.Minute), testTime), do: doSeries("up", testTime.Add(-time.Minute), testTime),
inErr: fmt.Errorf("some error"), inErr: fmt.Errorf("some error"),
reqMethod: "GET", reqMethod: "POST",
reqPath: "/api/v1/series", reqPath: "/api/v1/series",
err: errors.New("some error"), err: errors.New("some error"),
}, },
@ -474,7 +474,7 @@ func TestAPIs(t *testing.T) {
do: doSeries("up", testTime.Add(-time.Minute), testTime), do: doSeries("up", testTime.Add(-time.Minute), testTime),
inErr: fmt.Errorf("some error"), inErr: fmt.Errorf("some error"),
inWarnings: []string{"a"}, inWarnings: []string{"a"},
reqMethod: "GET", reqMethod: "POST",
reqPath: "/api/v1/series", reqPath: "/api/v1/series",
err: errors.New("some error"), err: errors.New("some error"),
}, },
@ -1149,7 +1149,7 @@ func TestAPIs(t *testing.T) {
{ {
do: doQueryExemplars("tns_request_duration_seconds_bucket", testTime.Add(-1*time.Minute), testTime), do: doQueryExemplars("tns_request_duration_seconds_bucket", testTime.Add(-1*time.Minute), testTime),
reqMethod: "GET", reqMethod: "POST",
reqPath: "/api/v1/query_exemplars", reqPath: "/api/v1/query_exemplars",
inErr: errors.New("some error"), inErr: errors.New("some error"),
err: errors.New("some error"), err: errors.New("some error"),
@ -1157,7 +1157,7 @@ func TestAPIs(t *testing.T) {
{ {
do: doQueryExemplars("tns_request_duration_seconds_bucket", testTime.Add(-1*time.Minute), testTime), do: doQueryExemplars("tns_request_duration_seconds_bucket", testTime.Add(-1*time.Minute), testTime),
reqMethod: "GET", reqMethod: "POST",
reqPath: "/api/v1/query_exemplars", reqPath: "/api/v1/query_exemplars",
inRes: []interface{}{ inRes: []interface{}{
map[string]interface{}{ map[string]interface{}{