Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#277 Add the ability to specify request timeouts #280

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

FRosner
Copy link

@FRosner FRosner commented Feb 28, 2024

Summary

I am adding the ability to configure request timeouts.

Details

  • Add a global request timeout object to be used for all requests (a0dcfcf)
  • Add request timeouts for custom queries, which overwrite the global timeout if set (e0dd4a6)

References

@yashvardhannanavati
Copy link

@FRosner Could you please add a couple of unit tests for this change?

prometheus_api_client/prometheus_connect.py Outdated Show resolved Hide resolved
prometheus_api_client/prometheus_connect.py Outdated Show resolved Hide resolved
prometheus_api_client/prometheus_connect.py Outdated Show resolved Hide resolved
@FRosner
Copy link
Author

FRosner commented Feb 29, 2024

Could you please add a couple of unit tests for this change?

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?

@4n4nd
Copy link
Owner

4n4nd commented Feb 29, 2024

@yashvardhannanavati

@yashvardhannanavati
Copy link

Could you please add a couple of unit tests for this change?

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?

@FRosner You could add a test to https://github.com/4n4nd/prometheus-api-client-python/blob/master/tests/test_prometheus_connect.py

@FRosner
Copy link
Author

FRosner commented Mar 19, 2024

Thanks! I got distracted a bit. I will try to get to this by next week.

@FRosner
Copy link
Author

FRosner commented Mar 26, 2024

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?

Either way, do you have a preference on how I can delay the response so that I hit a timeout? A mock server? Toxy proxy?

@4n4nd
Copy link
Owner

4n4nd commented Apr 13, 2024

@FRosner you can see how we are testing other functions here using a mocked network. In addition to that, we use this public prometheus instance to run some of our tests.

You can basically execute the following command to run the test suite:
PROM_URL="http://demo.robustperception.io:9090/" pytest

@Mo-to
Copy link

Mo-to commented Jun 21, 2024

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.

Usage

Just put the additional parameters into the request_args parameter. These kwargs get mostly passed to requests.Session.request

example_data = prometheus_connection.get_metric_range_data(
        metric_name="example",
        start_time=start_time,
        end_time=end_time,
        request_args={'timeout': 1} #<-- Added parameter
)

request_args argument equals **kwargs in the named method.

Installation

set PYTHONUTF8=1#<-- needed for the build on windows
pip install git+https://github.com/Mo-to/prometheus-api-client-python.git

The changes are in this fork in this commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow setting request timeout
4 participants