Skip to content

Commit 9f6e4c7

Browse files
committed
Submit startup time request asynchronously via task queue
1 parent d816ea8 commit 9f6e4c7

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

ci/fireci/fireci/uploader.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
import requests
1919
import subprocess
2020

21+
from google.cloud import tasks_v2
22+
from google.protobuf import duration_pb2
2123

2224
_logger = logging.getLogger('fireci.uploader')
2325

2426

25-
def post_report(test_report, metrics_service_url, access_token, metric_type):
27+
def post_report(test_report, metrics_service_url, access_token, metric_type, asynchronous=False):
2628
"""Post a report to the metrics service backend."""
2729

2830
endpoint = ''
@@ -39,9 +41,25 @@ def post_report(test_report, metrics_service_url, access_token, metric_type):
3941
_logger.info(f'Request data: {data}')
4042

4143
request_url = f'{metrics_service_url}{endpoint}'
42-
result = requests.post(request_url, data=data, headers=headers)
43-
44-
_logger.info(f'Response: {result.text}')
44+
if not asynchronous:
45+
result = requests.post(request_url, data=data, headers=headers)
46+
_logger.info(f'Response: {result.text}')
47+
else:
48+
client = tasks_v2.CloudTasksClient()
49+
parent = client.queue_path('fireescape-c4819', 'us-central1', 'task-queue')
50+
duration = duration_pb2.Duration()
51+
duration.FromSeconds(1200)
52+
task = {
53+
'http_request': {
54+
'http_method': tasks_v2.HttpMethod.POST,
55+
'url': request_url,
56+
'body': data.encode(),
57+
'headers': headers,
58+
},
59+
'dispatch_deadline': duration
60+
}
61+
response = client.create_task({'parent': parent, 'task': task})
62+
_logger.info(f'Created task: {response.name}')
4563

4664

4765
def _construct_request_endpoint_for_github_actions(metric_type):

ci/fireci/fireciplugins/macrobenchmark/analyze/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import tempfile
1919

2020
from click import ClickException
21-
from google.cloud import storage
21+
from google.cloud.storage import Client
2222
from pathlib import Path
2323
from typing import List, TypedDict
2424

@@ -41,7 +41,7 @@ def collect_data_points(ftl_results_dir: List[str], local_reports_dir: Path) ->
4141

4242
def _download(ftl_results_dirs: List[str]) -> Path:
4343
ftl_results_bucket = 'fireescape-benchmark-results'
44-
gcs = storage.Client()
44+
gcs = Client()
4545

4646
temp_dir = tempfile.mkdtemp(prefix='ftl-results-')
4747
for ftl_results_dir in ftl_results_dirs:

ci/fireci/fireciplugins/macrobenchmark/commands.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,13 @@ def ci(pull_request, repeat):
163163
if ftl_results:
164164
metric_service_url = 'https://api.firebase-sdk-health-metrics.com'
165165
access_token = ci_utils.gcloud_identity_token()
166-
uploader.post_report(startup_time_data, metric_service_url, access_token, 'startup-time')
166+
uploader.post_report(
167+
test_report=startup_time_data,
168+
metrics_service_url=metric_service_url,
169+
access_token=access_token,
170+
metric_type='startup-time',
171+
asynchronous=True
172+
)
167173

168174
if exception:
169175
raise exception

ci/fireci/setup.cfg

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ version = 0.1
44

55
[options]
66
install_requires =
7-
protobuf==3.19
7+
protobuf==3.19.6
88
click==8.1.3
99
google-cloud-storage==2.5.0
10+
google-cloud-tasks==2.10.4
1011
mypy==0.991
1112
numpy==1.23.1
1213
pandas==1.5.1
@@ -26,7 +27,9 @@ console_scripts =
2627

2728
[mypy]
2829
strict_optional = False
29-
[mypy-google.cloud]
30+
[mypy-google.cloud.storage]
31+
ignore_missing_imports = True
32+
[mypy-google.protobuf]
3033
ignore_missing_imports = True
3134
[mypy-matplotlib]
3235
ignore_missing_imports = True

0 commit comments

Comments
 (0)