jenkinsci / datadog-plugin

A Jenkins plugin used to forward metrics, events, and service checks to an account at Datadog, automatically.
https://plugins.jenkins.io/datadog/
MIT License
30 stars 48 forks source link

Add backoff to agent logger/statsd/http clients #352

Closed nikita-tkachenko-datadog closed 1 year ago

nikita-tkachenko-datadog commented 1 year ago

Requirements for Contributing to this repository

What does this PR do?

Adds exponential backoff to re-initialisation of HTTP logger, StatsD client and HTTP client that are used to communicate with the agent.

A customer might misconfigure their agent integration, in which case one or more of the clients listed above will not be able to initialise properly. If a client is not fully initialised, every request to it will lead to a re-init attempt. This is problematic, as initialising these clients is expensive. The problem is especially pronounced with the logger, as it receives the biggest number of request. This constant reinitialisation loop can consume a lot of resources (depending on the customer's workload) and lead to severe performance degradation.

While the plugin is not expected to work correctly if it is misconfigured, it should degrade gracefully and should not affect customer's jobs and pipelines.

Description of the Change

This change adds exponential back-off to initialisation of the three clients listed above. There is now a delay between re-initialisation attempts, starting at 100 ms and doubling every time initialisation fails, up to a maximum of 60 seconds. In case initialisation is successful, the delay is reset back to 100 ms so that subsequent errors lead to faster re-tries.

Alternate Designs

Possible Drawbacks

In case there is an intermittent network issue, clients will take longer to re-initialise (up to 1 minute in the absolute worst case, that is if the connectivity is lost for a period longer than this).

Verification Process

Verified manually with a dockerized Jenkins instance.

Additional Notes

Release Notes

Review checklist (to be filled by reviewers)