Skip to content

Commit

Permalink
Submit startup time request asynchronously via task queue
Browse files Browse the repository at this point in the history
  • Loading branch information
yifanyang committed Dec 5, 2022
1 parent d816ea8 commit eefe23f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
24 changes: 20 additions & 4 deletions ci/fireci/fireci/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
import requests
import subprocess

from google.cloud import tasks_v2
from google.protobuf import duration_pb2

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


def post_report(test_report, metrics_service_url, access_token, metric_type):
def post_report(test_report, metrics_service_url, access_token, metric_type, asynchronous=False):
"""Post a report to the metrics service backend."""

endpoint = ''
Expand All @@ -39,9 +41,23 @@ def post_report(test_report, metrics_service_url, access_token, metric_type):
_logger.info(f'Request data: {data}')

request_url = f'{metrics_service_url}{endpoint}'
result = requests.post(request_url, data=data, headers=headers)

_logger.info(f'Response: {result.text}')
if not asynchronous:
result = requests.post(request_url, data=data, headers=headers)
_logger.info(f'Response: {result.text}')
else:
client = tasks_v2.CloudTasksClient()
parent = client.queue_path('firebase-sdk-health-metrics', 'us-central1', 'task-queue')
task = {
'http_request': {
'http_method': tasks_v2.HttpMethod.POST,
'url': request_url,
'body': data,
'headers': headers,
},
'dispatch_deadline': duration_pb2.Duration().FromSeconds(900)
}
response = client.create_task({'parent': parent, 'task': task})
_logger.info(f'Response: {response}')


def _construct_request_endpoint_for_github_actions(metric_type):
Expand Down
8 changes: 7 additions & 1 deletion ci/fireci/fireciplugins/macrobenchmark/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,13 @@ def ci(pull_request, repeat):
if ftl_results:
metric_service_url = 'https://api.firebase-sdk-health-metrics.com'
access_token = ci_utils.gcloud_identity_token()
uploader.post_report(startup_time_data, metric_service_url, access_token, 'startup-time')
uploader.post_report(
test_report=startup_time_data,
metrics_service_url=metric_service_url,
access_token=access_token,
metric_type='startup-time',
asynchronous=True
)

if exception:
raise exception
Expand Down
5 changes: 4 additions & 1 deletion ci/fireci/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ version = 0.1

[options]
install_requires =
protobuf==3.19
protobuf==3.19.6
click==8.1.3
google-cloud-storage==2.5.0
google-cloud-tasks==2.10.4
mypy==0.991
numpy==1.23.1
pandas==1.5.1
Expand All @@ -28,6 +29,8 @@ console_scripts =
strict_optional = False
[mypy-google.cloud]
ignore_missing_imports = True
[mypy-google.protobuf]
ignore_missing_imports = True
[mypy-matplotlib]
ignore_missing_imports = True
[mypy-matplotlib.pyplot]
Expand Down

0 comments on commit eefe23f

Please sign in to comment.