Skip to content

Commit 9bb536c

Browse files
add documentation for the server & client side timeout
Signed-off-by: Priyanka Saggu <[email protected]>
1 parent 44b2325 commit 9bb536c

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

Diff for: examples/pod_namespace_watch.py renamed to examples/watch/pod_namespace_watch.py

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
The script will wait for 10 events related to namespaces to occur within
1818
the `timeout_seconds` threshold and then move on to wait for another 10 events
1919
related to pods to occur within the `timeout_seconds` threshold.
20+
21+
22+
Refer to the document below to understand the server-side & client-side
23+
timeout settings for the watch request handler: ~
24+
25+
https://github.com/github.com/kubernetes-client/python/blob/master/examples/watch/timeout-settings.md
2026
"""
2127

2228
from kubernetes import client, config, watch

Diff for: examples/watch/timeout-settings.md

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
**This documentation briefly provides information about the `server side` & `client side` connection timeout settings, in the watch request handler.**
3+
4+
---
5+
6+
There are two inputs available in the client, that could be used to set connection timeouts:
7+
8+
- `timeout_seconds`
9+
- `_request_timeout`
10+
11+
---
12+
13+
#### Sever-side timeout (`kwargs['timeout_seconds'] = n`)
14+
15+
- The value of the argument `timeout_seconds`, **n**, (which is time duration in seconds) is consumed at the server side. It is included in the request URL to the server.
16+
17+
*For eg.* ~ `https://localhost:6443/api/v1/namespaces/default/pods?labelSelector=app%3Ddemo&timeoutSeconds=100&watch=True`
18+
19+
- In case, if the `timeout_seconds` value is set, the value `n` would determine the server-side connection timeout duration.
20+
21+
*For eg.* ~ if `kwargs['timeout_seconds'] = 3600`, then the server-side connection timeout will be equal to 1 hour.
22+
23+
This timeout duration is determined by the expression ~ `timeout = time.Duration(3600) * time.seconds`, *i.e.* `timeout = 1 hour`
24+
25+
***Refer:***
26+
- *[kubernetes/apiserver/pkg/endpoints/handlers/get.go#L255](https://github.com/kubernetes/apiserver/blob/92392ef22153d75b3645b0ae339f89c12767fb52/pkg/endpoints/handlers/get.go#L255)*
27+
28+
- In case, if the `timeout_seconds` value is not set, then the connection timeout will be a randomized value (in seconds) between 0 and `minRequestTimeout`, to spread out load.
29+
30+
It is determined using the expression ~ `timeout = time.Duration(float64(minRequestTimeout) * (rand.Float64() + 1.0))`
31+
32+
Where `minRequestTimeout` indicates the minimum number of seconds a handler must keep a request open before timing it out.
33+
34+
The default value of `minRequestTimeout` is 1800 seconds.
35+
36+
***Refer:***
37+
- *[kubernetes/apiserver/pkg/endpoints/handlers/get.go#L258](https://github.com/kubernetes/apiserver/blob/92392ef22153d75b3645b0ae339f89c12767fb52/pkg/endpoints/handlers/get.go#L258)*
38+
- *[kubernetes/release-1.1/docs/admin/kube-apiserver.md](https://github.com/kubernetes/kubernetes/blob/release-1.1/docs/admin/kube-apiserver.md)*
39+
40+
- In case of a network outage, this timeout value will have no effect & the client will hang indefinitely without raising any exception.
41+
42+
- It is recommended to set this timeout value to a higher number such as 3600 seconds (1 hour).
43+
44+
---
45+
46+
#### Client-side timeout (`kwargs['_request_timeout'] = n`)
47+
48+
- The value of the argument `_request_timeout`, **n** (which is time duration in seconds) is set to the socket used for the connection.
49+
50+
- In case, if the `_request_timeout` value is set, this argument can accept 2 types of input values ~
51+
- integer (int),
52+
- a tuple (with a length of 2)
53+
54+
If it is tuple input type, the first value will be ignored.
55+
56+
- In case of network outage, leading to dropping all packets with no RST/FIN, the timeout value (in seconds) determined by the `request_timeout` argument, would be the time duration for how long the client will wait before realizing & dropping the connection.
57+
58+
- When the timeout happens, an exception will be raised, for eg. ~
59+
60+
`urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='localhost', port=6443): Read timed out.`
61+
62+
- In case, if the `_request_timeout` value is not set, then the default value is **`None`** & socket will have no timeout.
63+
64+
***Refer:***
65+
- [https://docs.python.org/2/library/socket.html#socket.getdefaulttimeout](https://docs.python.org/2/library/socket.html#socket.getdefaulttimeout)
66+
67+
- It is recommended to set this timeout value to a lower number (for eg. ~ maybe 60 seconds.
68+

0 commit comments

Comments
 (0)