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

Reduce api queries when getting latest release tag #1219

Merged

Conversation

Sunnatillo
Copy link
Member

@Sunnatillo Sunnatillo commented Apr 17, 2023

This PR reduces get_latest_release functions queries to github api for getting latest release tags.

@metal3-io-bot metal3-io-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 17, 2023
@Sunnatillo Sunnatillo force-pushed the simplify-get-release-logic/sunnat branch from f76ae56 to b03a7af Compare April 17, 2023 20:09
@Sunnatillo
Copy link
Member Author

/test-centos-integration-release-1-3
/test-ubuntu-e2e-integration-main

@Sunnatillo Sunnatillo force-pushed the simplify-get-release-logic/sunnat branch 4 times, most recently from b685f6e to 0f7d491 Compare April 18, 2023 05:47
@Sunnatillo
Copy link
Member Author

/test-centos-integration-release-1-3
/test-ubuntu-e2e-integration-main

@Sunnatillo Sunnatillo changed the title Simplify get latest releases function Simplify get_latest_releases function Apr 18, 2023
@Sunnatillo Sunnatillo force-pushed the simplify-get-release-logic/sunnat branch from 0f7d491 to a30b0a9 Compare April 18, 2023 06:05
lib/releases.sh Outdated Show resolved Hide resolved
lib/releases.sh Outdated Show resolved Hide resolved
lib/releases.sh Show resolved Hide resolved
lib/releases.sh Outdated Show resolved Hide resolved
@Sunnatillo Sunnatillo force-pushed the simplify-get-release-logic/sunnat branch from a30b0a9 to b6a2354 Compare April 18, 2023 06:08
lib/releases.sh Outdated Show resolved Hide resolved
lib/releases.sh Outdated Show resolved Hide resolved
@Sunnatillo Sunnatillo force-pushed the simplify-get-release-logic/sunnat branch from b6a2354 to b83f687 Compare April 18, 2023 06:37
lib/releases.sh Outdated Show resolved Hide resolved
@Sunnatillo Sunnatillo force-pushed the simplify-get-release-logic/sunnat branch 2 times, most recently from 373e9c4 to ed6e9b9 Compare April 18, 2023 07:28
Copy link
Member

@mboukhalfa mboukhalfa left a comment

Choose a reason for hiding this comment

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

