def runTest(self): logging.debug('Posting to endpoint: {0}'.format(self._url)) payloads = test_util.generate_logging_payloads() for payload in payloads: _, response_code = test_util.post(self._url, payload) if response_code != 0: self.fail('Error encountered inside ' 'sample application!') client = google.cloud.logging.Client() log_name = payload.get('log_name') token = payload.get('token') level = payload.get('level') logging.info('log name is {0}, ' 'token is {1}, ' 'level is {2}'.format(log_name, token, level)) project_id = test_util.project_id() FILTER = 'logName = ' \ '"projects/{0}/logs/{1}" ' \ 'AND (textPayload:{2} OR jsonPayload.message:*) ' \ 'AND severity = "{3}"'.format(project_id, log_name, test_util.LOGGING_PREFIX, level) logging.info('logging filter: {0}'.format(FILTER)) self.assertTrue( self._read_log(client, token, FILTER), 'Log entry not found for posted token!')
def runTest(self): payload = test_util.generate_exception_payload() _, response_code = test_util.post(self._url, payload) self.assertEquals(response_code, 0, 'Error encountered inside sample application!') logging.info('Token {0} written to Stackdriver ' 'Error Reporting'.format(payload.get('token')))
def runTest(self): logging.debug('Posting to endpoint: {0}'.format(self._url)) payloads = test_util.generate_logging_payloads() for payload in payloads: log_name, response_code = test_util.post(self._url, payload) if response_code != 0: self.fail('Error encountered inside ' 'sample application!') logging.info('response from sample app: {0}'.format(log_name)) client = google.cloud.logging.Client() token = payload.get('token') level = payload.get('level') logging.info('log name is {0}, ' 'token is {1}, ' 'level is {2}'.format(log_name, token, level)) environment = test_util.get_environment(self._base_url) if environment == constants.GAE: project_id = test_util.project_id() FILTER = 'logName = projects/{0}/logs/{1} ' \ 'AND textPayload:"{2}"'.format(project_id, log_name, token) else: FILTER = 'resource.type="container" ' \ 'AND resource.labels.cluster_name="{0}" ' \ 'AND textPayload:"{1}"'.format(constants.CLUSTER_NAME, token) logging.info('logging filter: {0}'.format(FILTER)) self.assertTrue(self._read_log(client, token, FILTER), 'Log entry not found for posted token!')
def runTest(self): payload = test_util.generate_metrics_payload() metric_name, target = payload.get('name'), payload.get('token') client = google.cloud.monitoring.Client() try: _, response_code = test_util.post(self._url, payload, constants.METRIC_TIMEOUT) self.assertEquals(response_code, 0, 'Error encountered inside sample application!') logging.info('trying to find {0} stored in {1}...'.format( target, metric_name)) start = time.time() try: found_token = self._read_metric(metric_name, target, client) failure = None except Exception as e: found_token = False failure = e elapsed = time.time() - start logging.info( 'time elapsed checking for metric: {0}s'.format(elapsed)) self.assertTrue( found_token, 'Token not found in Stackdriver monitoring!\n' 'Last error: {0}'.format(failure)) finally: self._try_cleanup_metric(client, metric_name)
def _validate(self, context, validation_specification): """Compare the specification with the context and assert that every key present in the specification is also present in the context, and that the value associated to that key in the context match the regular expression specified in the specification. Args: context: Dictionary containing for each step the request and the response. validation_specification: Dictionary with the following fields: match: List of object containing: key: Path in the context e.g step.response.headers.property . pattern: Regular expression to be compared with the value present at the path `key` in the context. Returns: None. """ match = validation_specification.get('match', []) endpoint = validation_specification.get('endpoint') for test in match: key = test.get('key') value = self._get_value_at_path(context, key) pattern = test.get('pattern') self.assertIsNotNone( re.search(pattern, value), 'The value `{0}` for the key `{1}` ' 'do not match the pattern `{2}`'.format(value, key, pattern)) if endpoint: _, response_code = test_util.post(url=urlparse.urljoin( self._base_url, endpoint), payload=context) self.assertEqual( response_code, 0, "The validation endpoint {0}" "returned a negative response".format(endpoint))
def runTest(self): payload = test_util.generate_metrics_payload() _, response_code = test_util.post(self._url, payload, test_util.METRIC_TIMEOUT) self.assertEquals(response_code, 0, 'Error encountered inside sample application!') client = google.cloud.monitoring.Client() self.assertTrue( self._read_metric(payload.get('name'), payload.get('token'), client), 'Token not found in Stackdriver monitoring!')
def runTest(self): logging.debug('Posting to endpoint: {0}'.format(self._url)) payloads = test_util.generate_logging_payloads() for payload in payloads: _, response_code = test_util.post(self._url, payload) if response_code != 0: self.fail('Error encountered inside ' 'sample application!') client = google.cloud.logging.Client() log_name = payload.get('log_name') token = payload.get('token') level = payload.get('level') logging.info('log name is {0}, ' 'token is {1}, ' 'level is {2}'.format(log_name, token, level)) self.assertTrue(self._read_log(client, log_name, token, level), 'Log entry not found for posted token!')
def runTest(self): logging.debug('Posting to endpoint: {0}'.format(self._url)) payload = test_util.generate_logging_payload() if test_util.post(self._url, payload) != 0: return self.fail('Error encountered inside sample application!') client = google.cloud.logging.Client() log_name = payload.get('log_name') token = payload.get('token') logging.info('log name is {0}, ' 'token is {1}'.format(log_name, token)) project_id = test_util._project_id() FILTER = 'logName = projects/{0}/logs/' \ 'appengine.googleapis.com%2Fstdout'.format(project_id) self.assertTrue(self._read_log(client, log_name, token, FILTER), 'Log entry not found for posted token!')