Skip to content

Commit f3ab68a

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

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

ci/fireci/fireci/uploader.py

Lines changed: 20 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,23 @@ 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('firebase-sdk-health-metrics', 'us-central1', 'task-queue')
50+
task = {
51+
'http_request': {
52+
'http_method': tasks_v2.HttpMethod.POST,
53+
'url': request_url,
54+
'body': data,
55+
'headers': headers,
56+
},
57+
'dispatch_deadline': duration_pb2.Duration().FromSeconds(900)
58+
}
59+
response = client.create_task({'parent': parent, 'task': task})
60+
_logger.info(f'Response: {response}')
4561

4662

4763
def _construct_request_endpoint_for_github_actions(metric_type):

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: 2 additions & 1 deletion
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

0 commit comments

Comments
 (0)