Commit Graph

67 Commits

Author SHA1 Message Date
Thomas Jackson 0392dffd0e
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>
2023-04-16 13:41:34 +01:00
Thomas Jackson 603786389c Only set start/end if time is not Zero
This is an updated PR of #615 -- based on discussion in #621

Fixes #621

Signed-off-by: Thomas Jackson <jacksontj.89@gmail.com>
2023-03-21 13:10:58 -07:00
beorn7 2236d782ff api: Extend and improve json-iterator usage
For one, this pulls up the histogram-related json-iterator usage from
prometheus/common into the API client. Previously, the only
json-iterater usage was here in the API client. But then json-iterator
was used for the native histogram additions directly in
prometheus/common, see
https://github.com/prometheus/common/pull/440/files . This however
meant that any user of prometheus/common/model would now link in
json-iterator, even if they are not using the JSON marshaling at
all. To keep prometheus/common/model more leightweight, this commit
moves all the json-iterator usage into the API client itself, as it
was done before for the normal float samples.

This commit also adds an unmarshaling function for native histograms,
which didn't even exist in prometheus/common/model so far.

It also adds json-iterator marshaling and un-marshaling for
model.SampleStream, which is only needed for the benchmark
(BenchmarkSamplesJsonSerialization). This fixes the benchmark such
that it actually compares json-iterator and std-lib json encoding
(which didn't work before because the custom marshaling methods of
model.SampleStream enforced std-lib json encoding for floats and
json-iterator encoding for histograms in all cases).

I expect this to fix #1179.

Signed-off-by: beorn7 <beorn@grafana.com>
2023-03-01 17:27:33 +01:00
Kemal Akkoyun 870469ecf9
Test and support 1.19 (#1160)
* Add new Go 1.19 metrics

Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>

* Format files with the latest formatter

Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>

Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
2022-11-08 00:14:19 +01:00
Christoph Mewes 618194de6a
fix assorted oddities found by golangci-lint (#1040)
* fix assorted oddities found by golangci-lint

Signed-off-by: Christoph Mewes <christoph@kubermatic.com>

* permanently enable the linters

Signed-off-by: Christoph Mewes <christoph@kubermatic.com>

* post-rebase blues

Signed-off-by: Christoph Mewes <christoph@kubermatic.com>
2022-08-03 06:30:51 +02:00
Soroosh Azary Marhabi 2cfd1eb960
Enable same linters as the Prometheus repo itself (#1056)
* Add gofumpt to github workflow & fix all files for it

Signed-off-by: sazary <soroosh@azary.ir>

* Add goimports to golangci & fix it's issues

Signed-off-by: sazary <soroosh@azary.ir>

* Add revive to golangci & fix it's issues

Signed-off-by: sazary <soroosh@azary.ir>

* Add errcheck & misspell to golangci and fix their issues

Signed-off-by: sazary <soroosh@azary.ir>

* Add govet & gosimple to golangci and fix their issues

Signed-off-by: sazary <soroosh@azary.ir>

* Enable all default linters of golangci

Signed-off-by: sazary <soroosh@azary.ir>
2022-06-17 09:04:06 +02:00
Joseph Woodward efe8e6fac8
Document WithTimeout options for Query/QueryRange (#1037)
Signed-off-by: Joseph Woodward <joseph.woodward@xeuse.com>
2022-04-29 06:34:50 +01:00
Joseph Woodward 48a686a603
Update query API to support timeouts (#1014)
* Add timeout parameter for queries

Signed-off-by: Joseph Woodward <joseph.woodward@xeuse.com>

* Update api/prometheus/v1/api.go

Co-authored-by: Kemal Akkoyun <kakkoyun@users.noreply.github.com>
Signed-off-by: Joseph Woodward <joseph.woodward@xeuse.com>

* Update api/prometheus/v1/api.go

Co-authored-by: Kemal Akkoyun <kakkoyun@users.noreply.github.com>
Signed-off-by: Joseph Woodward <joseph.woodward@xeuse.com>

* Pass timeout as stringified time.Duration instead of millisecond value

Signed-off-by: Joseph Woodward <joseph.woodward@xeuse.com>

* Update QueryRange API to support timeouts

Signed-off-by: Joseph Woodward <joseph.woodward@xeuse.com>

* Add timeout to test request params

Signed-off-by: Joseph Woodward <joseph.woodward@xeuse.com>

Co-authored-by: Kemal Akkoyun <kakkoyun@users.noreply.github.com>
2022-04-21 07:23:16 +02:00
Tomas Dohnalek cc7991d977
Make Query requests idempotent (#1022)
* Make Query requests idempotent

Address #1020.

Signed-off-by: Tomáš Dohnálek <dohnto@gmail.com>

* Use empty header

Signed-off-by: Tomáš Dohnálek <dohnto@gmail.com>

* Document issue with original documentation

Signed-off-by: Tomáš Dohnálek <dohnto@gmail.com>
2022-04-13 07:21:50 +02:00
Tomáš Dohnálek 40e54a75a6 Refactor apiClientImpl.DoGetFallback
Make apiClientImpl.DoGetFallback more idiomatic and efficient:
 * Save result of args.Encode() operation as it might be used 2 times in
   the function and due to looping and sorting it might be heavy.
 * Follow line-of-sight practise and therefore simplify the code.

Signed-off-by: Tomáš Dohnálek <dohnto@gmail.com>
2022-04-07 09:18:32 +02:00
Łukasz Mierzwa dc1559e8ef
Update /api/v1/status/tsdb to include headStats (#925)
Current structs for v1 HTTP API assume that there is chunkCount and timeSeriesCount on /api/v1/status/runtimeinfo, which seems to be gone for at least a few releases. /api/v1/status/tsdb now holds an extra headStats block with chunkCount, numSeries and a few other fields.
Update API models and tests to reflect this change.

Signed-off-by: Łukasz Mierzwa <l.mierzwa@gmail.com>
2022-01-05 10:09:29 +01:00
Ben Ye 440c09d3ec support wal replay status api
Signed-off-by: Ben Ye <ben.ye@bytedance.com>
2021-12-04 22:19:58 -08:00
yeya24 7a147c1bdf add exemplars API support
Signed-off-by: yeya24 <yb532204897@gmail.com>
2021-04-24 00:32:14 -04:00
Björn Rabenstein 4a22844c5d
Merge pull request #856 from yeya24/targets-field
Add missing fields to targets API
2021-04-12 22:30:20 +02:00
yeya24 45efe82b46 add missing fields to targets API
Signed-off-by: yeya24 <yb532204897@gmail.com>
2021-04-11 12:05:08 -04:00
Goutham Veeramachaneni 629f64ab3f
Add newer fields to Rules API
Signed-off-by: Goutham Veeramachaneni <gouthamve@gmail.com>
2021-04-11 12:17:26 +02:00
Kien Nguyen 4c24ae8b13 Add buildinfo method
Co-authored-by: Lili Cosic <cosiclili@gmail.com>
Signed-off-by: Kien Nguyen <kiennt2609@gmail.com>
2021-03-12 08:36:23 +07:00
yeya24 595a1d580c update comment
Signed-off-by: yeya24 <yb532204897@gmail.com>
2021-02-03 19:44:12 -05:00
yeya24 75d7516f2a support matchers in labels API
Signed-off-by: yeya24 <yb532204897@gmail.com>
2020-12-29 13:49:42 -05:00
beorn7 64b4a9cf9d API client: Enable fallback on status code 501, too
When discussing #801, I remembered #794. While dealing with the
latter, I read the HTTP RFC, stumbling upon the following:

    When a request method is received
    that is unrecognized or not implemented by an origin server, the
    origin server SHOULD respond with the 501 (Not Implemented) status
    code.  When a request method is received that is known by an origin
    server but not allowed for the target resource, the origin server
    SHOULD respond with the 405 (Method Not Allowed) status code.

Concluding from that, it is possible that a server desiring a fallback
to GET will send a status code of 501. It is even preferred if that
server does not offer any resource to be used with the POST method.

Therefore, I think we should fallback to GET on a 501, too.

Signed-off-by: beorn7 <beorn@grafana.com>
2020-09-10 13:14:07 +02:00
johncming 32a545bf61 Replace with the standard library constant.
Signed-off-by: johncming <johncming@yahoo.com>
2020-08-22 19:36:13 +08:00
Maximilian Gaß b0cdec211b
Use time.Time for timestamps in Runtimeinfo (#777)
Signed-off-by: Maximilian Gaß <m.gass@babiel.com>
2020-06-24 16:55:36 +01:00
Hima Varsha 6cd29bd38a
Add support for tsdb endpoint (#773)
Signed-off-by: Hima Varsha <hdureddy@apple.com>
2020-06-24 12:35:25 +01:00
yeya24 94ae5774fd fix time parameter propagation in labels API
Signed-off-by: yeya24 <yb532204897@gmail.com>
2020-06-19 18:57:25 -04:00
Augustin Husson 3defbd9c7c add start/end parameter for LabelValues
Signed-off-by: Augustin Husson <husson.augustin@gmail.com>
2020-06-11 16:05:23 +02:00
Augustin Husson 6ce5f2ca8a add start/end parameter for LabelNames
Signed-off-by: Augustin Husson <husson.augustin@gmail.com>
2020-06-11 13:02:32 +02:00
Lili Cosic c9e3c020a9 api/prometheus/v1/api.go: Add support for /runtimeinfo endpoint
Signed-off-by: Lili Cosic <cosiclili@gmail.com>
2020-05-18 20:12:53 +02:00
huanggze 8f87c69651
Improve API error handling
Signed-off-by: huanggze <loganhuang@yunify.com>
2020-04-02 16:02:06 +08:00
gotjosh 2463b8e78d Address review feedback
Signed-off-by: gotjosh <josue@grafana.com>
2020-02-28 09:49:39 +00:00
gotjosh 7f509dc4f4 API Client: Support new metadata endpoint in v1
Introduces support for the new metadata endpoint from Prometheus. The new endpoint provides information independent of targets and collapses the unique combinations of HELP, TYPE and UNIT.

Fixes #705

Signed-off-by: gotjosh <josue@grafana.com>
2020-02-26 17:48:57 +00:00
Joe Elliott 88792b1169 Moved warnings into apiclient
Signed-off-by: Joe Elliott <number101010@gmail.com>
2019-12-11 10:04:00 -05:00
Joe Elliott 393adc9261 Refactor ~worked. All tests passing except one
Signed-off-by: Joe Elliott <number101010@gmail.com>
2019-12-10 16:53:38 -05:00
Joe Elliott 7f4279992e First pass unravel
Signed-off-by: Joe Elliott <number101010@gmail.com>
2019-12-10 15:16:44 -05:00
Guangming Wang 49b3f23433 remove duplicated assignment in v1/api.go (#647)
Signed-off-by: Guangming Wang <guangming.wang@daocloud.io>
2019-10-02 00:47:28 +03:00
Thomas Jackson cd27091e79 Handle formatting when the time in nanoseconds requires more than a single int64
Signed-off-by: Thomas Jackson <jacksontj.89@gmail.com>

Fixup for #617
2019-07-09 09:23:52 -07:00
Thomas Jackson 9b5568b9ab Pass all precision instead of artificially limiting
Signed-off-by: Thomas Jackson <jacksontj.89@gmail.com>
2019-07-09 07:31:37 -07:00
Thomas Jackson c52580de2b Change all time formatting to UTC and off of time.RFC3339Nano
Prometheus has issues parsing RFC3339Nano timestamps if the year has more than 4 digits, in addition it is the second-pass parse attempt. Since this is a client library and the interface is a `time.Time` it makes sense that we pick the clearest simplest format-- so I propose we use the `model.Time` representation of time in our communications to prometheus. This (1) removes the issues with timezones in those queries going downstream and (2) completely works around this #614 issue as the parsing mechanism in prometheus can handle those times in this format.

Related to #614

Signed-off-by: Thomas Jackson <jacksontj.89@gmail.com>
2019-07-09 07:31:37 -07:00
Thomas Jackson 3d8379da8f Add Warnings to LabelValues and LabelNames (#609)
Signed-off-by: Thomas Jackson <jacksontj.89@gmail.com>
2019-06-17 21:27:57 +03:00
Thomas Jackson 063470a3c9 Add warnings to series (#603)
Signed-off-by: Thomas Jackson <jacksontj.89@gmail.com>
2019-06-15 00:28:28 +03:00
Thomas Jackson f213ad9bfc Add /labels API to client (#604)
API ref https://prometheus.io/docs/prometheus/latest/querying/api/#getting-label-names

Signed-off-by: Thomas Jackson <jacksontj.89@gmail.com>
2019-06-14 16:49:58 +02:00
Thomas Jackson 1335ef46bd Pass warnings through on non-error responses (#599)
Return warnings as a separate string slice to simplify handling.

Signed-off-by: Thomas Jackson <jacksontj.89@gmail.com>
2019-06-14 01:40:59 +02:00
Yao Zengzeng 329278ec53 encapsulate target metadata api (#590)
Signed-off-by: YaoZengzeng <yaozengzeng@zju.edu.cn>
2019-05-28 14:27:09 +02:00
Alex Salt 301aa8906b /api/v1/rules: alert value as string (#585)
Signed-off-by: Alexander Saltykov <alexander-s@yandex-team.ru>
2019-05-28 13:57:09 +02:00
Thomas Jackson 7e60220fd3 Switch from encoding/json -> jsoniter (#570)
* Switch from encoding/json -> jsoniter

Signed-off-by: Thomas Jackson <jacksontj.89@gmail.com>
2019-05-28 13:45:06 +02:00
Thomas Jackson d5f3c8d55d Add storage.Warnings to client
Signed-off-by: Thomas Jackson <jacksontj.89@gmail.com>

Fixes #560
2019-05-21 07:36:05 -07:00
Thomas Jackson 3f6cbd9560 Remove encode of params in query before DoGetFallback (#563)
Signed-off-by: Thomas Jackson <jacksontj.89@gmail.com>
2019-05-01 09:28:05 +03:00
Thomas Jackson a4daf0098c Implement POST with get fallback for Query/QueryRange (#557)
* Implement POST with get fallback for Query/QueryRange

Signed-off-by: Thomas Jackson <jacksontj.89@gmail.com>
2019-04-30 10:13:48 +03:00
Bjoern Rabenstein 1173d73405 Increase minimum required Go version to 1.9
This allows us to simplify a bunch of code while still supporting the
last four Go minor versions.

We have also run into minor annoyances a couple of times by now to
keep supporting 1.7 and 1.8.

It's time to pull the plug!

Signed-off-by: Bjoern Rabenstein <bjoern@rabenste.in>
2019-04-28 23:28:57 +02:00
Roald Nefs 7490f0a745 Add alerts endpoint to API client (#552)
Add alerts endpoint to API client. The alerts endpoint returns a list of all active alerts.

Signed-off-by: Roald Nefs <info@roaldnefs.com>
2019-03-25 10:23:28 +02:00
Oleksandr Kushchenko d5f63107bf Use a map to describe discovered labels, as they are not validated by the server (#529)
Signed-off-by: Oleksandr Kushchenko <okushchenko@palantir.com>
2019-01-23 18:39:45 +03:00