jenkinsci / hetzner-cloud-plugin

Hetzner cloud integration for Jenkins
https://plugins.jenkins.io/hetzner-cloud/
Apache License 2.0
24 stars 8 forks source link

Dynamic "Keep around minutes" according to Hetzner's hourly billing cycle #30

Closed sandrinr closed 2 years ago

sandrinr commented 2 years ago

What feature do you want to see added?

This is a request for an optimization around how Jenkins manages spawned Hetzner server resources. Currently, the plugin lets idle resources stay around for a configurable amount of time of which the default is 10 minutes. This can lead to the situation where multiple nodes are created and torn down within the same hour.

Hetzner bills its server resources on a hourly basis. The customer pays for every started hour. Jenkins normally does not know about the potential future workload it has to cope with. By letting nodes run idle just before a new hour would be started, Jenkins could make maximum use out of the already spawned resources.

Upstream changes

No response

rkosegi commented 2 years ago

Hi @sandrinr, thanks for interesting idea.

I can see 2 potential issues here:

  1. If Jenkins controller's clock is skewed
  2. How retention strategy works The number of minutes after which the strategy would like to be checked again. The strategy may be rechecked earlier or later than this!

This could lead in theory to consistent over-billing by one hour. So we would probably need some time buffer before whole hour is wrapped. Will look into to it soon

rkosegi commented 2 years ago

With latest release you can now specify 2 different ways of how agent is shutdown. Default being what was done until now to not break existing installations.

Second option will shutdown agent just before billing cycle completes: image

As mentioned in comment above, there is safety buffer of 5 minutes.

@sandrinr looking forward for feedback :wink:

sandrinr commented 2 years ago

Thanks a lot @rkosegi for providing this feature so quickly! Looking at our cloud statistics after the upgrade pretty much shows what I would expect.

image