Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

jenkins: disable send telemetry data by default #2603

Merged
merged 3 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pytest_otel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

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

unrelated but somehow the linting ran so I decided to fix this

if: success() || failure() # run this step even if previous step failed
with:
name: test-results
Expand Down
11 changes: 5 additions & 6 deletions src/test/groovy/NotifyBuildResultStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand All @@ -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))
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
39 changes: 21 additions & 18 deletions vars/notifyBuildResult.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/')
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions vars/notifyBuildResult.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Loading