Here you are removing the api pagination and keep checking only the last 100 releases created! so the function will fail if the target release is not in the first 100 batch ?
if the idea is just to limit the api request number you can increase the per_page to the max (i.e 100) while keeping the pagination since the current implementation will stop requesting the other pages if the target release found.
if you can guarantee that the target release will always be in the first api page with 100 elements you should make it clear in the function name for example :
function get_latest_release_from_first_githubapi_page() {
and add error message if the release was not found stating not found in the first page !

lib/releases.sh Outdated
if [ -z "${GITHUB_TOKEN:-}" ]; then
last_page="$(curl -s -I "${1}" | grep '^link:' | sed -e 's/^link:.*page=//g' -e 's/>.*$//g')"
release_tag=$(curl -sL "${url}" | jq .[].name -r | grep -E "${release}" -m 1)
Copy link
Member

Choose a reason for hiding this comment

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

Sorry for nitpicking this much, but please put .[].name in quotes for safer handling, and add the missing ^ in front of ${release} so it matches releases from the start only as it should.

Suggested change
release_tag=$(curl -sL "${url}" | jq .[].name -r | grep -E "${release}" -m 1)
release_tag=$(curl -sL "${url}" | jq ".[].name" -r | grep -E "^${release}" -m 1)

@Sunnatillo
Copy link
Member Author

Here you are removing the api pagination and keep checking only the last 100 releases created! so the function will fail if the target release is not in the first 100 batch ? if the idea is just to limit the api request number you can increase the per_page to the max (i.e 100) while keeping the pagination since the current implementation will stop requesting the other pages if the target release found. if you can guarantee that the target release will always be in the first api page with 100 elements you should make it clear in the function name for example : function get_latest_release_from_first_githubapi_page() { and add error message if the release was not found stating not found in the first page !

CAPI only maintain two latest minor release of current api version, and latest minor release for older api version. We also follow CAPI. Considering newest releases will be always on top, I do not see necessity adding complications to function. IMHO, 100 latest release is good enough. I can add a note to function saying that it will check only latest 100 releases.

@mboukhalfa
Copy link
Member

Here you are removing the api pagination and keep checking only the last 100 releases created! so the function will fail if the target release is not in the first 100 batch ? if the idea is just to limit the api request number you can increase the per_page to the max (i.e 100) while keeping the pagination since the current implementation will stop requesting the other pages if the target release found. if you can guarantee that the target release will always be in the first api page with 100 elements you should make it clear in the function name for example : function get_latest_release_from_first_githubapi_page() { and add error message if the release was not found stating not found in the first page !

CAPI only maintain two latest minor release of current api version, and latest minor release for older api version. We also follow CAPI. Considering newest releases will be always on top, I do not see necessity adding complications to function. IMHO, 100 latest release is good enough. I can add a note to function saying that it will check only latest 100 releases.

Please note that although we no longer support v1alpha5 release we still use them (e.g in upgrade) and since there are no new patches they will keep going deep in bottom of the list as new releases are pushed on top not sure when but at some point they will get moved to the second page the proper behavior of this function is to go through the next pages if the release was not found on the first. I stand by keeping this behavior I remember when we hit this issue we increased the per_page to 100 as a workaround then we decided to implement proper api pagination use! We should not regress removing this implementation in the sake of limiting GitHub requests which we can do while keeping the same behavior.

Check this issue :
kubernetes-sigs/cluster-api#8233

and previous PRs:
#1168
workaround #1161
slack discussion : https://kubernetes.slack.com/archives/C8TSNPY4T/p1678105939902579

@Sunnatillo Sunnatillo force-pushed the simplify-get-release-logic/sunnat branch from ed6e9b9 to aca2c18 Compare May 2, 2023 11:14
@Sunnatillo Sunnatillo changed the title Simplify get_latest_releases function Reduce api queries when getting latest release tag May 2, 2023
@Sunnatillo
Copy link
Member Author

/test-centos-integration-release-1-4
/test-ubuntu-e2e-integration-main

@Sunnatillo Sunnatillo requested a review from mboukhalfa May 3, 2023 11:30
Copy link
Member

@tuminoid tuminoid left a comment

Choose a reason for hiding this comment

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

Nits.

lib/releases.sh Outdated Show resolved Hide resolved
lib/releases.sh Outdated Show resolved Hide resolved
lib/releases.sh Outdated Show resolved Hide resolved
lib/releases.sh Outdated Show resolved Hide resolved
@Sunnatillo Sunnatillo force-pushed the simplify-get-release-logic/sunnat branch from aca2c18 to aeee422 Compare May 4, 2023 10:11
@tuminoid
Copy link
Member

tuminoid commented May 4, 2023

/test-centos-integration-release-1-4
/test-ubuntu-e2e-integration-main

@tuminoid
Copy link
Member

tuminoid commented May 4, 2023

/test-ubuntu-e2e-integration-main

@tuminoid
Copy link
Member

tuminoid commented May 4, 2023

/test-ubuntu-e2e-integration-main

Come on Cleura....

@Sunnatillo
Copy link
Member Author

/test-ubuntu-e2e-integration-main

1 similar comment
@Sunnatillo
Copy link
Member Author

/test-ubuntu-e2e-integration-main

lib/releases.sh Outdated
Comment on lines 14 to 27
if [ -z "${GITHUB_TOKEN:-}" ]; then
response=$(curl -si "${url}")
else
response=$(curl -si "${url}" -H "Authorization: token ${GITHUB_TOKEN}")
fi

done
# Divide response to headers and body
response_headers=$(echo "${response}" | awk 'BEGIN {RS="\r\n\r\n"} NR==1 {print}')
response_body=$(echo "${response}" | awk 'BEGIN {RS="\r\n\r\n"} NR==2 {print}')

# get the last page of releases from headers
last_page=$(echo "${response_headers}" | grep '^link:' | sed -e 's/^link:.*page=//g' -e 's/>.*$//g')
Copy link
Member

Choose a reason for hiding this comment

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

something is printing the full response on the logs and you know how huge it is !

Copy link
Member

Choose a reason for hiding this comment

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

it has increased the logs size from around 482 KB to 73,059 KB and Jenkins is struggling show full logs 💥

Copy link
Member Author

Choose a reason for hiding this comment

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

/hold
until logs are silenced.
Thank you for noticing it.

@metal3-io-bot metal3-io-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 9, 2023
@Sunnatillo
Copy link
Member Author

/hold
until logs are silenced

@Sunnatillo Sunnatillo force-pushed the simplify-get-release-logic/sunnat branch from aeee422 to 1254f6c Compare May 11, 2023 07:10
@Sunnatillo
Copy link
Member Author

/test-centos-integration-release-1-4

@Sunnatillo
Copy link
Member Author

/test-ubuntu-e2e-integration-main

@Sunnatillo
Copy link
Member Author

Sunnatillo commented May 12, 2023

/unhold
logs are silenced

@metal3-io-bot metal3-io-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 12, 2023
@mboukhalfa
Copy link
Member

/lgtm

@metal3-io-bot metal3-io-bot added the lgtm Indicates that a PR is ready to be merged. label May 12, 2023
@metal3-io-bot metal3-io-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 22, 2023
Copy link
Member

@lentzi90 lentzi90 left a comment

Choose a reason for hiding this comment

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

/approve

@metal3-io-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: kashifest, lentzi90, tuminoid

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kashifest kashifest dismissed mboukhalfa’s stale review May 22, 2023 11:51

Mohammad has already lgtmed it

@metal3-io-bot metal3-io-bot merged commit 10d02d0 into metal3-io:main May 22, 2023
@Sunnatillo Sunnatillo deleted the simplify-get-release-logic/sunnat branch July 31, 2023 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants