Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: output JSON for VHD build benchmarks and publish as pipeline artifact #4521

Merged
merged 60 commits into from
Jul 10, 2024

Conversation

zachary-bailey
Copy link
Collaborator

What type of PR is this?

/test

What this PR does / why we need it:

This PR changes the workflow for benchmarking the VHD build process and publishes a build artifact at the conclusion of the pipeline. Changes include removing the start_watch function, adding the installJq function, and outputting benchmarking data in JSON instead of formatted strings. At the end of each script, a JSON object will be output in the terminal with performance data for each section.

The installJq function was necessary because jq is not installed until the installDeps function is called in install-dependencies.sh, but it is needed when the build process starts in pre-install-dependencies.sh.

The pipeline artifact that will be published is a JSON file that will contain benchmarking data for the build process. In later changes, github actions will be used to evaluate this artifact and check for build time regression.

The formatting of the artifact can be checked by going to the PR gate build and checking the artifacts list.

Which issue(s) this PR fixes:

This will prevent vhd build times from incrementally increasing due to code changes.

Note: When reviewing "Files changed", please collapse /pkg/agent/testdata to see all relevant file changes
Requirements:

@coveralls
Copy link

coveralls commented Jun 14, 2024

Pull Request Test Coverage Report for Build 9520897360

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 75.969%

Totals Coverage Status
Change from base Build 9520862858: 0.0%
Covered Lines: 2627
Relevant Lines: 3458

💛 - Coveralls

@coveralls
Copy link

coveralls commented Jun 14, 2024

Pull Request Test Coverage Report for Build 9520911031

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 75.969%

Totals Coverage Status
Change from base Build 9520862858: 0.0%
Covered Lines: 2627
Relevant Lines: 3458

💛 - Coveralls


local current_time=$(date +%s)
local end_timestamp=$(date +%H:%M:%S)
local difference_in_seconds=$((current_time - ${1}))
if [ "$is_final_section" = true ]; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

==, right?

}

stop_watch () {
capture_benchmarks () {
Copy link
Collaborator

@Devinwong Devinwong Jun 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function has 2 purposes, namely, capture benchmarks for a section and for the whole script.
If I were implementing it, I would separate this function into two, e.g., capture_section_benchmarks and capture_script_benchmarks (or capture_final_section_benchmarks if it's more appropriate), instead of using a bool to control the logic.
The reasons behind that are

  • Single Responsibility Principle: The idea behind the SRP is that every class, module, or function in a program should have one responsibility/purpose in a program (copied from search engine)
  • There isn't too much common logic between when $is_final_section == true vs false. So duplicate codes shouldn't be an issue here.
  • Even there were duplicate codes, I would put them into functions so that capture_section_benchmarks and capture_script_benchmarks can reuse.

Just my 2 cents :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review! I will look into refactoring the function with this in mind.

script_object=$(jq -n --arg script_name "$title" --arg script_start_timestamp "$script_start_timestamp" --arg end_timestamp "$end_timestamp" --arg total_time_elapsed "$total_time_elapsed" '{($script_name): {"overall": {"start_time": $script_start_timestamp, "end_time": $end_timestamp, "total_time_elapsed": $total_time_elapsed}}}')

#iterate over the benchmarks array in order to retrieve data from previous sections and create section objects for each
for ((i=0; i<${#benchmarks[@]}; i+=4)); do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: consider using 4 arrays to store the information, namely, section_name, section_start_timestamp, end_timestamp, total_time_elapsed if there is no obvious benefit to use a single array. Just for easier debugging consideration. (Struct is not supported in bash script, otherwise it would be even better)

echo "$output"
else
if [[ $OS == $MARINER_OS_NAME ]]; then
sudo tdnf install -y jq
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we capture the error in case it fails to install?
For example, in install_dependencies.sh it is doing something like this apt_get_install 30 1 600 grub-efi || exit 1

sudo tdnf install -y jq
echo "jq was installed: $(jq --version)"
else
apt_get_install 5 1 60 jq
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above. Capture error?

}

stop_watch () {
capture_benchmarks () {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added a shell script unit test and merged to master branch. Please git pull master branch and take a look at the section shell scripts unit tests in the readme. It will be great if you can add unit tests to your new functions. Examples are listed in the readme too.

@coveralls
Copy link

coveralls commented Jun 19, 2024

Pull Request Test Coverage Report for Build 9586871333

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 75.969%

Totals Coverage Status
Change from base Build 9586608818: 0.0%
Covered Lines: 2627
Relevant Lines: 3458

💛 - Coveralls

@zachary-bailey zachary-bailey merged commit ad9e7a2 into master Jul 10, 2024
17 of 18 checks passed
@zachary-bailey zachary-bailey deleted the zacharybailey/jsonbenchmarks branch July 10, 2024 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants