Merge "Metal3: Add more params to container build jobs"
[infra/cicd.git] / jjb / onap / cps / prepare-performance-tests-data.sh
index 1b4b61f29182cccf2b298ba6c936102dec15426c..7be4e83c7c72631d31342faa82ff031d5c563294 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() {
@@ -125,13 +137,8 @@ buildStaticReport() {
     # Set Y-axis label
     set ylabel "Percentage of limit %"
 
-         # Get stats for min and max
-    stats '$dataFile' using 1
-         xmin = STATS_min
-         freq = 5 #frequency
-         xLabel(x) = (int((x - xmin) / freq) % 2 == 0) ? sprintf("%d", x) : ""
-
-       plot '$dataFile' using (column(0)+1):2:xtic(xLabel(column(1))) with linespoints title "limit"
+       set xtics rotate
+       plot '$dataFile' using (column(0)+1):2:xtic(sprintf("%d", column(1))) with linespoints title "limit"
 EOT
 
     # Run the Gnuplot script
@@ -165,7 +172,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 +216,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>
@@ -372,3 +383,12 @@ buildPageReport "createLargeData.png" "Creating openroadm anchors with large dat
 buildPageReport "readDataTrees.png" "Read datatrees using openroadm root"  "readOperation.html"
 buildPageReport "updateDatanodes.png" "Update 100 data nodes" "updateOperation.html"
 buildPageReport "batchDelete.png" "Batch delete 100 whole lists" "deleteOperation.html"
+
+#############################################################################################################################
+##################################################### D A T A ###############################################################
+#############################################################################################################################
+
+cat create_performance_data.txt
+cat read_performance_data.txt
+cat update_performance_data.txt
+cat delete_performance_data.txt
\ No newline at end of file