sheetsync, cutter: Collect metrics on http calls

In particular, to google apis.
pull/133/head
Mike Lang 5 years ago
parent d63ae573b7
commit 52e6c4ad41

@ -2,7 +2,11 @@
import time
import gevent
import requests
from .requests import InstrumentedSession
# Wraps all requests in some metric collection
requests = InstrumentedSession()
class GoogleAPIClient(object):
@ -40,7 +44,7 @@ class GoogleAPIClient(object):
'client_secret': self.client_secret,
'refresh_token': self.refresh_token,
'grant_type': 'refresh_token',
})
}, metric_name='get_access_token')
resp.raise_for_status()
data = resp.json()
self._access_token = data['access_token']

@ -143,13 +143,14 @@ class Youtube(UploadBackend):
'uploadType': 'resumable',
},
json=json,
metric_name='create_video',
)
if not resp.ok:
# Don't retry, because failed calls still count against our upload quota.
# The risk of repeated failed attempts blowing through our quota is too high.
raise UploadError("Youtube create video call failed with {resp.status_code}: {resp.content}".format(resp=resp))
upload_url = resp.headers['Location']
resp = self.client.request('POST', upload_url, data=data)
resp = self.client.request('POST', upload_url, data=data, metric_name='upload_video')
if 400 <= resp.status_code < 500:
# As above, don't retry. But with 4xx's we know the upload didn't go through.
# On a 5xx, we can't be sure (the server is in an unspecified state).
@ -169,6 +170,7 @@ class Youtube(UploadBackend):
'part': 'id,status',
'id': ','.join(group),
},
metric_name='list_videos',
)
resp.raise_for_status()
for item in resp.json()['items']:

@ -23,6 +23,7 @@ class Sheets(object):
'https://sheets.googleapis.com/v4/spreadsheets/{}/values/{}'.format(
spreadsheet_id, range,
),
metric_name='get_rows',
)
resp.raise_for_status()
data = resp.json()
@ -46,6 +47,7 @@ class Sheets(object):
"range": range,
"values": [[value]],
},
metric_name='write_value',
)
resp.raise_for_status()

Loading…
Cancel
Save