blob: 3ccb5ed98866f8319dd4d57d6dd7be083887ffd7 [file] [log] [blame]
emaclee5bbdfca2023-08-18 14:14:49 +01001#!/bin/bash
danielhanrahan0cb80c92024-01-25 20:06:31 +00002#
3# Copyright 2023-2024 Nordix Foundation.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18set -o errexit # Exit on most errors
19set -o nounset # Disallow expansion of unset variables
20set -o pipefail # Use last non-zero exit code in a pipeline
21#set -o xtrace # Trace logging - disabled to avoid producing gigabytes of logs
22
emaclee0c5c58d2023-09-11 11:53:43 +020023#############################################################################################################################
24################################################ F U N C T I O N S ##########################################################
25#############################################################################################################################
emaclee5bbdfca2023-08-18 14:14:49 +010026
halil.cakal869f7942024-04-24 10:02:55 +010027cps_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")
emaclee5bbdfca2023-08-18 14:14:49 +010028
halil.cakal869f7942024-04-24 10:02:55 +010029ncmp_stable_test_names=("Look up CM-handles by module-set-tag" "CpsPath Registry attributes Query")
30
31cps_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")
32
33ncmp_unstable_test_names=("Look up CM-handle by id" "Update matching subscription" "Look up CM-handle by alternate-id")
emaclee5bbdfca2023-08-18 14:14:49 +010034
emaclee4c548972023-10-12 20:19:51 +010035JENKINS_JOB_URL="https://jenkins.nordix.org/job/onap-cps-master-performance-test-java"
emaclee5bbdfca2023-08-18 14:14:49 +010036
emaclee128f17a2023-11-14 15:12:27 +010037latestBuildToRecord=""
emaclee0c5c58d2023-09-11 11:53:43 +020038consoleText=""
emaclee128f17a2023-11-14 15:12:27 +010039latestRecordedBuild=""
40timestampOfLatestRecordedBuild=""
emaclee0c5c58d2023-09-11 11:53:43 +020041
halil.cakalff389332024-04-18 16:17:10 +010042# Get latest-completed build number from the jenkins job
43# The number has not been plotted on the graphs yet
44getLastCompletedBuildNumber() {
45 curl -s "${JENKINS_JOB_URL}/lastCompletedBuild/buildNumber"
46}
47
48# Get the last build number from local workspace
49# The number has already been plotted on the graphs
50getLastRecordedBuildNumber() {
51 cd "$WORKSPACE"
52 local file_name="Delete root node.txt"
53
54 # Check if the file exists
55 if [ -f "$file_name" ]; then
56 # Get the last line from the file
57 local last_line=$(tail -n 1 "$file_name")
58 local left_side=$(echo "$last_line" | cut -d ',' -f 1)
59 echo "$left_side"
60 else
halil.cakal869f7942024-04-24 10:02:55 +010061 echo "0"
halil.cakalff389332024-04-18 16:17:10 +010062 fi
63}
64
65# Get all builds numbers
66getAllBuildNumbers() {
67 curl -s "${JENKINS_JOB_URL}/api/json?tree=allBuilds\[id\]" | jq -r '.allBuilds[].id' | sort -n
68}
69
emaclee4c548972023-10-12 20:19:51 +010070# Get the console text from specific build of the performance job
emaclee0c5c58d2023-09-11 11:53:43 +020071getConsoleText() {
danielhanrahan0cb80c92024-01-25 20:06:31 +000072 buildToRead=$1
73 consoleURL="${JENKINS_JOB_URL}/${buildToRead}/consoleText"
74 consoleText=$(curl -s "$consoleURL")
emaclee0c5c58d2023-09-11 11:53:43 +020075}
76
halil.cakalff389332024-04-18 16:17:10 +010077# Get and record the percentage (performance job result) for each test name for a build number
78getAndRecordPerformanceJobResultForBuild() {
79 buildNumber="$1"
80 getConsoleText "$buildNumber"
81 # Loop through each text name
halil.cakal869f7942024-04-24 10:02:55 +010082 for cps_stable_test_name in "${cps_stable_test_names[@]}"; do
83 getAndRecordDataResults "$consoleText" "$cps_stable_test_name" "$cps_stable_test_name.txt" "$buildNumber"
halil.cakalff389332024-04-18 16:17:10 +010084 done
halil.cakal869f7942024-04-24 10:02:55 +010085 for ncmp_stable_test_name in "${ncmp_stable_test_names[@]}"; do
86 getAndRecordDataResults "$consoleText" "$ncmp_stable_test_name" "$ncmp_stable_test_name.txt" "$buildNumber"
87 done
88 for cps_unstable_test_name in "${cps_unstable_test_names[@]}"; do
89 getAndRecordDataResults "$consoleText" "$cps_unstable_test_name" "$cps_unstable_test_name.txt" "$buildNumber"
90 done
91 for ncmp_unstable_test_name in "${ncmp_unstable_test_names[@]}"; do
92 getAndRecordDataResults "$consoleText" "$ncmp_unstable_test_name" "$ncmp_unstable_test_name.txt" "$buildNumber"
halil.cakalff389332024-04-18 16:17:10 +010093 done
94}
95
96# Calculate the percentage value for a specific test and append into test data file with build number
emaclee0c5c58d2023-09-11 11:53:43 +020097getAndRecordDataResults() {
danielhanrahan0cb80c92024-01-25 20:06:31 +000098 consoleText=$1
99 patternToMatch=$2
100 dataFile=$3
101 buildNumber=$4
102 new_data=""
103 matched_line=""
104 limit_value=""
105 took_value=""
emaclee0c5c58d2023-09-11 11:53:43 +0200106
halil.cakalff389332024-04-18 16:17:10 +0100107 # Get and calculate percentage for the graph
108 if matched_line=$(echo "$consoleText" | grep "$patternToMatch"); then
danielhanrahan0cb80c92024-01-25 20:06:31 +0000109 limit_value=$(echo "$matched_line" | grep -o -P 'limit\s*\K\d+(\.\d+)?' | tr -cd '[:digit:].')
110 took_value=$(echo "$matched_line" | grep -o -P 'took\s*\K\d+(\.\d+)?' | tr -cd '[:digit:].')
111 percentage=$(echo "scale=2; $took_value * 100.00 / $limit_value" | bc)
112 new_data="$percentage"
113 fi
emaclee128f17a2023-11-14 15:12:27 +0100114
halil.cakalff389332024-04-18 16:17:10 +0100115 # Record result into related test data file
danielhanrahan0cb80c92024-01-25 20:06:31 +0000116 touch "$dataFile"
117 lastLine=$(tail -n 1 "$dataFile")
118 newLine="$buildNumber,$new_data"
119 if [ -z "$new_data" ]; then
halil.cakalff389332024-04-18 16:17:10 +0100120 # No data found for this build probably the build failed
danielhanrahan0cb80c92024-01-25 20:06:31 +0000121 echo "$buildNumber,0" >>"$dataFile"
122 recordLatestRecordedBuild "$buildNumber"
123 elif [ "$newLine" == "$lastLine" ]; then
124 # Data already exists
125 recordLatestRecordedBuild "$buildNumber"
126 else
halil.cakalff389332024-04-18 16:17:10 +0100127 # New data added into the file
danielhanrahan0cb80c92024-01-25 20:06:31 +0000128 echo "$buildNumber,$new_data" >>"$dataFile"
129 recordLatestRecordedBuild "$buildNumber"
130 fi
emaclee128f17a2023-11-14 15:12:27 +0100131}
132
halil.cakalff389332024-04-18 16:17:10 +0100133# Save the latest recorded build number with date and time
emaclee128f17a2023-11-14 15:12:27 +0100134recordLatestRecordedBuild() {
danielhanrahan0cb80c92024-01-25 20:06:31 +0000135 latestBuildToRecord="$1"
136 timestampOfLatestRecordedBuild=$(curl -s "${JENKINS_JOB_URL}/${latestBuildToRecord}/api/json?tree=timestamp" | jq -r '.timestamp')
137 formattedTimestampOfLatestRecordedBuild=$(date -d "@$((timestampOfLatestRecordedBuild / 1000))" "+%B %e, %Y at %H:%M")
138 latestRecordedBuild=$latestBuildToRecord
emaclee0c5c58d2023-09-11 11:53:43 +0200139}
140
halil.cakalff389332024-04-18 16:17:10 +0100141# Plot the image (graph) in png format
danielhanrahan0cb80c92024-01-25 20:06:31 +0000142buildPlotImage() {
143 dataFile="$1" # Get the input file name from the function parameter
144 chartFileName="$2"
emaclee0c5c58d2023-09-11 11:53:43 +0200145
danielhanrahan0cb80c92024-01-25 20:06:31 +0000146 # Create a temporary Gnuplot script
147 cat <<EOT >gnuplot_script.gp
148set datafile separator ","
149set terminal pngcairo size 1500,600
150set output "${chartFileName}"
151set xlabel "Build"
152set ylabel "Percentage of limit %"
153set yrange [0 < * < 80 : 120 < *]
154set xtics rotate
155plot '$dataFile' using (column(0)):2:xtic(sprintf("%d", column(1))) with linespoints title "measured", \
156 100 with lines linestyle 2 title "100% limit"
emaclee0c5c58d2023-09-11 11:53:43 +0200157EOT
158
halil.cakalff389332024-04-18 16:17:10 +0100159 # Run the temporary Gnuplot script
danielhanrahan0cb80c92024-01-25 20:06:31 +0000160 gnuplot gnuplot_script.gp
emaclee0c5c58d2023-09-11 11:53:43 +0200161
halil.cakalff389332024-04-18 16:17:10 +0100162 # Remove the temporary Gnuplot script
danielhanrahan0cb80c92024-01-25 20:06:31 +0000163 rm gnuplot_script.gp
emaclee0c5c58d2023-09-11 11:53:43 +0200164}
emaclee5bbdfca2023-08-18 14:14:49 +0100165
halil.cakal869f7942024-04-24 10:02:55 +0100166# Builds category html file
167buildCategoryHtmlReport() {
168 # use indirect expansion to get all elements of the array
169 categoryName=("${!1}")
danielhanrahan0cb80c92024-01-25 20:06:31 +0000170 reportTitle="$2"
171 outputFile="$3"
172 cat <<EOT >"$outputFile"
emaclee0c5c58d2023-09-11 11:53:43 +0200173 <!DOCTYPE html>
174 <html>
175 <head>
176 <title>$reportTitle</title>
177 </head>
178 <body>
halil.cakal869f7942024-04-24 10:02:55 +0100179 <h1 style="text-align: center;">$reportTitle</h1>
180 <h4>Last updated for performance job build no. $latestRecordedBuild on $formattedTimestampOfLatestRecordedBuild</h4>
181 <table align="center">
182EOT
183# Loop through the test names to generate HTML rows
184for test_name_in_category in "${categoryName[@]}"; do
185 cat <<EOF >>"$outputFile"
186 <tr> <!-- Row for $test_name_in_category -->
187 <td align="center" style="padding: 10px;">
188 <figcaption>"$test_name_in_category"</figcaption>
189 <img src="$test_name_in_category.png" width="750" height="300">
190 </td>
191 </tr>
192EOF
193done
194# Close the HTML file
195cat <<EOT >>"$outputFile"
196 </table>
197 <p>The performance tests job runs every two (even) hours, providing performance metrics. The following graphs being updated every two (odd) hours.</p>
198 <p>Successful performance tests job build adds new data, but even if a build fails, existing data is retained.</p>
199 <p>Updates occur whenever new successful data is available.</p>
emaclee0c5c58d2023-09-11 11:53:43 +0200200 </body>
halil.cakal869f7942024-04-24 10:02:55 +0100201 </html>
emaclee0c5c58d2023-09-11 11:53:43 +0200202EOT
203}
204
emaclee0c5c58d2023-09-11 11:53:43 +0200205#############################################################################################################################
halil.cakalff389332024-04-18 16:17:10 +0100206################################################ M A I N ####################################################################
emaclee0c5c58d2023-09-11 11:53:43 +0200207#############################################################################################################################
208
danielhanrahan0cb80c92024-01-25 20:06:31 +0000209# Install dependencies
210sudo apt-get install -y bc gnuplot jq
emaclee0c5c58d2023-09-11 11:53:43 +0200211
danielhanrahan0cb80c92024-01-25 20:06:31 +0000212# Download data from CPS performance Jenkins job
213cd "$WORKSPACE"
emaclee0c5c58d2023-09-11 11:53:43 +0200214if [ -z "$(ls -A)" ]; then
danielhanrahan0cb80c92024-01-25 20:06:31 +0000215 # If workspace is empty, pull data from all previous performance job runs
halil.cakalff389332024-04-18 16:17:10 +0100216 for buildNumber in $(getAllBuildNumbers); do
217 getAndRecordPerformanceJobResultForBuild "$buildNumber"
danielhanrahan0cb80c92024-01-25 20:06:31 +0000218 done
emaclee5bbdfca2023-08-18 14:14:49 +0100219else
halil.cakalff389332024-04-18 16:17:10 +0100220 # Append new data from latest jobs run
221 lastCompletedBuildNumber=$(getLastCompletedBuildNumber)
222 lastRecordedBuildNumber=$(getLastRecordedBuildNumber)
223 # Check if last completed build number is greater than last recorded build number
224 if [ "$lastCompletedBuildNumber" -gt "$lastRecordedBuildNumber" ]; then
225 for ((i = lastRecordedBuildNumber + 1; i <= lastCompletedBuildNumber; i++)); do
226 getAndRecordPerformanceJobResultForBuild "$i"
227 done
228 else
229 echo "No new builds to process."
230 fi
emaclee0c5c58d2023-09-11 11:53:43 +0200231fi
232
halil.cakalff389332024-04-18 16:17:10 +0100233# Plot image (graphs) files in png format
halil.cakal869f7942024-04-24 10:02:55 +0100234for cps_stable_test_name in "${cps_stable_test_names[@]}"; do
235 buildPlotImage "$cps_stable_test_name.txt" "$cps_stable_test_name.png"
halil.cakalff389332024-04-18 16:17:10 +0100236done
halil.cakal869f7942024-04-24 10:02:55 +0100237for ncmp_stable_test_name in "${ncmp_stable_test_names[@]}"; do
238 buildPlotImage "$ncmp_stable_test_name.txt" "$ncmp_stable_test_name.png"
239done
240for cps_unstable_test_name in "${cps_unstable_test_names[@]}"; do
241 buildPlotImage "$cps_unstable_test_name.txt" "$cps_unstable_test_name.png"
242done
243for ncmp_unstable_test_name in "${ncmp_unstable_test_names[@]}"; do
244 buildPlotImage "$ncmp_unstable_test_name.txt" "$ncmp_unstable_test_name.png"
halil.cakalff389332024-04-18 16:17:10 +0100245done
emaclee0c5c58d2023-09-11 11:53:43 +0200246
halil.cakal869f7942024-04-24 10:02:55 +0100247# Build the category pages
248buildCategoryHtmlReport cps_stable_test_names[@] "cps stable tests performance review" "cpsStableTestsPerformanceReview.html"
249buildCategoryHtmlReport ncmp_stable_test_names[@] "ncmp stable tests performance review" "ncmpStableTestsPerformanceReview.html"
250buildCategoryHtmlReport cps_unstable_test_names[@] "cps unstable tests performance review" "cpsUnstableTestsPerformanceReview.html"
251buildCategoryHtmlReport ncmp_unstable_test_names[@] "ncmp unstable tests performance review" "ncmpUnstableTestsPerformanceReview.html"