client icon indicating copy to clipboard operation
client copied to clipboard

Add configurable timeout for a HTTPClient

Open octo47 opened this issue 3 years ago • 3 comments

In some large Kubernetes deployments various techniques may be applied to protect API:

  • throttling -> connection may take longer then default 1 second
  • large deployments -> read may require additional timeout tuning.

Suggestion:

  • we can accept additional parameter HTTPClient.Configuration.Timeout

Alternatives considered:

  • Accept full HTTPClient -> will make TLS configuration more complicated
  • Accept full HTTPClient.Configuation -> frankly not many parameters actually can be configured, so better to be focused and just accept Timeout as the most environment specific out of all other HTTPClient.Configuation parameters

octo47 avatar Oct 06 '22 11:10 octo47

@octo47 Hey 👋 Yes, this is really useful. However, I think this parameter should be part of the KubernetesClientConfig. The thing is, I haven't found a way yet, to make it easily configurable w/o providing the whole config object. And like you said, their is not much we can configure in the HTTPClient.Configuation. The only other candidate would be redirectConfiguration. I'll try a few things and report back 😉

iabudiab avatar Oct 09 '22 23:10 iabudiab

thanks @iabudiab , definitely worth to think. I was noticing that KubernetesClientConfig is coming from .kube/config so thought that client timeout is something coming from the application using KubeClient rather k8s itself. That's why thought it could be external. But thanks for looking into, looking forward to get this fixed! Thanks.

octo47 avatar Oct 12 '22 08:10 octo47

@octo47 hey there, sorry for the delay 🙈 😅 I finally found some time to test some ideas and have settled on one variant. How about something like this:

let config = KubernetesClientConfig.initialize(
     timeout: .init(connect: .seconds(1), read: .seconds(60)),
     redirectConfiguration: .follow(max: 5, allowCycles: false)
)
let client = KubernetesClient(config: config!, logger: logger)

KubernetesClientConfig now exposes a static method to initialise a config (by loading a local kubeconfig or a service account) while also accepting any override configurations. In this case the timeout and redirectConfiguration.

iabudiab avatar Oct 19 '22 21:10 iabudiab

@octo47 This landed in https://github.com/swiftkube/client/releases/tag/0.12.0

I've made some changes as described in https://github.com/swiftkube/client/pull/18#issuecomment-1284616210

iabudiab avatar Jan 25 '23 19:01 iabudiab