[Android v4 API] Migrate fetch_artifact to use new V4 API#5371
Conversation
|
|
||
| def get(bid, target, regex, output_directory, output_filename=None): | ||
| """Return artifact for a given build id, target and file regex.""" | ||
| client = get_client() |
There was a problem hiding this comment.
could we add one more flag that completely disables fetch_artifact? In the chance that we run into an issue with v4 and v3 is throttled? And then add any error handling we need to the flashing and symbolization path to gracefully handle the new flag being disabled
There was a problem hiding this comment.
oooh i get it now, ill create a third PR for this
|
|
||
| def get(bid, target, regex, output_directory, output_filename=None): | ||
| """Return artifact for a given build id, target and file regex.""" | ||
| client = get_client() |
| attempt_id=attempt_id, | ||
| artifact_name=name) | ||
|
|
||
| if _use_v4(): |
There was a problem hiding this comment.
I just saw that the use_v4 logic was implemented at #5335 by using the config of source of truth for the flag. Maybe we could move it to use the structure of https://github.com/google/clusterfuzz/blob/6ff486c47af95d6fa9d86238a65cc15adf5a9393/src/clusterfuzz/_internal/base/feature_flags.py#L23 to avoid the need of PRs and deployments to apply the change.
## Overview As per requested, we created a new feature flag to disable definitely the API build use cases(used trough `fetch_artifact.py`), this feature flag is enabled by default, because that's the current API & ClusterFuzz workflow. But can be disabled by adding the feature flag to the DB and marking it as enabled=false. ## Changes - Creates new feature_flag, and enables it by default in `fetch_artifact.py` - Logs warnings when the feature flag is disabled in `fetch_artifact.py` - Safely exists the related methods in `symbols_downloader` and `flash.py` which consume the `fetch_artifact.py` - Moved up the `adb.bad_state_reach()` method from the `fetch_artifact.py` module to its callers, this way we can now handle better the None values and raised errors from the API being turned off by the feature flag. ## Tests After the initial tests in the PR parents, i tested this changes once more in dev(including all 3 prs), looking specifically for `utils.fetch_url` or errors inherent to the return value from this method. Basically since my changes landed in dev the following error groups where seen: <img width="1735" height="1240" alt="image" src="https://github.com/user-attachments/assets/0591fb5c-d728-406a-b888-4f2534b2daab" /> Discarded the errors following this logic: - 403 Errors are expected to appear as per the changes that were previously there to avoid them are no longer in dev - Some error groups only appeared on previous clusterfuzz versions - Other errors are expected(like the queue size limit or bad revision errors) - There are errors from corpus pruning & fuzzer not found, this have been seen for a while now, not related to my changes - Lastly there are some errors in a cron_job, specifically in [this file ](https://github.com/google/clusterfuzz/blob/master/src/clusterfuzz/_internal/cron/load_bigquery_stats.py)but this one doesn't make usage of `fetch_url` and nor does the method that triggered the error #### PR review 1. [**#5370** Add Android Build API V4 REST client and tests ](#5370) 2. [#5371 Migrate fetch_artifact to use new V4 API](#5371) 3. 👉 [#5373 Creates Feature Flag for Android V4 API](#5373) *(This PR)* Please only approve, I'll merge this PR's to avoid any possible merge conflict that can appear in the process :D
## Changes We previously migrated the v3 api to use v4 in [fetch_artifact.py](https://github.com/google/clusterfuzz/blob/master/src/clusterfuzz/_internal/platforms/android/fetch_artifact.py) but after testing the implementation we discovered that we can't continue the same approach of using a client created by service discovery url , if we want to continue using the android build api we needed to change our strategy and start using raw http requests. - Creates the new android v4 api class - Instantiated trough a static method that recieves service account credentials to avoid silent failures - Updates the `utils.fetch_url` to unify requests and reuse it in this new api while maintaining previous functionality For more info in the v4 api see: go/build-api-v4-clients-migration-guide & b/422775458 ## Tests - Created unit tests for this new class - Tested this class implementation using [a custom script](https://github.com/google/clusterfuzz/compare/android-build-v4-testing) ### Testing script details The [custom script](https://github.com/google/clusterfuzz/compare/android-build-v4-testing) performs various tests that imitate how clusterfuzz would use the `fetch_artifact.py` module in conjunction with our new api. The script test the following: - Correct API Version selection - Correct API instantiation by checking that the credentials in the db are valid - Queries latest artifact info(like build_id) for the given branch and target - branch and target come from a adb device (see where [we got this from](https://paste.googleplex.com/5462351594782720)) - Uses the retrieved build_id to get android builds artifact metadata - Downloads the given artifact Test steps: - Chery-pick the scripot commit into my branch - Run the script using butler: ``` pipenv run python butler.py run -c /usr/local/google/home/ibarba/projects/clusterfuzz-config/configs/chrome-staging test_fetch_artifact \ --script_args \ --branch=git_main \ --target=cf_x86_64_phone-next-userdebug ``` ## Dev verification After the initial tests ^ i tested this changes once more in dev(including all 3 prs), looking specifically for `utils.fetch_url` or errors inherent to the return value from this method. Basically since my changes landed in dev the following error groups where seen: <img width="1735" height="1240" alt="image" src="https://github.com/user-attachments/assets/0591fb5c-d728-406a-b888-4f2534b2daab" /> Discarded the errors following this logic: - 403 Errors are expected to appear as per the changes that were previously there to avoid them are no longer in dev - Some error groups only appeared on previous clusterfuzz versions - Other errors are expected(like the queue size limit or bad revision errors) - There are errors from corpus pruning & fuzzer not found, this have been seen for a while now, not related to my changes - Lastly there are some errors in a cron_job, specifically in [this file ](https://github.com/google/clusterfuzz/blob/master/src/clusterfuzz/_internal/cron/load_bigquery_stats.py)but this one doesn't make usage of `fetch_url` and nor does the method that triggered the error ## Note: ### PR review Stack 1. 👉 **#5370** Add Android Build API V4 REST client and tests *(This PR)* 2. [#5371 Migrate fetch_artifact to use new V4 API](#5371) 3. [#5373 Creates Feature Flag for Android V4 API](#5373) Please only approve, I'll merge this PR's to avoid any possible merge conflict that can appear in the process :D
Overview
Bug: b/422775458
Our previous implementation of the android builv v4 api was wrong, it failed always because the api no longer worked on discovery service url. In other PR we focused on creating the new api to interact with the v4 requirements. In this PR we focus on using this api class in the
fetch_artifact.pymodule,Changes
fetch_artifact.pyfetch_artifact.pyscript to avoid breaking anythingTests performed
feth_artifact.pyPR review
Please only approve, I'll merge this PR's to avoid any possible merge conflict that can appear in the process :D