From 3dc10eca2f32e0b645b8ef1084880803500999df Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Thu, 9 May 2024 10:07:34 +0200 Subject: [PATCH 1/3] jenkins: disable send telemetry data by default --- vars/notifyBuildResult.groovy | 39 +++++++++++++++++++---------------- vars/notifyBuildResult.txt | 1 + 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/vars/notifyBuildResult.groovy b/vars/notifyBuildResult.groovy index 0b1db0d90..3a58d8a94 100644 --- a/vars/notifyBuildResult.groovy +++ b/vars/notifyBuildResult.groovy @@ -45,6 +45,7 @@ import co.elastic.NotificationManager import org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper def call(Map args = [:]) { + def sendTelemetry = args.containsKey('sendTelemetry') ? args.sendTelemetry : false def notifyPRComment = args.containsKey('prComment') ? args.prComment : true def notifyCoverageComment = args.containsKey('coverageComment') ? args.coverageComment : true def notifyGoBenchmarkComment = args.containsKey('goBenchmarkComment') ? args.goBenchmarkComment : false @@ -115,24 +116,26 @@ def call(Map args = [:]) { createGitHubIssue(data: data, when: notifyGHIssue) } - catchError(message: 'There were some failures when sending data to elasticsearch', buildResult: 'SUCCESS', stageResult: 'UNSTABLE') { - timeout(5) { - // New indexes - def bulkFile = 'ci-test-report-bulk.json' - if (fileExists(bulkFile)) { - datafile = readFile(file: bulkFile) - sendDataToElasticsearch(es: es, secret: secret, data: datafile, restCall: '/ci-tests/_bulk/') - } - datafile = 'ci-build-report.json' - if (fileExists(datafile)) { - sendDataToElasticsearch(es: es, secret: secret, restCall: '/ci-builds/_doc/', data: readFile(file: datafile)) - } - - // NOTE: Support temporarily the email notifications with the test summary - // See https://github.com/elastic/apm-pipeline-library/pull/1514 as a potential replacement - if (env.REPO_NAME == 'integrations') { - datafile = readFile(file: 'custom-build-report.json') - sendDataToElasticsearch(es: es, secret: secret, data: datafile, restCall: '/ci-integrations-builds/_doc/') + if (sendTelemetry) { + catchError(message: 'There were some failures when sending data to elasticsearch', buildResult: 'SUCCESS', stageResult: 'UNSTABLE') { + timeout(5) { + // New indexes + def bulkFile = 'ci-test-report-bulk.json' + if (fileExists(bulkFile)) { + datafile = readFile(file: bulkFile) + sendDataToElasticsearch(es: es, secret: secret, data: datafile, restCall: '/ci-tests/_bulk/') + } + datafile = 'ci-build-report.json' + if (fileExists(datafile)) { + sendDataToElasticsearch(es: es, secret: secret, restCall: '/ci-builds/_doc/', data: readFile(file: datafile)) + } + + // NOTE: Support temporarily the email notifications with the test summary + // See https://github.com/elastic/apm-pipeline-library/pull/1514 as a potential replacement + if (env.REPO_NAME == 'integrations') { + datafile = readFile(file: 'custom-build-report.json') + sendDataToElasticsearch(es: es, secret: secret, data: datafile, restCall: '/ci-integrations-builds/_doc/') + } } } } diff --git a/vars/notifyBuildResult.txt b/vars/notifyBuildResult.txt index 1a8e500a3..e7e736dcf 100644 --- a/vars/notifyBuildResult.txt +++ b/vars/notifyBuildResult.txt @@ -45,3 +45,4 @@ emails on Failed builds that are not pull request. * githubAssignees: What GitHub assignees to be added in the GitHub issue. Default value uses ``. * githubLabels: What GitHub labels to be added in the GitHub issue in addition to `automation,ci-reported`. Optional * githubTitle: What GitHub title to be added in the GitHub issue. Default: `Build ${env.BUILD_NUMBER} for ${env.BRANCH_NAME} with status '${buildStatus}'`. +* sendTelemetry: Whether to ingest the CI data to Elasticsearch. Default value `false` From 907861968a12470a5a44b7cb64de164b4e2057c1 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Thu, 9 May 2024 10:14:52 +0200 Subject: [PATCH 2/3] fix UTs --- src/test/groovy/NotifyBuildResultStepTests.groovy | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/test/groovy/NotifyBuildResultStepTests.groovy b/src/test/groovy/NotifyBuildResultStepTests.groovy index 6290ca48a..69b87468a 100644 --- a/src/test/groovy/NotifyBuildResultStepTests.groovy +++ b/src/test/groovy/NotifyBuildResultStepTests.groovy @@ -64,7 +64,7 @@ class NotifyBuildResultStepTests extends ApmBasePipelineTest { @Test void testPullRequest() throws Exception { env.CHANGE_ID = "123" - script.call(es: EXAMPLE_URL, secret: VaultSecret.SECRET_NAME.toString()) + script.call(es: EXAMPLE_URL, secret: VaultSecret.SECRET_NAME.toString(), sendTelemetry: true) printCallStack() assertTrue(assertMethodCallOccurrences('getBuildInfoJsonFiles', 1)) assertTrue(assertMethodCallOccurrences('sendDataToElasticsearch', 2)) @@ -85,7 +85,7 @@ class NotifyBuildResultStepTests extends ApmBasePipelineTest { binding.getVariable('currentBuild').result = "SUCCESS" binding.getVariable('currentBuild').currentResult = "SUCCESS" - script.call(es: EXAMPLE_URL, secret: VaultSecret.SECRET_NAME.toString()) + script.call(es: EXAMPLE_URL, secret: VaultSecret.SECRET_NAME.toString(), sendTelemetry: true) printCallStack() assertTrue(assertMethodCallOccurrences('getBuildInfoJsonFiles', 1)) assertTrue(assertMethodCallOccurrences('sendDataToElasticsearch', 2)) @@ -98,13 +98,12 @@ class NotifyBuildResultStepTests extends ApmBasePipelineTest { script.call() printCallStack() assertTrue(assertMethodCallOccurrences('getBuildInfoJsonFiles', 1)) - assertTrue(assertMethodCallOccurrences('sendDataToElasticsearch', 2)) assertFalse(assertMethodCallContainsPattern('log', 'notifyBuildResult: Notifying results by email.')) } @Test void testWithoutSecret() throws Exception { - script.call(es: EXAMPLE_URL) + script.call(es: EXAMPLE_URL, sendTelemetry: true) printCallStack() assertTrue(assertMethodCallOccurrences('getBuildInfoJsonFiles', 1)) assertTrue(assertMethodCallOccurrences('sendDataToElasticsearch', 2)) @@ -121,7 +120,7 @@ class NotifyBuildResultStepTests extends ApmBasePipelineTest { binding.getVariable('currentBuild').result = "SUCCESS" binding.getVariable('currentBuild').currentResult = "SUCCESS" - script.call(es: EXAMPLE_URL, secret: VaultSecret.SECRET_NAME.toString()) + script.call(es: EXAMPLE_URL, secret: VaultSecret.SECRET_NAME.toString(), sendTelemetry: true) printCallStack() // Then senddata to ElasticSearch happens @@ -336,7 +335,7 @@ class NotifyBuildResultStepTests extends ApmBasePipelineTest { // When PR and there is a builk file helper.registerAllowedMethod('isPR', { return true }) - script.call(es: EXAMPLE_URL, secret: VaultSecret.SECRET_NAME.toString()) + script.call(es: EXAMPLE_URL, secret: VaultSecret.SECRET_NAME.toString(), sendTelemetry: true) printCallStack() // Then sendDataToElasticsearch happens three times From c130c41a47c6440ffc016c83c449791938d56ff8 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Thu, 9 May 2024 10:15:42 +0200 Subject: [PATCH 3/3] fix lint --- .github/workflows/pytest_otel.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pytest_otel.yml b/.github/workflows/pytest_otel.yml index bb0ff8373..cf56c81e3 100644 --- a/.github/workflows/pytest_otel.yml +++ b/.github/workflows/pytest_otel.yml @@ -36,7 +36,7 @@ jobs: run: make -C resources/scripts/pytest_otel test - name: it-test run: make -C resources/scripts/pytest_otel it-test - - uses: actions/upload-artifact@v2 # upload test results + - uses: actions/upload-artifact@v4 # upload test results if: success() || failure() # run this step even if previous step failed with: name: test-results