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): 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 _read_log(self, client, log_name, token, level): project_id = test_util.project_id() FILTER = 'logName = projects/{0}/logs/' \ '{1}'.format(project_id, log_name) for entry in client.list_entries(filter_=FILTER): logging.debug(entry.payload) if token in entry.payload: logging.info('Token {0} found in ' 'Stackdriver logs!'.format(token)) return True raise Exception('Log entry not found for posted token!')
def _read_log(self, client, log_name, token, level): project_id = test_util.project_id() FILTER = 'logName = projects/{0}/logs/' \ '{1}'.format(project_id, log_name) for entry in client.list_entries(filter_=FILTER): # since the logs we're examining are for the deployed flex app, # we can safely log from the test driver without contaminating # the logs under examination. logging.debug(entry.payload) if token in entry.payload: logging.info('Token {0} found in ' 'Stackdriver logs!'.format(token)) return True raise Exception('Log entry not found for posted token!')
def _read_log(self, client, log_name, token, level): project_id = test_util.project_id() FILTER = 'logName = projects/{0}/logs/{1} ' \ 'AND (textPayload:{2} OR jsonPayload.message:*)'.format( project_id, log_name, test_util.LOGGING_PREFIX ) for entry in client.list_entries(filter_=FILTER): logging.debug(entry.payload) if (token in entry.payload or isinstance(entry.payload, dict) and token in entry.payload.get('message')): logging.info('Token {0} found in ' 'Stackdriver logs!'.format(token)) return True raise Exception('Log entry not found for posted token!')