Skip to content

Commit

Permalink
MESH-000 - Report release metrics to ODL (istio-ecosystem#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
aattuluri authored and GitHub Enterprise committed Aug 16, 2021
1 parent 7371461 commit 864c1c7
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ def ptNameVersion = "admiral-${UUID.randomUUID().toString().toLowerCase()}"

def jenkins_pod_label = "admiral-build"

def commitSha = ''
commitSha = ''

envMap = [:]

pipeline {

Expand All @@ -29,6 +31,8 @@ pipeline {
//from msaas generated
service_name = "admiral"
asset_id = "8287766806579881856"
heliograph_asset_id = "721719432597284573"
heliograph_application_name = "heliograph"
application_name = "admiral" // *** update the Application Name you wish to use for metrics

l1 = "services"
Expand All @@ -54,17 +58,18 @@ pipeline {
stage_timeout = 22
git_timeout = 2
pipelineStartTime = 0
//envMap = [:]
commit_id = ""
git_tag = ""
admiralTag = "placeholder"
heliographTag = "placeholder"
serviceAssetId = "8287766806579881856"
GIT_TOKEN = credentials('GIT_TOKEN')
}
stages {
stage('pre-build-setup') {
steps {
script {
pipelineStartTime = System.currentTimeMillis()
container('jnlp') {
sh '''
apt-get update
Expand Down Expand Up @@ -177,7 +182,9 @@ pipeline {
iksType = "ppd"
appName = "${l1}-${l2}-${service_name}-${region}-${iksType}"
echo "Starting deploy"
deployGitOps('qal', appName, 'ppd')
iStage(appName, 'qal') {
deployGitOps('qal', appName, 'ppd')
}
}
}
}
Expand Down Expand Up @@ -269,7 +276,7 @@ def updateEnvTag(String env) {

sh "git pull"

def heliographTag = readFile "heliograph-tag.txt"
heliographTag = readFile "heliograph-tag.txt"

echo admiralTag
echo heliographTag
Expand Down Expand Up @@ -340,7 +347,10 @@ def _prepareAndSendMetrics(metricsType, startMillis, endMillis, envName, name, s

if (metricsType == 'deployment') {
_populateEnvMap(envName, endMillis)
_postToDataLake(_getDepIdxJSON(name, envName, status, startTime, endTime), metricsType)
//report admiral deployment to ODL
_postToDataLake(_getDepIdxJSON(name, envName, status, startTime, endTime, true), metricsType)
//report heliograph deployment to ODL
_postToDataLake(_getDepIdxJSON(name, envName, status, startTime, endTime, false), metricsType)
_postToDataLake(_getStgIdxJSON("deploy $envName", status, startTime, endTime, totalTime), 'pipelinestage')
} else if (metricsType == 'pipelinestage') {
_postToDataLake(_getStgIdxJSON(name, status, startTime, endTime, totalTime), metricsType)
Expand All @@ -349,18 +359,28 @@ def _prepareAndSendMetrics(metricsType, startMillis, endMillis, envName, name, s
}
}

def _getDepIdxJSON(appName, envName, status, startTime, endTime) {
def _getDepIdxJSON(appName, envName, status, startTime, endTime, admiral) {
def final_asset_id = asset_id
def final_app_name = application_name
def final_tag = admiralTag
def final_sha = commitSha
if (!admiral) {
final_asset_id = heliograph_asset_id
final_app_name = heliograph_application_name
final_tag = heliographTag
final_sha = heliographTag
}
def metricsJson = """
{
"deployTool" : "Jenkins Pipeline",
"applicationName" : "${application_name}",
"applicationVersion" : "${git_tag}",
"commitId" : "${commit_id}",
"applicationVersion" : "${final_sha}",
"commitId" : "${final_tag}",
"deployStartTime" : "${startTime}",
"assetId" : "${asset_id}",
"assetId" : "${final_asset_id}",
"jobUrl" : "${env.BUILD_URL}",
"clusterName" : "${argocd_server}",
"namespace" : "${appName}-${envName}",
"namespace" : "${final_app_name}-${envName}",
"deployTarget": "AWS",
"package": {
"name": "ksonnet",
Expand All @@ -381,7 +401,7 @@ def _getPLIdxJSON(status, startTime, endTime, totalTime) {
"pipelineId" : "${ptNameVersion}",
"pipelineName" : "${service_name}",
"assetId" : "${asset_id}",
"commitId": "${commit_id}",
"commitId": "${commitSha}",
"pipelineTool" : "Jenkins Pipeline",
"applicationName" : "${application_name}",
"target" : "AWS",
Expand All @@ -403,7 +423,7 @@ def _getStgIdxJSON(stageName, status, startTime, endTime, totalTime) {
"pipelineTool" : "Jenkins Pipeline",
"stageType": "cd_stage",
"assetId" : "${asset_id}",
"commitId": "${commit_id}",
"commitId": "${commitSha}",
"applicationName" : "${application_name}",
"target" : "AWS",
"startTime" : "${startTime}",
Expand Down

0 comments on commit 864c1c7

Please sign in to comment.