| #!/bin/bash |
| # |
| # Copyright 2023-2024 Nordix Foundation. |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| # |
| |
| set -o errexit # Exit on most errors |
| set -o nounset # Disallow expansion of unset variables |
| set -o pipefail # Use last non-zero exit code in a pipeline |
| #set -o xtrace # Trace logging - disabled to avoid producing gigabytes of logs |
| |
| ############################################################################################################################# |
| ################################################ F U N C T I O N S ########################################################## |
| ############################################################################################################################# |
| |
| cps_stable_test_names=("Delete data nodes for anchor" "Delete one large node" "Batch delete 100 lists elements" "Batch delete 100 containers" "Query across anchors top element" "Delete root node" "Query across anchors ancestors" "Query across anchors leaf condition + an" "Read datatrees using openroadm root" "Read datatrees using openroadm top eleme" "Query 1 anchor leaf condition + ancestor" "Query 1 anchor top element" "Creating 33,000 books" "Replace list of 0 with 100" "Query ancestors with all descendants" "Replace 0 nodes with 100" "Writing 6400 books" "Read datatrees with all descendants" "Query 1 anchor ancestors" "Writing 400 devices" "Writing 3200 books" "Saving list of 100 devices" "Saving list of 50 devices" "Saving list of 400 devices" "Query with all descendants" "Writing 100 devices" "Writing 50 devices" "Writing 200 devices" "Read datatrees for multiple xpaths" "Saving list of 200 devices") |
| |
| ncmp_stable_test_names=("Look up CM-handles by module-set-tag" "CpsPath Registry attributes Query") |
| |
| cps_unstable_test_names=("Batch delete 100 non-existing" "Batch delete 100 whole lists" "Query with direct descendants" "Delete 100 whole lists" "Query 1 anchor non-existing data" "Read datatrees with no descendants" "Read non-existing xpaths" "Query with no descendants" "Update leaves for 100 data nodes" "Query ancestors with no descendants" "Replace 100 with new leaf values" "Query ancestors with direct descendants" "Replace list of 100 with new leaf values" "Replace list of 100 using same data" "Deleting test data" "Replace list of 100 nodes with 1" "Read datatrees using openroadm whole lis" "Replace 100 using same data" "Read datatrees with direct descendants" "Replace 100 nodes with 0" "Replace list with 50 existing and 50 new" "Delete 100 lists elements" "Replace 50 existing and 50 new" "Writing 800 books" "Delete 100 containers" "Replace list with 100 new nodes" "Replace 100 with 100 new nodes" "Writing 1600 books" "Saving list of 200 devices" "Read datatrees for multiple xpaths") |
| |
| ncmp_unstable_test_names=("Look up CM-handle by id" "Update matching subscription" "Look up CM-handle by alternate-id") |
| |
| JENKINS_JOB_URL="https://jenkins.nordix.org/job/onap-cps-master-performance-test-java" |
| |
| latestBuildToRecord="" |
| consoleText="" |
| latestRecordedBuild="" |
| timestampOfLatestRecordedBuild="" |
| |
| # Get latest-completed build number from the jenkins job |
| # The number has not been plotted on the graphs yet |
| getLastCompletedBuildNumber() { |
| curl -s "${JENKINS_JOB_URL}/lastCompletedBuild/buildNumber" |
| } |
| |
| # Get the last build number from local workspace |
| # The number has already been plotted on the graphs |
| getLastRecordedBuildNumber() { |
| cd "$WORKSPACE" |
| local file_name="Delete root node.txt" |
| |
| # Check if the file exists |
| if [ -f "$file_name" ]; then |
| # Get the last line from the file |
| local last_line=$(tail -n 1 "$file_name") |
| local left_side=$(echo "$last_line" | cut -d ',' -f 1) |
| echo "$left_side" |
| else |
| echo "0" |
| fi |
| } |
| |
| # Get all builds numbers |
| getAllBuildNumbers() { |
| curl -s "${JENKINS_JOB_URL}/api/json?tree=allBuilds\[id\]" | jq -r '.allBuilds[].id' | sort -n |
| } |
| |
| # Get the console text from specific build of the performance job |
| getConsoleText() { |
| buildToRead=$1 |
| consoleURL="${JENKINS_JOB_URL}/${buildToRead}/consoleText" |
| consoleText=$(curl -s "$consoleURL") |
| } |
| |
| # Get and record the percentage (performance job result) for each test name for a build number |
| getAndRecordPerformanceJobResultForBuild() { |
| buildNumber="$1" |
| getConsoleText "$buildNumber" |
| # Loop through each text name |
| for cps_stable_test_name in "${cps_stable_test_names[@]}"; do |
| getAndRecordDataResults "$consoleText" "$cps_stable_test_name" "$cps_stable_test_name.txt" "$buildNumber" |
| done |
| for ncmp_stable_test_name in "${ncmp_stable_test_names[@]}"; do |
| getAndRecordDataResults "$consoleText" "$ncmp_stable_test_name" "$ncmp_stable_test_name.txt" "$buildNumber" |
| done |
| for cps_unstable_test_name in "${cps_unstable_test_names[@]}"; do |
| getAndRecordDataResults "$consoleText" "$cps_unstable_test_name" "$cps_unstable_test_name.txt" "$buildNumber" |
| done |
| for ncmp_unstable_test_name in "${ncmp_unstable_test_names[@]}"; do |
| getAndRecordDataResults "$consoleText" "$ncmp_unstable_test_name" "$ncmp_unstable_test_name.txt" "$buildNumber" |
| done |
| } |
| |
| # Calculate the percentage value for a specific test and append into test data file with build number |
| getAndRecordDataResults() { |
| consoleText=$1 |
| patternToMatch=$2 |
| dataFile=$3 |
| buildNumber=$4 |
| new_data="" |
| matched_line="" |
| limit_value="" |
| took_value="" |
| |
| # Get and calculate percentage for the graph |
| if matched_line=$(echo "$consoleText" | grep "$patternToMatch"); then |
| limit_value=$(echo "$matched_line" | grep -o -P 'limit\s*\K\d+(\.\d+)?' | tr -cd '[:digit:].') |
| took_value=$(echo "$matched_line" | grep -o -P 'took\s*\K\d+(\.\d+)?' | tr -cd '[:digit:].') |
| percentage=$(echo "scale=2; $took_value * 100.00 / $limit_value" | bc) |
| new_data="$percentage" |
| fi |
| |
| # Record result into related test data file |
| touch "$dataFile" |
| lastLine=$(tail -n 1 "$dataFile") |
| newLine="$buildNumber,$new_data" |
| if [ -z "$new_data" ]; then |
| # No data found for this build probably the build failed |
| echo "$buildNumber,0" >>"$dataFile" |
| recordLatestRecordedBuild "$buildNumber" |
| elif [ "$newLine" == "$lastLine" ]; then |
| # Data already exists |
| recordLatestRecordedBuild "$buildNumber" |
| else |
| # New data added into the file |
| echo "$buildNumber,$new_data" >>"$dataFile" |
| recordLatestRecordedBuild "$buildNumber" |
| fi |
| } |
| |
| # Save the latest recorded build number with date and time |
| recordLatestRecordedBuild() { |
| latestBuildToRecord="$1" |
| timestampOfLatestRecordedBuild=$(curl -s "${JENKINS_JOB_URL}/${latestBuildToRecord}/api/json?tree=timestamp" | jq -r '.timestamp') |
| formattedTimestampOfLatestRecordedBuild=$(date -d "@$((timestampOfLatestRecordedBuild / 1000))" "+%B %e, %Y at %H:%M") |
| latestRecordedBuild=$latestBuildToRecord |
| } |
| |
| # Plot the image (graph) in png format |
| buildPlotImage() { |
| dataFile="$1" # Get the input file name from the function parameter |
| chartFileName="$2" |
| |
| # Create a temporary Gnuplot script |
| cat <<EOT >gnuplot_script.gp |
| set datafile separator "," |
| set terminal pngcairo size 1500,600 |
| set output "${chartFileName}" |
| set xlabel "Build" |
| set ylabel "Percentage of limit %" |
| set yrange [0 : 120 < *] |
| set xtics rotate |
| plot '$dataFile' using (column(0)):2:xtic(sprintf("%d", column(1))) with linespoints title "measured", \ |
| 100 with lines linestyle 2 title "100% limit" |
| EOT |
| |
| # Run the temporary Gnuplot script |
| gnuplot gnuplot_script.gp |
| |
| # Remove the temporary Gnuplot script |
| rm gnuplot_script.gp |
| } |
| |
| # Builds category html file |
| buildCategoryHtmlReport() { |
| # use indirect expansion to get all elements of the array |
| categoryName=("${!1}") |
| reportTitle="$2" |
| outputFile="$3" |
| cat <<EOT >"$outputFile" |
| <!DOCTYPE html> |
| <html> |
| <head> |
| <title>$reportTitle</title> |
| </head> |
| <body> |
| <h1 style="text-align: center;">$reportTitle</h1> |
| <h4>Last updated for performance job build no. $latestRecordedBuild on $formattedTimestampOfLatestRecordedBuild</h4> |
| <table align="center"> |
| EOT |
| # Loop through the test names to generate HTML rows |
| for test_name_in_category in "${categoryName[@]}"; do |
| cat <<EOF >>"$outputFile" |
| <tr> <!-- Row for $test_name_in_category --> |
| <td align="center" style="padding: 10px;"> |
| <figcaption>"$test_name_in_category"</figcaption> |
| <img src="$test_name_in_category.png" width="750" height="300"> |
| </td> |
| </tr> |
| EOF |
| done |
| # Close the HTML file |
| cat <<EOT >>"$outputFile" |
| </table> |
| <p>The performance tests job runs every two (even) hours, providing performance metrics. The following graphs being updated every two (odd) hours.</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> |
| </body> |
| </html> |
| EOT |
| } |
| |
| ############################################################################################################################# |
| ################################################ M A I N #################################################################### |
| ############################################################################################################################# |
| |
| # Install dependencies |
| sudo apt-get install -y bc gnuplot jq |
| |
| # Download data from CPS performance Jenkins job |
| cd "$WORKSPACE" |
| if [ -z "$(ls -A)" ]; then |
| # If workspace is empty, pull data from all previous performance job runs |
| for buildNumber in $(getAllBuildNumbers); do |
| getAndRecordPerformanceJobResultForBuild "$buildNumber" |
| done |
| else |
| # Append new data from latest jobs run |
| lastCompletedBuildNumber=$(getLastCompletedBuildNumber) |
| lastRecordedBuildNumber=$(getLastRecordedBuildNumber) |
| # Check if last completed build number is greater than last recorded build number |
| if [ "$lastCompletedBuildNumber" -gt "$lastRecordedBuildNumber" ]; then |
| for ((i = lastRecordedBuildNumber + 1; i <= lastCompletedBuildNumber; i++)); do |
| getAndRecordPerformanceJobResultForBuild "$i" |
| done |
| else |
| echo "No new builds to process." |
| fi |
| fi |
| |
| # Limit the plots to last 100 builds for each test |
| for cps_stable_test_name in "${cps_stable_test_names[@]}"; do |
| tail -n 100 "$cps_stable_test_name.txt" > file.tmp && mv file.tmp "$cps_stable_test_name.txt" |
| done |
| for ncmp_stable_test_name in "${ncmp_stable_test_names[@]}"; do |
| tail -n 100 "$ncmp_stable_test_name.txt" > file.tmp && mv file.tmp "$ncmp_stable_test_name.txt" |
| done |
| for cps_unstable_test_name in "${cps_unstable_test_names[@]}"; do |
| tail -n 100 "$cps_unstable_test_name.txt" > file.tmp && mv file.tmp "$cps_unstable_test_name.txt" |
| done |
| for ncmp_unstable_test_name in "${ncmp_unstable_test_names[@]}"; do |
| tail -n 100 "$ncmp_unstable_test_name.txt" > file.tmp && mv file.tmp "$ncmp_unstable_test_name.txt" |
| done |
| |
| # Plot image (graphs) files in png format |
| for cps_stable_test_name in "${cps_stable_test_names[@]}"; do |
| buildPlotImage "$cps_stable_test_name.txt" "$cps_stable_test_name.png" |
| done |
| for ncmp_stable_test_name in "${ncmp_stable_test_names[@]}"; do |
| buildPlotImage "$ncmp_stable_test_name.txt" "$ncmp_stable_test_name.png" |
| done |
| for cps_unstable_test_name in "${cps_unstable_test_names[@]}"; do |
| buildPlotImage "$cps_unstable_test_name.txt" "$cps_unstable_test_name.png" |
| done |
| for ncmp_unstable_test_name in "${ncmp_unstable_test_names[@]}"; do |
| buildPlotImage "$ncmp_unstable_test_name.txt" "$ncmp_unstable_test_name.png" |
| done |
| |
| # Build the category pages |
| buildCategoryHtmlReport cps_stable_test_names[@] "cps stable tests performance review" "cpsStableTestsPerformanceReview.html" |
| buildCategoryHtmlReport ncmp_stable_test_names[@] "ncmp stable tests performance review" "ncmpStableTestsPerformanceReview.html" |
| buildCategoryHtmlReport cps_unstable_test_names[@] "cps unstable tests performance review" "cpsUnstableTestsPerformanceReview.html" |
| buildCategoryHtmlReport ncmp_unstable_test_names[@] "ncmp unstable tests performance review" "ncmpUnstableTestsPerformanceReview.html" |