From 8c8bb82d04e854d82555150ca2e71e2bc159df90 Mon Sep 17 00:00:00 2001 From: Bob Shannon Date: Tue, 2 Apr 2019 13:00:29 -0400 Subject: [PATCH] Add support for POSTing to /series endpoint (#5422) * Add support for POSTing to /series endpoint * Document query API POST support Signed-off-by: Bob Shannon --- docs/querying/api.md | 17 ++++++++++++++++- web/api/v1/api.go | 1 + web/api/v1/api_test.go | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/docs/querying/api.md b/docs/querying/api.md index 8ba9b02c6..b548f1262 100644 --- a/docs/querying/api.md +++ b/docs/querying/api.md @@ -74,6 +74,7 @@ The following endpoint evaluates an instant query at a single point in time: ``` GET /api/v1/query +POST /api/v1/query ``` URL query parameters: @@ -85,6 +86,10 @@ URL query parameters: The current server time is used if the `time` parameter is omitted. +You can URL-encode these parameters directly in the request body by using the `POST` method and +`Content-Type: application/x-www-form-urlencoded` header. This is useful when specifying a large +or dynamic number of series selectors that may breach server-side URL character limits. + The `data` section of the query result has the following format: ``` @@ -135,6 +140,7 @@ The following endpoint evaluates an expression query over a range of time: ``` GET /api/v1/query_range +POST /api/v1/query_range ``` URL query parameters: @@ -146,6 +152,10 @@ URL query parameters: - `timeout=`: Evaluation timeout. Optional. Defaults to and is capped by the value of the `-query.timeout` flag. +You can URL-encode these parameters directly in the request body by using the `POST` method and +`Content-Type: application/x-www-form-urlencoded` header. This is useful when specifying a large +or dynamic number of series selectors that may breach server-side URL character limits. + The `data` section of the query result has the following format: ``` @@ -205,6 +215,7 @@ The following endpoint returns the list of time series that match a certain labe ``` GET /api/v1/series +POST /api/v1/series ``` URL query parameters: @@ -214,6 +225,10 @@ URL query parameters: - `start=`: Start timestamp. - `end=`: End timestamp. +You can URL-encode these parameters directly in the request body by using the `POST` method and +`Content-Type: application/x-www-form-urlencoded` header. This is useful when specifying a large +or dynamic number of series selectors that may breach server-side URL character limits. + The `data` section of the query result consists of a list of objects that contain the label name/value pairs which identify each series. @@ -221,7 +236,7 @@ The following example returns all series that match either of the selectors `up` or `process_start_time_seconds{job="prometheus"}`: ```json -$ curl -g 'http://localhost:9090/api/v1/series?match[]=up&match[]=process_start_time_seconds{job="prometheus"}' +$ curl -g 'http://localhost:9090/api/v1/series?' --data-urlencode='match[]=up' --data-urlencode='match[]=process_start_time_seconds{job="prometheus"}' { "status" : "success", "data" : [ diff --git a/web/api/v1/api.go b/web/api/v1/api.go index b169514c7..08a1c4d0b 100644 --- a/web/api/v1/api.go +++ b/web/api/v1/api.go @@ -231,6 +231,7 @@ func (api *API) Register(r *route.Router) { r.Get("/label/:name/values", wrap(api.labelValues)) r.Get("/series", wrap(api.series)) + r.Post("/series", wrap(api.series)) r.Del("/series", wrap(api.dropSeries)) r.Get("/targets", wrap(api.targets)) diff --git a/web/api/v1/api_test.go b/web/api/v1/api_test.go index c4d52e034..5082c1172 100644 --- a/web/api/v1/api_test.go +++ b/web/api/v1/api_test.go @@ -835,7 +835,7 @@ func testEndpoints(t *testing.T, api *API, testLabelAPI bool) { methods := func(f apiFunc) []string { fp := reflect.ValueOf(f).Pointer() - if fp == reflect.ValueOf(api.query).Pointer() || fp == reflect.ValueOf(api.queryRange).Pointer() { + if fp == reflect.ValueOf(api.query).Pointer() || fp == reflect.ValueOf(api.queryRange).Pointer() || fp == reflect.ValueOf(api.series).Pointer() { return []string{http.MethodGet, http.MethodPost} } return []string{http.MethodGet}