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

Fix error status propagation to take into account catch/catchError/warnError blocks #343

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?

This PR fixes logic that propagates errors from pipeline nodes to their parents. The problem is that currently errors are propagated unconditionally from a node to its ancestors until the root node is reached. This approach is not always correct, as an error in the pipeline might be caught and suppressed, in which case Jenkins can report as successful the stage that caught the error (along with all its parents). The desired state is to have statuses of the spans sent to Datadog exactly the same as the statuses of corresponding Jenkins pipeline stages, which means the logic should be adjusted to stop propagation if the error was caught.

The motivation to change this now is that there is a customer complaining about the statuses disparity.

Description of the Change

There are 3 ways to catch and suppress an error:

For the latter two BuildPipelineNode class was augmented with an additional field that stores the status that should be applied if an error occurs in that node (with catchError this status can be configured, with warnError the status is always unstable). For the first one, existing field BuildPipelineNode#errorObj is examined: if an error is caught and suppressed, the node that caught it will have null in that field.

Alternate Designs

Possible Drawbacks

Verification Process

Verified manually with a local Jenkins instance and DD staging, and covered with integration tests that contain examples of pipelines where errors are caught using different ways.

Additional Notes

Release Notes

Review checklist (to be filled by reviewers)