prometheus-api-client-python icon indicating copy to clipboard operation
prometheus-api-client-python copied to clipboard

A python wrapper for the prometheus http api

Results 33 prometheus-api-client-python issues
Sort by recently updated
recently updated
newest added

Add optional auth parameters for requests

[{"_id":"63451a2f8402fb318b706a1a","body":"@ugurzongur this looks great! But I don't really know how to test it since I don't have access to an amazon instance. Do you have any suggestions?\r\nCould you also please add a mock test if possible?","issue_id":1660422800223,"origin_id":1215375968,"user_origin_id":22333506,"create_time":1660582732,"update_time":1660582732,"id":1665473071142,"updated_at":"2022-10-11T07:24:31.141000Z","created_at":"2022-10-11T07:24:31.141000Z"},{"_id":"63451a2f8402fb318b706a1b","body":"FWIW I've tested this and was able to pull metrics from my AMP Workspace. This looks good to me and I'd be very happy to have this functionality available.","issue_id":1660422800223,"origin_id":1270615753,"user_origin_id":46289310,"create_time":1665086588,"update_time":1665086588,"id":1665473071145,"updated_at":"2022-10-11T07:24:31.145000Z","created_at":"2022-10-11T07:24:31.145000Z"},{"_id":"6387eb2b5ae95c7a22387ae2","body":"Now that I think about it, the changes seem simple enough that we can merge them.","issue_id":1660422800223,"origin_id":1297363896,"user_origin_id":22333506,"create_time":1667234249,"update_time":1667234249,"id":1669851947612,"updated_at":"2022-11-30T23:45:47.612000Z","created_at":"2022-11-30T23:45:47.612000Z"}] comment

Addresses #244

**Is your feature request related to a problem? Please describe.** Amazon Managed Service for Prometheus (APS) cannot be queried. This is because APS uses SigV4 but prometheus-api-client-python doesn't support that...

Add support for query functions to custom_query_range

[{"_id":"634516276a9f94608c587b14","body":"Hi @NoahZielke thanks for bringing this up! I believe you're right, I'm also unable to use query functions in `get_metric_range_data` like this:\r\n```python\r\nstart_time = parse_datetime(\"3d\")\r\nend_time = parse_datetime(\"now\")\r\nchunk_size = parse_timedelta(\"now\", \"1d\")\r\n\r\nquery = \"rate(scrape_duration_seconds[5m])\"\r\n\r\nmetric_data = pc.get_metric_range_data(\r\n query,\r\n start_time=start_time,\r\n end_time=end_time,\r\n chunk_size=chunk_size,\r\n)\r\n```\r\nAnd yes, it's likely because of the way chunk size is implemented.\r\n\r\n> Is there another way to use these functions\r\n\r\nI was able to work around this problem by using `custom_query_range` instead like this:\r\n```python\r\nstart_time = parse_datetime(\"3d\")\r\nend_time = parse_datetime(\"now\")\r\n\r\nquery = \"rate(scrape_duration_seconds[5m])\"\r\n\r\nmetric_data = pc.custom_query_range(\r\n query,\r\n start_time=start_time,\r\n end_time=end_time,\r\n step=\"1d\",\r\n)\r\n```\r\nDoes this work for your use case too?\r\n\r\n> or does this support need to be added? I don't mind trying to add it if it needs it.\r\n\r\nWhether `get_metric_range_data` should be updated to support this functionality, or users should use `custom_query_range` for such cases would be up for discussion imo \/cc @4n4nd ","issue_id":1660422800229,"origin_id":1171638136,"user_origin_id":15005500,"create_time":1656620379,"update_time":1656620379,"id":1665472039703,"updated_at":"2022-10-11T07:07:19.703000Z","created_at":"2022-10-11T07:07:19.703000Z"},{"_id":"634516276a9f94608c587b15","body":"> Hi @NoahZielke thanks for bringing this up! I believe you're right, I'm also unable to use query functions in `get_metric_range_data` like this:\r\n> \r\n> ```python\r\n> start_time = parse_datetime(\"3d\")\r\n> end_time = parse_datetime(\"now\")\r\n> chunk_size = parse_timedelta(\"now\", \"1d\")\r\n> \r\n> query = \"rate(scrape_duration_seconds[5m])\"\r\n> \r\n> metric_data = pc.get_metric_range_data(\r\n> query,\r\n> start_time=start_time,\r\n> end_time=end_time,\r\n> chunk_size=chunk_size,\r\n> )\r\n> ```\r\n> \r\n> And yes, it's likely because of the way chunk size is implemented.\r\n> \r\n> > Is there another way to use these functions\r\n> \r\n> I was able to work around this problem by using `custom_query_range` instead like this:\r\n> \r\n> ```python\r\n> start_time = parse_datetime(\"3d\")\r\n> end_time = parse_datetime(\"now\")\r\n> \r\n> query = \"rate(scrape_duration_seconds[5m])\"\r\n> \r\n> metric_data = pc.custom_query_range(\r\n> query,\r\n> start_time=start_time,\r\n> end_time=end_time,\r\n> step=\"1d\",\r\n> )\r\n> ```\r\n> \r\n> Does this work for your use case too?\r\n> \r\n> > or does this support need to be added? I don't mind trying to add it if it needs it.\r\n> \r\n> Whether `get_metric_range_data` should be updated to support this functionality, or users should use `custom_query_range` for such cases would be up for discussion imo \/cc @4n4nd\r\n\r\nYes, using `custom_query_range` was the workaround I used also. It isn't as confusing in hindsight, but it was initially, and it's interesting that I wasn't the only one with the issue. Thanks","issue_id":1660422800229,"origin_id":1172881815,"user_origin_id":22875039,"create_time":1656760783,"update_time":1656760783,"id":1665472039706,"updated_at":"2022-10-11T07:07:19.706000Z","created_at":"2022-10-11T07:07:19.706000Z"},{"_id":"6387e97070db72139b19b38b","body":"Question: If I use `metric_data = prom.get_metric_range_data(...)` then I can use `metric_object_list = MetricsList(metric_data)` call. However, If I use `metric_data = prom.custom_query_range(...)` then the `MetricsList()` call fails with `KeyError: '__name__'`. I can fix this by running this loop before calling `MetricsList()`.\r\n```\r\n for r in metric_data:\r\n r['metric'][\"__name__\"] = metric_name\r\n```\r\nWhere `metric_name` is part of my query string. \r\n\r\nIs this right? Or am I crossing the streams (so to speak).\r\n\r\nThanks in advance","issue_id":1660422800229,"origin_id":1296102762,"user_origin_id":4521085,"create_time":1667104140,"update_time":1667104140,"id":1669851504863,"updated_at":"2022-11-30T23:38:24.862000Z","created_at":"2022-11-30T23:38:24.862000Z"},{"_id":"6387e97070db72139b19b38c","body":"> Is this right? Or am I crossing the streams (so to speak).\r\n\r\nThis is the \"right\" way to do it since Prometheus doesn't return a metric name when you use functions. I wasn't sure if the library should add the query string as the name by default. wdyt @chauhankaranraj?","issue_id":1660422800229,"origin_id":1297383180,"user_origin_id":22333506,"create_time":1667235182,"update_time":1667235182,"id":1669851504868,"updated_at":"2022-11-30T23:38:24.868000Z","created_at":"2022-11-30T23:38:24.868000Z"},{"_id":"663c5f172cfd0d66a802e36c","body":"> > Is this right? Or am I crossing the streams (so to speak).\r\n> \r\n> This is the \"right\" way to do it since Prometheus doesn't return a metric name when you use functions. I wasn't sure if the library should add the query string as the name by default. wdyt @chauhankaranraj?\r\n\r\nI encountered same issue with query fuction when using custom_query_range(). Is it possible to add a parameter for custom_query_range() to specify the missing metric name ? ","issue_id":1660422800229,"origin_id":1345548436,"user_origin_id":26592945,"create_time":1670763605,"update_time":1670763605,"id":1715232535145,"updated_at":"2024-05-09T05:28:55.144000Z","created_at":"2024-05-09T05:28:55.144000Z"},{"_id":"663c5f172cfd0d66a802e36d","body":"> > Is this right? Or am I crossing the streams (so to speak).\r\n> \r\n> This is the \"right\" way to do it since Prometheus doesn't return a metric name when you use functions. I wasn't sure if the library should add the query string as the name by default. wdyt @chauhankaranraj?\r\n\r\nHm that's an interesting problem. Do we know if users tend to pass the return value of `custom_query_range()` to `MetricsList()`? If yes, and if that is one of the intended use cases of the `MetricsList` class, then I think we should make the query string as the name by default.","issue_id":1660422800229,"origin_id":1491248562,"user_origin_id":15005500,"create_time":1680234658,"update_time":1680234658,"id":1715232535149,"updated_at":"2024-05-09T05:28:55.149000Z","created_at":"2024-05-09T05:28:55.149000Z"}] comment

I found that I was unable to use [query functions](https://prometheus.io/docs/prometheus/latest/querying/functions/#rate) on [get_metric_range](https://github.com/4n4nd/prometheus-api-client-python/blob/a3e2cde7419ba97224f7374641b90c77bec15b9b/prometheus_api_client/prometheus_connect.py#L174) because of how the chunk is implemented. Is there another way to use these functions or does this...

Can the metrics_name be in the format of an expression?

[{"_id":"634514c009a35269b780bbe3","body":"Hi @lynBIT, thanks for opening an issue :smile:\r\n\r\nI believe it is possible, but using `custom_query_range` instead of `get_metric_range_data`. I was able to run a query similar to yours on the [robustperception.io demo prometheus instance](http:\/\/demo.robustperception.io:9090\/graph):\r\n```python\r\nstart_time = parse_datetime(\"3d\")\r\nend_time = parse_datetime(\"now\")\r\n\r\nquery = '1 - sum(increase(node_cpu_seconds_total{mode=\"idle\"}[5m])) by (instance) \/ sum(increase(node_cpu_seconds_total[5m])) by (instance)'\r\n\r\nmetric_data = pc.custom_query_range(\r\n query,\r\n start_time=start_time,\r\n end_time=end_time,\r\n step=\"1d\",\r\n)\r\nmetric_data\r\n\r\n# output:\r\n[{'metric': {'instance': 'demo.do.prometheus.io:9100'},\r\n 'values': [[1656361768, '0.06370670074256046'],\r\n [1656448168, '0.057729768018532024'],\r\n [1656534568, '0.06394668746362964'],\r\n [1656620968, '0.06474131821663776']]}]\r\n```\r\n\r\nHope this helps!","issue_id":1660422800232,"origin_id":1171647064,"user_origin_id":15005500,"create_time":1656621013,"update_time":1656621013,"id":1665471680110,"updated_at":"2022-10-11T07:01:20.110000Z","created_at":"2022-10-11T07:01:20.110000Z"},{"_id":"663c5ee74a8e87d14e0c9f7c","body":"Hi @lynBIT, did the above suggestion help resolve your problem? Can this issue be closed now?","issue_id":1660422800232,"origin_id":1491249161,"user_origin_id":15005500,"create_time":1680234732,"update_time":1680234732,"id":1715232487625,"updated_at":"2024-05-09T05:28:07.625000Z","created_at":"2024-05-09T05:28:07.625000Z"}] comment

**Describe the solution you'd like** I want to get the value of the computed expression through Prometheus' API。 pc.get_metric_range_data(metric_name=train_data[0].metric_name ....) Can I make metric_name = (1- sum(increase(node_cpu_seconds_total{mode='idle',instance='172.29.3.13:9101'}[2m])) by (instance)/sum(increase(node_cpu_seconds_total{instance='172.29.3.13:9101'}[2m])) by...

Async Querying

[{"_id":"63451d7709a35269b780c289","body":"Thanks for the suggestion @peterder72, I think that's a great idea!\r\n\r\n> If there are no objections, I can start with the implementation.\r\n\r\nSure, feel free to get started with the implementation :)\r\n\r\n\/assign peterder72","issue_id":1660422800235,"origin_id":1150380501,"user_origin_id":15005500,"create_time":1654720229,"update_time":1654720229,"id":1665473911348,"updated_at":"2022-10-11T07:38:31.347000Z","created_at":"2022-10-11T07:38:31.347000Z"},{"_id":"663c5ef62308c3a9030f8b0e","body":"Hi there !\r\n\r\nI wonder if there's news about this issue ?","issue_id":1660422800235,"origin_id":1589279920,"user_origin_id":94912547,"create_time":1686661677,"update_time":1686661677,"id":1715232502166,"updated_at":"2024-05-09T05:28:22.166000Z","created_at":"2024-05-09T05:28:22.166000Z"}] comment

I'm using this library for a project of mine where I need to gather 48h worth of timestamp data. While the library gets the job done, since all requests are...

**Describe the bug** The `PrometheusApiClientException` class naming violates pep8 N818 naming convention. So this is resulting in pre-commit-check failing on every PR, even if the PR is not related to...

Fix [FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.]

[{"_id":"636ac10e8041c95dfb282f05","body":"@psujit775 could you please check why the tests are failing? Maybe the pandas version needs to be updated","issue_id":1664493206114,"origin_id":1233070720,"user_origin_id":22333506,"create_time":1661958775,"update_time":1661958775,"id":1667940622397,"updated_at":"2022-11-08T20:50:22.397000Z","created_at":"2022-11-08T20:50:22.397000Z"},{"_id":"636ac10e8041c95dfb282f06","body":"@4n4nd updated Pipfile and requirements.txt to pandas min version >=1.4.0.\r\n\r\nDeprecations reference: https:\/\/pandas.pydata.org\/docs\/whatsnew\/v1.4.0.html#whatsnew-140-deprecations-frame-series-append","issue_id":1664493206114,"origin_id":1233335783,"user_origin_id":50701338,"create_time":1661974028,"update_time":1661975985,"id":1667940622403,"updated_at":"2022-11-08T20:50:22.403000Z","created_at":"2022-11-08T20:50:22.403000Z"},{"_id":"636ac10e8041c95dfb282f07","body":"@psujit775 could you also update the piplock?","issue_id":1664493206114,"origin_id":1285808902,"user_origin_id":22333506,"create_time":1666281877,"update_time":1666281877,"id":1667940622408,"updated_at":"2022-11-08T20:50:22.407000Z","created_at":"2022-11-08T20:50:22.407000Z"},{"_id":"636ac10e8041c95dfb282f08","body":"@4n4nd updated the Pipfile.lock file.","issue_id":1664493206114,"origin_id":1285858714,"user_origin_id":50701338,"create_time":1666284229,"update_time":1666284229,"id":1667940622411,"updated_at":"2022-11-08T20:50:22.411000Z","created_at":"2022-11-08T20:50:22.411000Z"},{"_id":"636ac10e8041c95dfb282f09","body":"Thanks!","issue_id":1664493206114,"origin_id":1285869822,"user_origin_id":22333506,"create_time":1666284839,"update_time":1666284839,"id":1667940622416,"updated_at":"2022-11-08T20:50:22.415000Z","created_at":"2022-11-08T20:50:22.415000Z"},{"_id":"636ac10e8041c95dfb282f0a","body":"Thank you Anand for merging it.\n\nI know it's just a little change but I'm so happy.\n\nThanks again,\n\nOn Thu, Oct 20, 2022 at 10:24 PM Anand Sanmukhani ***@***.***>\nwrote:\n\n> Thanks!\n>\n> \u2014\n> Reply to this email directly, view it on GitHub\n> <https:\/\/github.com\/4n4nd\/prometheus-api-client-python\/pull\/247#issuecomment-1285869822>,\n> or unsubscribe\n> <https:\/\/github.com\/notifications\/unsubscribe-auth\/AMC2IGT7WPM7NUBPQUCGG6DWEF2LDANCNFSM6AAAAAAQBNTRAQ>\n> .\n> You are receiving this because you were mentioned.Message ID:\n> ***@***.***>\n>\n","issue_id":1664493206114,"origin_id":1285884442,"user_origin_id":50701338,"create_time":1666285630,"update_time":1666285630,"id":1667940622419,"updated_at":"2022-11-08T20:50:22.419000Z","created_at":"2022-11-08T20:50:22.419000Z"},{"_id":"636ac10e8041c95dfb282f0b","body":"Thank you for working on it!","issue_id":1664493206114,"origin_id":1285891998,"user_origin_id":22333506,"create_time":1666286055,"update_time":1666286055,"id":1667940622422,"updated_at":"2022-11-08T20:50:22.422000Z","created_at":"2022-11-08T20:50:22.422000Z"}] comment

Fix [FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.] Upstream issue: https://github.com/pandas-dev/pandas/issues/35407

Hi, if you were to put your disable_ssl as false, where else would I be required to configure my cert path etc? Thanks!

#277 Add the ability to specify request timeouts

[{"_id":"66cd8e0d5a1d13a44707c7fb","body":"@FRosner Could you please add a couple of unit tests for this change?","issue_id":1709750358473,"origin_id":1969993753,"user_origin_id":22090997,"create_time":1709157721,"update_time":1709157721,"id":1724747277829,"updated_at":"2024-08-27T08:27:57.829000Z","created_at":"2024-08-27T08:27:57.829000Z"},{"_id":"66cd8e0d5a1d13a44707c7fc","body":"> Could you please add a couple of unit tests for this change?\r\n\r\nSure @4n4nd! Do you have a pointer for me on which file to add this to? Do you have any tests that simulate making requests to Prom where I can add a case that times out?","issue_id":1709750358473,"origin_id":1970630087,"user_origin_id":3427394,"create_time":1709194724,"update_time":1709194724,"id":1724747277832,"updated_at":"2024-08-27T08:27:57.832000Z","created_at":"2024-08-27T08:27:57.832000Z"},{"_id":"66cd8e0d5a1d13a44707c7fd","body":"@yashvardhannanavati ","issue_id":1709750358473,"origin_id":1971054357,"user_origin_id":22333506,"create_time":1709210311,"update_time":1709210311,"id":1724747277836,"updated_at":"2024-08-27T08:27:57.836000Z","created_at":"2024-08-27T08:27:57.836000Z"},{"_id":"66cd8e0d5a1d13a44707c7fe","body":"> > Could you please add a couple of unit tests for this change?\r\n> \r\n> Sure @4n4nd! Do you have a pointer for me on which file to add this to? Do you have any tests that simulate making requests to Prom where I can add a case that times out?\r\n\r\n@FRosner You could add a test to https:\/\/github.com\/4n4nd\/prometheus-api-client-python\/blob\/master\/tests\/test_prometheus_connect.py ","issue_id":1709750358473,"origin_id":1984000803,"user_origin_id":22090997,"create_time":1709830563,"update_time":1709830563,"id":1724747277840,"updated_at":"2024-08-27T08:27:57.839000Z","created_at":"2024-08-27T08:27:57.839000Z"},{"_id":"66cd8e0d5a1d13a44707c7ff","body":"Thanks! I got distracted a bit. I will try to get to this by next week.","issue_id":1709750358473,"origin_id":2006501274,"user_origin_id":3427394,"create_time":1710840706,"update_time":1710840706,"id":1724747277843,"updated_at":"2024-08-27T08:27:57.843000Z","created_at":"2024-08-27T08:27:57.843000Z"},{"_id":"66cd8e0d5a1d13a44707c800","body":"Sorry, I'm back after a bit. I looked into the test and it seems I have to bring my own Prometheus? Is there a specific reason you are not using testcontainers?\r\n\r\nEither way, do you have a preference on how I can delay the response so that I hit a timeout? A mock server? Toxy proxy?","issue_id":1709750358473,"origin_id":2020123415,"user_origin_id":3427394,"create_time":1711450796,"update_time":1711450796,"id":1724747277847,"updated_at":"2024-08-27T08:27:57.846000Z","created_at":"2024-08-27T08:27:57.846000Z"},{"_id":"66cd8e0d5a1d13a44707c801","body":"@FRosner you can see how we are testing other functions [here](https:\/\/github.com\/4n4nd\/prometheus-api-client-python\/blob\/master\/tests\/test_prometheus_connect.py#L144) using a mocked network. In addition to that, we use [this public prometheus instance](http:\/\/demo.robustperception.io:9090\/) to run some of our tests.\r\n\r\nYou can basically execute the following command to run the test suite:\r\n`PROM_URL=\"http:\/\/demo.robustperception.io:9090\/\" pytest`","issue_id":1709750358473,"origin_id":2052742419,"user_origin_id":22333506,"create_time":1712969075,"update_time":1712969075,"id":1724747277850,"updated_at":"2024-08-27T08:27:57.849000Z","created_at":"2024-08-27T08:27:57.849000Z"},{"_id":"66cd8e0d5a1d13a44707c803","body":"I respect check have to be passed, but for anyone who is searching **for a quick solution** i will provide a fork that adds an addtional request_args parameter to every function. This solution is not perfect at all, because the parameters get parsed differently on different levels and functions, but i thought i could may help someone in special cases.\r\n\r\n# Usage\r\nJust put the additional parameters into the request_args parameter. These kwargs get mostly passed to [requests.Session.request](https:\/\/tedboy.github.io\/requests\/generated\/generated\/requests.Session.request.html)\r\n```\r\nexample_data = prometheus_connection.get_metric_range_data(\r\n metric_name=\"example\",\r\n start_time=start_time,\r\n end_time=end_time,\r\n request_args={'timeout': 1} #<-- Added parameter\r\n)\r\n```\r\nrequest_args argument equals **kwargs in the named method.\r\n\r\n# Installation\r\n```\r\nset PYTHONUTF8=1#<-- needed for the build on windows\r\npip install git+https:\/\/github.com\/Mo-to\/prometheus-api-client-python.git\r\n```\r\n\r\nThe changes are in this [fork](https:\/\/github.com\/Mo-to\/prometheus-api-client-python\/tree\/master) in this [commit](https:\/\/github.com\/Mo-to\/prometheus-api-client-python\/commit\/064deab4e839ed8a30f4c22d886fec647d2e5f5a)\r\n","issue_id":1709750358473,"origin_id":2181797075,"user_origin_id":62118334,"create_time":1718931527,"update_time":1718931527,"id":1724747277855,"updated_at":"2024-08-27T08:27:57.854000Z","created_at":"2024-08-27T08:27:57.854000Z"}] comment

# Summary I am adding the ability to configure request timeouts. # Details - Add a global request timeout object to be used for all requests (https://github.com/4n4nd/prometheus-api-client-python/commit/a0dcfcf8448ed5a0815f1fd15e5fd6d975bf0f71) - Add request...

Allow setting request timeout

[{"_id":"66cd8dfcb3dc7ee8eb10124a","body":"@4n4nd let me know what you think about this. I can try to submit a PR, but I just wanted to confirm with you if you agree with the issue \/ proposed solution.","issue_id":1709750358478,"origin_id":1963752588,"user_origin_id":3427394,"create_time":1708942206,"update_time":1708942206,"id":1724747260843,"updated_at":"2024-08-27T08:27:40.842000Z","created_at":"2024-08-27T08:27:40.842000Z"},{"_id":"66cd8dfcb3dc7ee8eb10124b","body":"yeah that seems like a reasonable solution. Could you please create a PR?","issue_id":1709750358478,"origin_id":1965298062,"user_origin_id":22333506,"create_time":1708982122,"update_time":1708982122,"id":1724747260846,"updated_at":"2024-08-27T08:27:40.846000Z","created_at":"2024-08-27T08:27:40.846000Z"},{"_id":"66cd8dfcb3dc7ee8eb10124c","body":"> Could you please create a PR?\r\n\r\nhttps:\/\/github.com\/4n4nd\/prometheus-api-client-python\/pull\/280","issue_id":1709750358478,"origin_id":1968508380,"user_origin_id":3427394,"create_time":1709110371,"update_time":1709110371,"id":1724747260850,"updated_at":"2024-08-27T08:27:40.849000Z","created_at":"2024-08-27T08:27:40.849000Z"}] comment

**Is your feature request related to a problem? Please describe.** We see requests getting stuck forever which blocks our app. The fix is to set a request timeout, which is...