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

Allow setting request timeout

Open FRosner opened this issue 1 year ago • 3 comments

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 not possible with the current APIs.

Describe the solution you'd like

I'd like the ability to provide a global timeout when creating the client, as well as the ability to override the timeout for each request.

        response = self._session.get(
            "{0}/api/v1/query".format(self._url),
            params={**{"query": query}, **params},
            verify=self._ssl_verification,
            timeout=self._timeout,
        )

Describe alternatives you've considered

I don't think there are good alternatives. You gotta be defensive towards requests getting stuck.

FRosner avatar Feb 19 '24 16:02 FRosner

@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.

FRosner avatar Feb 26 '24 10:02 FRosner

yeah that seems like a reasonable solution. Could you please create a PR?

4n4nd avatar Feb 26 '24 21:02 4n4nd

Could you please create a PR?

https://github.com/4n4nd/prometheus-api-client-python/pull/280

FRosner avatar Feb 28 '24 08:02 FRosner