CPS: Update the time recorded in performance plots 39/19939/3
authoremaclee <lee.anjella.macabuhay@est.tech>
Tue, 14 Nov 2023 14:12:27 +0000 (15:12 +0100)
committerLee Anjella Macabuhay <lee.anjella.macabuhay@est.tech>
Tue, 14 Nov 2023 14:24:43 +0000 (14:24 +0000)
Issue-ID: CPS-1777
Signed-off-by: emaclee <lee.anjella.macabuhay@est.tech>
Change-Id: Ie6eae4673209698e36e8cedea7e0579275f6b923

jjb/onap/cps/prepare-performance-tests-data.sh

index 1b4b61f29182cccf2b298ba6c936102dec15426c..3205eb3cbd0a765e09f23e977c9ab79490335331 100644 (file)
@@ -1,4 +1,5 @@
 #!/bin/bash
+sudo apt-get install bc
 #############################################################################################################################
 ################################################ F U N C T I O N S ##########################################################
 #############################################################################################################################
@@ -30,9 +31,11 @@ getLatestBuild() {
 }
 
 latestBuild=$(getLatestBuild)
+latestBuildToRecord=""
 consoleText=""
 lastRecordedBuild=""
-timestampOfLastRecordedBuild=""
+latestRecordedBuild=""
+timestampOfLatestRecordedBuild=""
 
 # Create and add header to the file
 createAndAddHeader() {
@@ -67,11 +70,12 @@ getAndRecordDataResults() {
     # Get and calculate data for plot
     if matched_line=$(echo "$consoleText" | grep -o -P "$patternToMatch"); then
        echo "Matched line: $matched_line"
-       limit_value=$(echo "$matched_line" | grep -o -P 'limit\s*\K\d+(,\d+)?' | tr -cd '[:digit:]')
+       limit_value=$(echo "$matched_line" | grep -o -P 'limit\s*\K\d+(\.\d+)?' | tr -cd '[:digit:].')
         echo $limit_value
-       took_value=$(echo "$matched_line" | grep -o -P 'took\s*\K\d+(,\d+)?' | tr -cd '[:digit:]')
+       took_value=$(echo "$matched_line" | grep -o -P 'took\s*\K\d+(\.\d+)?' | tr -cd '[:digit:].')
         echo $took_value
-       percentage=$(($took_value * 100 / $limit_value))
+       percentage=$(echo "scale=2; $took_value * 100.00 / $limit_value" | bc)
+
 
        echo "Limit value: $limit_value"
        echo "Took value: $took_value"
@@ -93,17 +97,25 @@ getAndRecordDataResults() {
     newLine="$buildNumber,$new_data"
     if [ -z "$new_data" ]; then
         echo "No new data"
+        lastRecordedBuild=$(echo "$lastLine" | awk -F, '{print $1}')
+        recordLatestRecordedBuild "$lastRecordedBuild"
     elif [ $newLine == $lastLine ]; then
-       echo "Data already exists"
+         echo "Data already exists"
+        recordLatestRecordedBuild "$buildNumber"
     else
         echo "$buildNumber,$new_data" >> $dataFile
         echo "New data added"
+        recordLatestRecordedBuild "$buildNumber"
     fi
-    lastRecordedBuild=$buildNumber
-    timestampOfLastRecordedBuild=$(curl -s "${JENKINS_JOB_URL}/${lastRecordedBuild}/api/json" | jq -r '.timestamp')
-       formattedTimestampOfLastBuild=$(date -d "@$((timestampOfLastRecordedBuild / 1000))" "+%B %e, %Y at %H:%M")
-    echo "last Recorded build: $lastRecordedBuild"
-    echo "date of last recorded build: $formattedTimestampOfLastBuild"
+}
+
+recordLatestRecordedBuild() {
+       latestBuildToRecord="$1"
+  timestampOfLatestRecordedBuild=$(curl -s "${JENKINS_JOB_URL}/${latestBuildToRecord}/api/json" | jq -r '.timestamp')
+       formattedTimestampOfLatestRecordedBuild=$(date -d "@$((timestampOfLatestRecordedBuild / 1000))" "+%B %e, %Y at %H:%M")
+    echo "Latest recorded build: $latestBuildToRecord"
+    echo "Date of latest recorded build: $formattedTimestampOfLatestRecordedBuild"
+    latestRecordedBuild=$latestBuildToRecord
 }
 
 buildStaticReport() {
@@ -165,7 +177,11 @@ cat <<EOT > "index.html"
 </head>
 <body>
     <h1 style="text-align: center;">$reportTitle</h1>
-    <h4>Last updated for performance job build no. $lastRecordedBuild on $formattedTimestampOfLastBuild</h4>
+    <h4>Last updated for performance job build no. $latestRecordedBuild on $formattedTimestampOfLatestRecordedBuild</h4>
+    <p>The performance tests job runs daily at 02:15 UTC, providing performance metrics. The following graphs update at 04:15 UTC.</p>
+    <p>Successful performance tests job build adds new data, but even if a build fails, existing data is retained.</p>
+    <p>Updates occur whenever new successful data is available.</p>
+
     <table align="center">
         <tr> <!-- First Row -->
             <td align="center">
@@ -205,7 +221,7 @@ buildPageReport() {
     </head>
     <body>
         <h1>$reportTitle</h1>
-        <h4>Last updated for performance job build no. $lastRecordedBuild on $formattedTimestampOfLastBuild</h4>
+        <h4>Last updated for performance job build no. $latestRecordedBuild on $formattedTimestampOfLatestRecordedBuild</h4>
         <img src="$chartFileName" alt="Graph Image">
     </body>
     </html>