Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Classes representing the monitoring interface for tasks or devices.""" | 5 """Classes representing the monitoring interface for tasks or devices.""" |
| 6 | 6 |
| 7 | 7 |
| 8 import base64 | 8 import base64 |
| 9 import json | 9 import json |
| 10 import logging | 10 import logging |
| 11 import traceback | 11 import traceback |
| 12 | 12 |
| 13 from googleapiclient import discovery | 13 from googleapiclient import discovery |
| 14 from oauth2client import gce | 14 from oauth2client.contrib import gce |
|
Sergey Berezin
2016/03/07 17:41:15
I'd rather update this upstream first. For instanc
| |
| 15 from oauth2client.client import GoogleCredentials | 15 from oauth2client.client import GoogleCredentials |
| 16 from oauth2client.file import Storage | 16 from oauth2client.file import Storage |
| 17 import httplib2 | 17 import httplib2 |
| 18 | 18 |
| 19 from infra_libs import httplib2_utils | 19 from infra_libs import httplib2_utils |
| 20 from infra_libs.ts_mon.common import http_metrics | 20 from infra_libs.ts_mon.common import http_metrics |
| 21 from infra_libs.ts_mon.protos import metrics_pb2 | 21 from infra_libs.ts_mon.protos import metrics_pb2 |
| 22 | 22 |
| 23 | 23 |
| 24 # Special string that can be passed through as the credentials path to use the | 24 # Special string that can be passed through as the credentials path to use the |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 'https://www.googleapis.com/auth/pubsub', | 65 'https://www.googleapis.com/auth/pubsub', |
| 66 ] | 66 ] |
| 67 | 67 |
| 68 TIMEOUT = 10 # seconds | 68 TIMEOUT = 10 # seconds |
| 69 | 69 |
| 70 def _load_credentials(self, credentials_file_path): | 70 def _load_credentials(self, credentials_file_path): |
| 71 if credentials_file_path == GCE_CREDENTIALS: | 71 if credentials_file_path == GCE_CREDENTIALS: |
| 72 return gce.AppAssertionCredentials(self._SCOPES) | 72 return gce.AppAssertionCredentials(self._SCOPES) |
| 73 if credentials_file_path == APPENGINE_CREDENTIALS: # pragma: no cover | 73 if credentials_file_path == APPENGINE_CREDENTIALS: # pragma: no cover |
| 74 # This import doesn't work outside appengine, so delay it until it's used. | 74 # This import doesn't work outside appengine, so delay it until it's used. |
| 75 from oauth2client import appengine | 75 from oauth2client.contrib import appengine |
| 76 from google.appengine.api import app_identity | 76 from google.appengine.api import app_identity |
| 77 logging.info('Initializing with service account %s', | 77 logging.info('Initializing with service account %s', |
| 78 app_identity.get_service_account_name()) | 78 app_identity.get_service_account_name()) |
| 79 return appengine.AppAssertionCredentials(self._SCOPES) | 79 return appengine.AppAssertionCredentials(self._SCOPES) |
| 80 | 80 |
| 81 with open(credentials_file_path, 'r') as credentials_file: | 81 with open(credentials_file_path, 'r') as credentials_file: |
| 82 credentials_json = json.load(credentials_file) | 82 credentials_json = json.load(credentials_file) |
| 83 if credentials_json.get('type', None): | 83 if credentials_json.get('type', None): |
| 84 credentials = GoogleCredentials.from_stream(credentials_file_path) | 84 credentials = GoogleCredentials.from_stream(credentials_file_path) |
| 85 credentials = credentials.create_scoped(self._SCOPES) | 85 credentials = credentials.create_scoped(self._SCOPES) |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 logging.info('Flushing monitoring metrics:\n%s', text) | 171 logging.info('Flushing monitoring metrics:\n%s', text) |
| 172 if self._fh is not None: | 172 if self._fh is not None: |
| 173 self._fh.write(text + '\n\n') | 173 self._fh.write(text + '\n\n') |
| 174 self._fh.flush() | 174 self._fh.flush() |
| 175 | 175 |
| 176 | 176 |
| 177 class NullMonitor(Monitor): | 177 class NullMonitor(Monitor): |
| 178 """Class that doesn't send metrics anywhere.""" | 178 """Class that doesn't send metrics anywhere.""" |
| 179 def send(self, metric_pb): | 179 def send(self, metric_pb): |
| 180 pass | 180 pass |
| OLD | NEW |