c305cdd9fa872f7d16e48b6aee48e8b7643ed396
[infra/cicd.git] / jjb / onap / cps / prepare-performance-tests-data.sh
1 #!/bin/bash
2 cd $WORKSPACE
3
4 data_file="results.txt"
5 data_file_headers="Creating openroadm anchors with large data,Read datatrees using openroadm root,Update 100 data nodes,Batch delete 100 whole lists"
6
7 if [[ ! -f "$data_file" ]]; then
8     echo "Creating $data_file"
9     touch "$data_file"
10     echo "$data_file_headers" > $data_file
11 else
12     echo "$data_file already exists"
13 fi
14
15 echo "-----------------------------------------------------------------------------------"
16 echo "-----------------------------------------------------------------------------------"
17 # Extracting data results from performance job
18 JENKINS_JOB_URL="https://jenkins.nordix.org/job/onap-cps-master-performance-test-java"
19 latest_build=$(curl -s "${JENKINS_JOB_URL}/lastBuild/api/json" | jq -r '.number')
20 echo "latest build is $latest_build"
21
22 # Get the latest build status
23 latest_build_status=$(curl -s "${JENKINS_JOB_URL}/api/json" | jq -r '.color')
24 echo "latest build status is $latest_build_status"
25
26 # Construct the URL for getting the console text
27 CONSOLE_URL="${JENKINS_JOB_URL}/${latest_build}/consoleText"
28
29 # Get the console text
30 console_text=$(curl -s "$CONSOLE_URL")
31
32 echo "-----------------------------------------------------------------------------------"
33 echo "-----------------------------------------------------------------------------------"
34
35 # Text patterns to match in console log
36 creating_bookstore_pattern="^.*Creating openroadm anchors with large.*"
37 read_datatreees_pattern="^.*Read datatrees using openroadm root.*"
38 update_datanodes_pattern="^.*Update 100 data nodes.*"
39 batch_delete_pattern="^.*Batch delete 100 whole lists.*"
40
41 all_patterns=("$creating_bookstore_pattern" "$read_datatreees_pattern" "$update_datanodes_pattern" "$batch_delete_pattern")
42 new_data=""
43
44 # Extract numerical values as data results
45 for pattern in "${all_patterns[@]}"; do
46         if matched_line=$(echo "$console_text" | grep -o -P "$pattern"); then
47         echo "Matched line: $matched_line"
48         limit_value=$(echo "$matched_line" | grep -o -P 'limit\s*\K\d+(,\d+)?' | tr -cd '[:digit:]')
49         took_value=$(echo "$matched_line" | grep -o -P 'took\s*\K\d+(,\d+)?' | tr -cd '[:digit:]')
50         percentage=$((took_value * 100 / limit_value))
51
52         echo "Limit value: $limit_value"
53         echo "Took value: $took_value"
54         echo "Percentage: $percentage"
55
56     if [ -z "$new_data" ]; then
57         new_data="$percentage"
58         else
59         new_data+=",$percentage"
60         fi
61         echo "New data: $new_data"
62
63         else
64         echo "No match found."
65         fi
66 done
67 echo "-----------------------------------------------------------------------------------"
68 echo "-----------------------------------------------------------------------------------"
69
70
71 # Publish results in file for building plot
72 if [ -z "$new_data" ]; then
73     echo "No new data"
74 else
75     echo "$new_data" >> $data_file
76 fi