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

Short-circuit StageData creation in trace generation #430

Closed msbit01 closed 2 months ago

msbit01 commented 2 months ago

Requirements for Contributing to this repository

What does this PR do?

This is a fix for https://github.com/jenkinsci/datadog-plugin/issues/429. This change will cause trace generation to short circuit before creating an unbounded number of StageData objects.

Description of the Change

Prevent creation of an unbounded number of StageData objects by limiting the number of objects created to be at most the number of characters allowed in the json object created from said objects. This is a conservative approach that could be refined but is simple and good enough in that it avoids unbounded object creation.

Alternate Designs

I considered computing the json and keeping track of the running length of the json object that would be created and checking to see if its length would exceed the limit. That would be a more precise approach than simply counting the number of stages but as my goal was just to bound the number of stages and not necessarily have the bound be perfect, I preferred this approach for its simplicity.

Possible Drawbacks

Verification Process

I confirmed that a test version of the plugin didn't result in the generation of millions of StageData objects as I had seen in previous tests.

Additional Notes

Release Notes

Review checklist (to be filled by reviewers)

tsmsbit commented 2 months ago

@nikita-tkachenko-datadog thanks for the rapid feedback! When do you think it would get released?

nikita-tkachenko-datadog commented 2 months ago

@nikita-tkachenko-datadog thanks for the rapid feedback! When do you think it would get released?

I will try to do a release tomorrow