From 6feb0cf9e97ef6abeb70fbe65f35513c9210a2a4 Mon Sep 17 00:00:00 2001 From: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Date: Thu, 19 Mar 2020 10:49:28 +0100 Subject: [PATCH] fix(telemetry): disable telemetry in init stage (#1272) * disable telemetry in init stage * Apply suggestions from code review * Update vars/piperStageWrapper.groovy --- vars/piperPipelineStageInit.groovy | 2 +- vars/piperStageWrapper.groovy | 49 ++++++++++++++++-------------- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/vars/piperPipelineStageInit.groovy b/vars/piperPipelineStageInit.groovy index a7010487f..c03c854d6 100644 --- a/vars/piperPipelineStageInit.groovy +++ b/vars/piperPipelineStageInit.groovy @@ -46,7 +46,7 @@ void call(Map parameters = [:]) { def stageName = parameters.stageName?:env.STAGE_NAME - piperStageWrapper (script: script, stageName: stageName, stashContent: [], ordinal: 1) { + piperStageWrapper (script: script, stageName: stageName, stashContent: [], ordinal: 1, telemetryDisabled: true) { def scmInfo = checkout scm setupCommonPipelineEnvironment script: script, customDefaults: parameters.customDefaults diff --git a/vars/piperStageWrapper.groovy b/vars/piperStageWrapper.groovy index 386975da6..09b356b44 100644 --- a/vars/piperStageWrapper.groovy +++ b/vars/piperStageWrapper.groovy @@ -37,12 +37,12 @@ void call(Map parameters = [:], body) { DebugReport.instance.environment.put("environment", "Kubernetes") withEnv(["POD_NAME=${stageName}"]) { dockerExecuteOnKubernetes(script: script, containerMap: containerMap, stageName: stageName) { - executeStage(script, body, stageName, config, utils) + executeStage(script, body, stageName, config, utils, parameters.telemetryDisabled) } } } else { node(config.nodeLabel) { - executeStage(script, body, stageName, config, utils) + executeStage(script, body, stageName, config, utils, parameters.telemetryDisabled) } } } @@ -60,7 +60,7 @@ private void stageLocking(Map config, Closure body) { } } -private void executeStage(script, originalStage, stageName, config, utils) { +private void executeStage(script, originalStage, stageName, config, utils, telemetryDisabled = false) { boolean projectExtensions boolean globalExtensions def startTime = System.currentTimeMillis() @@ -124,26 +124,29 @@ private void executeStage(script, originalStage, stageName, config, utils) { //Perform stashing of selected files in workspace utils.stashStageFiles(script, stageName) - def duration = System.currentTimeMillis() - startTime - utils.pushToSWA([ - eventType: 'library-os-stage', - stageName: stageName, - stepParamKey1: 'buildResult', - stepParam1: "${script.currentBuild.currentResult}", - buildResult: "${script.currentBuild.currentResult}", - stepParamKey2: 'stageStartTime', - stepParam2: "${startTime}", - stageStartTime: "${startTime}", - stepParamKey3: 'stageDuration', - stepParam3: "${duration}", - stageDuration: "${duration}", - stepParamKey4: 'projectExtension', - stepParam4: "${projectExtensions}", - projectExtension: "${projectExtensions}", - stepParamKey5: 'globalExtension', - stepParam5: "${globalExtensions}", - globalExtension: "${globalExtensions}" - ], config) + // In general telemetry reporting is disabled by the config settings. This flag is used to disable the reporting when the config is not yet read (e.g. init stage). + if(!telemetryDisabled){ + def duration = System.currentTimeMillis() - startTime + utils.pushToSWA([ + eventType: 'library-os-stage', + stageName: stageName, + stepParamKey1: 'buildResult', + stepParam1: "${script.currentBuild.currentResult}", + buildResult: "${script.currentBuild.currentResult}", + stepParamKey2: 'stageStartTime', + stepParam2: "${startTime}", + stageStartTime: "${startTime}", + stepParamKey3: 'stageDuration', + stepParam3: "${duration}", + stageDuration: "${duration}", + stepParamKey4: 'projectExtension', + stepParam4: "${projectExtensions}", + projectExtension: "${projectExtensions}", + stepParamKey5: 'globalExtension', + stepParam5: "${globalExtensions}", + globalExtension: "${globalExtensions}" + ], config) + } } }