Code Monkey home page Code Monkey logo

Comments (7)

amotl avatar amotl commented on June 11, 2024 2

Hi again,

sorry again for my late response to this issue.

I've just checked the code, and found that GrafanaApi() already obtains an argument timeout, which unfortunately defaults to 5 seconds. I agree with Mikhail that this should also be available as an argument to from_url(), amongst other improvements in the same area, and - most importantly - this option should have proper documentation, right?

In the meanwhile, and with any current release of grafana-client, before running any requests, you should be able to do this:

# Create Grafana API wrapper instance, and set timeout.
grafana = GrafanaApi.from_url("https://username:[email protected]/grafana/")
grafana.client.timeout = 60

Let me know if that helps you already, so I can handle that with a corresponding priority if it is still a pain, or if that workaround will fit your needs already. Apologies, Mikhail, for missing that detail because I did not have a look at the code yet at the time I was responding to you.

With kind regards,
Andreas.

https://github.com/panodata/grafana-client/blob/63d67567086a2427bd4386a6578907df9dcbe2b3/grafana_client/api.py#L38-L49

from grafana-client.

dheeg avatar dheeg commented on June 11, 2024 1

Hi @amotl ,

yes absolutely thanks for your work on this!

from grafana-client.

amotl avatar amotl commented on June 11, 2024

Dear Mikhail,

thanks a stack for suggesting this. We will bring it in on the next development iteration. Patches are always welcome.

With kind regards,
Andreas.

from grafana-client.

dheeg avatar dheeg commented on June 11, 2024

Thanks for your work. This feature is important for us as well. Sometimes Grafana needs >5s to create a dashboard.

from grafana-client.

amotl avatar amotl commented on June 11, 2024

For the improvements to the implementation, when they will be conducted, I would like to leave this note here, in order to pick up corresponding guidelines quickly, without needing to research them again. Also, to eventually receive any comments about it.

Recap

  • The current default timeout of 5 seconds is unfortunate.
  • As a workaround, timeout options can be adjusted by using the GrafanaClient object's timeout attribute. It is a bit awkward, so that interface should be improved.
# Create Grafana API wrapper instance, and set timeout.
grafana = GrafanaApi.from_url("https://username:[email protected]/grafana/")
grafana.client.timeout = 60

Proposal

  • The future implementation may just use the defaults of the underlying HTTP library, urllib3 1. There is also excellent documentation about this topic at 2. Following the urllib3 implementation, the new default timeout value will implicitly use socket.getdefaulttimeout(), which is None by default, at least on my machine. Effectively, this would mean "infinite" timeout by default.
  • Adjusting timeout values (total vs. connect vs. read) should also fit into the convenience factory methods from_url() and from_env().

Footnotes

  1. https://urllib3.readthedocs.io/en/stable/reference/urllib3.util.html#urllib3.util.Timeout

  2. https://datagy.io/python-requests-timeouts/

from grafana-client.

amotl avatar amotl commented on June 11, 2024

Choosing sensible default timeout values. 5 seconds, it is.

To contradict my previous statement, I think grafana-client should keep sensible default values for the HTTP timeout options, following the recommendation of the requests authors.

Most requests to external servers should have a timeout attached, in case the server is not responding in a timely manner. By default, requests do not time out unless a timeout value is set explicitly. Without a timeout, your code may hang for minutes or more. 1

I think following HTTPX' recommendations would be a reasonable approach.

HTTPX defaults to including reasonable timeouts for all network operations, meaning that if a connection is not properly established then it should always raise an error rather than hanging indefinitely. The default timeout for network inactivity is five seconds. 2

requests also presents this code example at the first place. So, it can indeed be considered as a recommendation.

requests.get('https://github.com', timeout=5)

Effectively, this would mean the default timeout value does not change at all, will be 5 seconds as before, but its configuration interface will be more friendly, and documentation will be improved. Do you have any objections?

Footnotes

  1. https://requests.readthedocs.io/en/latest/user/advanced/#timeouts

  2. https://www.python-httpx.org/quickstart/#timeouts

from grafana-client.

amotl avatar amotl commented on June 11, 2024

Hi again,

a few improvements have been made with GH-99, and released on behalf of version 3.6.0. Do you think this will satisfy your needs? You can find a corresponding documentation snippet at 1.

With kind regards,
Andreas.

Footnotes

  1. https://github.com/panodata/grafana-client#timeout-settings

from grafana-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.