Skip to content

Commit

Permalink
Optimize get_artifacts_for_build() with regex filtering (#4297) (#4544)
Browse files Browse the repository at this point in the history
Introduces regex-based filtering directly in the API to improve
performance and reduce number of calls to ab api server.

Cherry pick: #4297

Co-authored-by: aditya-wazir <[email protected]>
  • Loading branch information
jonathanmetzman and aditya-wazir authored Dec 26, 2024
1 parent 5646228 commit 8786d5c
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/clusterfuzz/_internal/platforms/android/fetch_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import json
import os
import re
from typing import List
from typing import Optional

import apiclient
from oauth2client.service_account import ServiceAccountCredentials
Expand Down Expand Up @@ -119,10 +121,22 @@ def download_artifact(client, bid, target, attempt_id, name, output_directory,
return output_path


def get_artifacts_for_build(client, bid, target, attempt_id='latest'):
def get_artifacts_for_build(client,
bid: str,
target: str,
attempt_id: str = 'latest',
regexp: Optional[str] = None) -> List[str]:
"""Return list of artifacts for a given build."""
request = client.buildartifact().list(
buildId=bid, target=target, attemptId=attempt_id)
if not regexp:
request = client.buildartifact().list(
buildId=bid, target=target, attemptId=attempt_id)
else:
request = client.buildartifact().list(
buildId=bid,
target=target,
attemptId=attempt_id,
nameRegexp=regexp,
maxResults=100)

request_str = (f'{request.uri}, {request.method}, '
f'{request.body}, {request.methodId}')
Expand Down Expand Up @@ -239,7 +253,7 @@ def get(bid, target, regex, output_directory, output_filename=None):
def run_script(client, bid, target, regex, output_directory, output_filename):
"""Download artifacts as specified."""
artifacts = get_artifacts_for_build(
client=client, bid=bid, target=target, attempt_id='latest')
client=client, bid=bid, target=target, attempt_id='latest', regexp=regex)
if not artifacts:
logs.error(f'Artifact could not be fetched for target {target}, '
f'build id {bid}.')
Expand Down

0 comments on commit 8786d5c

Please sign in to comment.