Commit Graph

92 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
Joseph Woodward 44ce5e1ee5
Ensure tests verify request params (#1047)
* Ensure tests verify request params

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

* Fix error message

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

* gofumpt-ed with extra.

Signed-off-by: bwplotka <bwplotka@gmail.com>

Co-authored-by: bwplotka <bwplotka@gmail.com>
2022-08-02 11:24:17 +02:00
inosato 44c2c4de85
Remove ioutil (#1096)
Signed-off-by: inosato <si17_21@yahoo.co.jp>
2022-08-02 10:27:49 +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
Björn Rabenstein 3cd398565b
Merge pull request #843 from prometheus/beorn7/release
Update dependencies
2021-03-13 18:46:33 +01: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
beorn7 a60c63e313 Update dependencies
Signed-off-by: beorn7 <beorn@grafana.com>
2021-03-11 20:22:47 +01: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
Bartlomiej Plotka 39b478e90c
Added example api code showing how to add auth tokens and user agents to prom client. (#817)
* Added example api code showing how to add auth tokens and user agents to prom client.

Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>

* Ran go mod tidy.

Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
2020-11-20 19:58:16 +00: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 6c43f2ebc2 api/prometheus/v1/api_test.go: Add test case for runtimeinfo endpoint
Signed-off-by: Lili Cosic <cosiclili@gmail.com>
2020-05-18 20:12:53 +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 7810669cc3 Update api/prometheus/v1/api_test.go
Co-Authored-By: Tobias Guggenmos <tguggenm@redhat.com>
Signed-off-by: gotjosh <josue@grafana.com>
2020-02-27 17:52:05 +00:00
gotjosh bd79fe1bf1 Update api/prometheus/v1/api_test.go
Co-Authored-By: Tobias Guggenmos <tguggenm@redhat.com>
Signed-off-by: gotjosh <josue@grafana.com>
2020-02-27 17:52:05 +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 bd858421cd Fixed TestDoGetFallback test
Signed-off-by: Joe Elliott <number101010@gmail.com>
2019-12-11 09:36:49 -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
Beni Cherniavsky-Paskin 38c67520a3 api client examples: avoid shadowing package with variable
Signed-off-by: Beni Cherniavsky-Paskin <cben@redhat.com>
2019-12-09 14:55:16 +02:00
beorn7 b8308329f0 Fix function names in API examples
The part after the underscore has to be lowercase. Otherwise, it is
seen as the name of a Go type, which doesn't exist, which will result
in the example not showing up in godoc.

Signed-off-by: beorn7 <beorn@grafana.com>
2019-10-15 13:43:53 +02: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
Chris Marchbanks 48fdc3021b
Provide godoc examples for using the api
Closes #194

Signed-off-by: Chris Marchbanks <csmarchbanks@gmail.com>
2019-08-07 20:53:38 -06: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