Skip to content

Fix Datadog pipeline options scope#468

Merged
nikita-tkachenko-datadog merged 5 commits into
masterfrom
nikita-tkachenko/fix-datadog-step-scope
Dec 5, 2024
Merged

Fix Datadog pipeline options scope#468
nikita-tkachenko-datadog merged 5 commits into
masterfrom
nikita-tkachenko/fix-datadog-step-scope

Conversation

@nikita-tkachenko-datadog

@nikita-tkachenko-datadog nikita-tkachenko-datadog commented Nov 7, 2024

Copy link
Copy Markdown
Collaborator

Requirements for Contributing to this repository

  • Fill out the template below. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion.
  • The pull request must only fix one issue at the time.
  • The pull request must update the test suite to demonstrate the changed functionality.
  • After you create the pull request, all status checks must be pass before a maintainer reviews your contribution. For more details, please see CONTRIBUTING.

What does this PR do?

Fixes the scope of datadog pipeline options:

  • test visibility auto-instrumentation is only applied to the stages where datadog option is present
  • custom tags are only applied to the stages where datadog option is present

See examples for better understanding.

In the below pipeline test visibility auto-instrumentation and "myTag" custom tag will be applied for every stage:

pipeline {
    agent any
    options {
        datadog(
            testVisibility: [ enabled: true, ...],
            tags: ["myTag:myValue"]
        )
    }
    stages {
        stage('Stage 1') {
            steps {
                ...
            }
        }
        
        stage('Stage 2') {
            steps {
                ...
            }
        }
        
        stage('Stage 3') {
            steps {
                ...
            }
        }
    }
}

In the below pipeline test visibility auto-instrumentation and "myTag" custom tag will be applied only for Stage 2:

pipeline {
    agent any
    stages {
        stage('Stage 1') {
            steps {
                ...
            }
        }
        
        stage('Stage 2') {
            options {
                datadog(
                    testVisibility: [ enabled: true, ...],
                    tags: ["myTag:myValue"]
                )
            }
            steps {
                ...
            }
        }
        
        stage('Stage 3') {
            steps {
                ...
            }
        }
    }
}

In the below pipeline test visibility auto-instrumentation and "myTag" custom tag will be applied for Stage 2, Stage 2.1, Stage 2.2, Stage 2.3.
Additionally, "myOtherTag" custom tag will be applied to Stage 2.2.

pipeline {
    agent any
    stages {
        stage('Stage 1') {
            steps {
                ...
            }
        }
        
        stage('Stage 2') {
            options {
                datadog(
                    testVisibility: [ enabled: true, ...],
                    tags: ["myTag:myValue"]
                )
            }
            stages {
                stage('Stage 2.1') {
                    steps {
                        ...
                    }
                }

                stage('Stage 2.2') {
                    options {
                        datadog(tags: ["myOtherTag:myOtherValue"])
                    }
                    steps {
                        ...
                    }
                }

                stage('Stage 2.3') {
                    steps {
                        ...
                    }
                }
            }
        }
        
        stage('Stage 3') {
            steps {
                ...
            }
        }
    }
}

Description of the Change

Alternate Designs

Possible Drawbacks

Verification Process

Additional Notes

Release Notes

Review checklist (to be filled by reviewers)

  • Feature or bug fix MUST have appropriate tests (unit, integration, etc...)
  • PR title must be written as a CHANGELOG entry (see why)
  • Files changes must correspond to the primary purpose of the PR as described in the title (small unrelated changes should have their own PR)
  • PR must have one changelog/ label attached. If applicable it should have the backward-incompatible label attached.
  • PR should not have do-not-merge/ label attached.
  • If Applicable, issue must have kind/ and severity/ labels attached at least.

@nikita-tkachenko-datadog nikita-tkachenko-datadog added changelog/Fixed Fixed features results into a bug fix version bump documentation Documentation related changes labels Nov 7, 2024
@nikita-tkachenko-datadog
nikita-tkachenko-datadog force-pushed the nikita-tkachenko/fix-datadog-step-scope branch from a6b533c to 8463b71 Compare November 20, 2024 09:49
@nikita-tkachenko-datadog
nikita-tkachenko-datadog marked this pull request as ready for review November 20, 2024 09:49

@drodriguezhdez drodriguezhdez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped some questions about some scenarios that combines options both at root and at stage level. Finally, also dropped some comments about the complete renaming from TestVisibility to TestOptimization.

public TestVisibility() {
}

public TestVisibility(boolean enabled, String serviceName, Collection<TracerLanguage> languages, Map<String, String> additionalVariables) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we name this TestOptimization or TestOptimizationConfig class? (Given the fact that's just a model class with getters/setters that keeps the config of Test Optimization)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, renamed.

Comment on lines +13 to +15
options {
datadog(tags: ["outer_tag:value"])
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to have (and if so, what happens if):

  • tags at root level and tags at the stage level at the same time?
  • tags at root level with the same key than the tags at the stage level at the same time?

@nikita-tkachenko-datadog nikita-tkachenko-datadog Dec 5, 2024

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tags at root level and tags at the stage level at the same time?

yes, this is possible

tags at root level with the same key than the tags at the stage level at the same time?

if the same tag is defined at multiple levels (root, stage, "substage"), the innermost value will be used. I actually had to fix this

drodriguezhdez
drodriguezhdez previously approved these changes Dec 5, 2024
@nikita-tkachenko-datadog
nikita-tkachenko-datadog merged commit 5e6a73b into master Dec 5, 2024
@nikita-tkachenko-datadog
nikita-tkachenko-datadog deleted the nikita-tkachenko/fix-datadog-step-scope branch December 5, 2024 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/Fixed Fixed features results into a bug fix version bump documentation Documentation related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants