def get_new_failures(dates): bq = big_query_utils.create_big_query() this_script_path = os.path.join(os.path.dirname(__file__)) sql_script = os.path.join(this_script_path, 'sql/new_failures_24h.sql') with open(sql_script) as query_file: query = query_file.read().format( calibration_begin=dates['calibration']['begin'], calibration_end=dates['calibration']['end'], reporting_begin=dates['reporting']['begin'], reporting_end=dates['reporting']['end']) logging.debug("Query:\n%s", query) query_job = big_query_utils.sync_query_job(bq, 'grpc-testing', query) page = bq.jobs().getQueryResults( pageToken=None, **query_job['jobReference']).execute(num_retries=3) rows = page.get('rows') if rows: return { row['f'][0]['v']: Row(poll_strategy=row['f'][1]['v'], job_name=row['f'][2]['v'], build_id=row['f'][3]['v'], timestamp=row['f'][4]['v']) for row in rows } else: return {}
def _upload_results_to_bq(rows): """Upload test results to a BQ table. Args: rows: A list of dictionaries containing data for each row to insert """ bq = big_query_utils.create_big_query() big_query_utils.create_partitioned_table( bq, _PROJECT_ID, _DATASET_ID, _TABLE_ID, _RESULTS_SCHEMA, _DESCRIPTION, partition_type=_PARTITION_TYPE, expiration_ms=_EXPIRATION_MS) max_retries = 3 for attempt in range(max_retries): if big_query_utils.insert_rows(bq, _PROJECT_ID, _DATASET_ID, _TABLE_ID, rows): break else: if attempt < max_retries - 1: print('Error uploading result to bigquery, will retry.') else: print( 'Error uploading result to bigquery, all attempts failed.') sys.exit(1)
def upload_interop_results_to_bq(resultset, bq_table, args): """Upload interop test results to a BQ table. Args: resultset: dictionary generated by jobset.run bq_table: string name of table to create/upload results to in BQ args: args in run_interop_tests.py, generated by argparse """ bq = big_query_utils.create_big_query() big_query_utils.create_partitioned_table( bq, _PROJECT_ID, _DATASET_ID, bq_table, _INTEROP_RESULTS_SCHEMA, _DESCRIPTION, partition_type=_PARTITION_TYPE, expiration_ms=_EXPIRATION_MS) bq_rows = [] for shortname, results in six.iteritems(resultset): for result in results: test_results = {} _get_build_metadata(test_results) test_results['elapsed_time'] = '%.2f' % result.elapsed_time test_results['result'] = result.state test_results['test_name'] = shortname test_results['suite'] = shortname.split(':')[0] test_results['client'] = shortname.split(':')[1] test_results['server'] = shortname.split(':')[2] test_results['test_case'] = shortname.split(':')[3] test_results['timestamp'] = time.strftime('%Y-%m-%d %H:%M:%S') row = big_query_utils.make_row(str(uuid.uuid4()), test_results) bq_rows.append(row) _insert_rows_with_retries(bq, bq_table, bq_rows)
def get_flaky_tests(days_lower_bound, days_upper_bound, limit=None): """ period is one of "WEEK", "DAY", etc. (see https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#date_add). """ bq = big_query_utils.create_big_query() query = """ SELECT REGEXP_REPLACE(test_name, r'/\d+', '') AS filtered_test_name, job_name, build_id, timestamp FROM [grpc-testing:jenkins_test_results.aggregate_results] WHERE timestamp > DATE_ADD(CURRENT_DATE(), {days_lower_bound}, "DAY") AND timestamp <= DATE_ADD(CURRENT_DATE(), {days_upper_bound}, "DAY") AND NOT REGEXP_MATCH(job_name, '.*portability.*') AND result != 'PASSED' AND result != 'SKIPPED' ORDER BY timestamp desc """.format(days_lower_bound=days_lower_bound, days_upper_bound=days_upper_bound) if limit: query += '\n LIMIT {}'.format(limit) query_job = big_query_utils.sync_query_job(bq, 'grpc-testing', query) page = bq.jobs().getQueryResults( pageToken=None, **query_job['jobReference']).execute(num_retries=3) testname_to_cols = {row['f'][0]['v']: (row['f'][1]['v'], row['f'][2]['v'], row['f'][3]['v']) for row in page['rows']} return testname_to_cols
def _upload_netperf_latency_csv_to_bigquery(dataset_id, table_id, result_file): with open(result_file, 'r') as f: (col1, col2, col3) = f.read().split(',') latency50 = float(col1.strip()) * 1000 latency90 = float(col2.strip()) * 1000 latency99 = float(col3.strip()) * 1000 scenario_result = { 'scenario': { 'name': 'netperf_tcp_rr' }, 'summary': { 'latency50': latency50, 'latency90': latency90, 'latency99': latency99 } } bq = big_query_utils.create_big_query() _create_results_table(bq, dataset_id, table_id) if not _insert_result( bq, dataset_id, table_id, scenario_result, flatten=False): print('Error uploading result to bigquery.') sys.exit(1)
def upload_results_to_bq(resultset, bq_table, args, platform): """Upload test results to a BQ table. Args: resultset: dictionary generated by jobset.run bq_table: string name of table to create/upload results to in BQ args: args in run_tests.py, generated by argparse platform: string name of platform tests were run on """ bq = big_query_utils.create_big_query() big_query_utils.create_partitioned_table(bq, _PROJECT_ID, _DATASET_ID, bq_table, _RESULTS_SCHEMA, _DESCRIPTION, partition_type=_PARTITION_TYPE, expiration_ms= _EXPIRATION_MS) for shortname, results in six.iteritems(resultset): for result in results: test_results = {} _get_build_metadata(test_results) test_results['compiler'] = args.compiler test_results['config'] = args.config test_results['cpu_estimated'] = result.cpu_estimated test_results['cpu_measured'] = result.cpu_measured test_results['elapsed_time'] = '%.2f' % result.elapsed_time test_results['iomgr_platform'] = args.iomgr_platform # args.language is a list, but will always have one element in the contexts # this function is used. test_results['language'] = args.language[0] test_results['platform'] = platform test_results['result'] = result.state test_results['test_name'] = shortname test_results['timestamp'] = time.strftime('%Y-%m-%d %H:%M:%S') row = big_query_utils.make_row(str(uuid.uuid4()), test_results) if not big_query_utils.insert_rows(bq, _PROJECT_ID, _DATASET_ID, bq_table, [row]): print('Error uploading result to bigquery.') sys.exit(1)
def _patch_results_table(dataset_id, table_id): bq = big_query_utils.create_big_query() with open(os.path.dirname(__file__) + '/scenario_result_schema.json', 'r') as f: table_schema = json.loads(f.read()) desc = 'Results of performance benchmarks.' return big_query_utils.patch_table(bq, _PROJECT_ID, dataset_id, table_id, table_schema)
def _upload_scenario_result_to_bigquery(dataset_id, table_id, result_file): with open(result_file, 'r') as f: scenario_result = json.loads(f.read()) bq = big_query_utils.create_big_query() _create_results_table(bq, dataset_id, table_id) if not _insert_result(bq, dataset_id, table_id, scenario_result): print 'Error uploading result to bigquery.' sys.exit(1)
def upload_result(result_list, metadata): for result in result_list: new_result = copy.deepcopy(result) new_result['metadata'] = metadata bq = big_query_utils.create_big_query() row = big_query_utils.make_row(str(uuid.uuid4()), new_result) if not big_query_utils.insert_rows(bq, _PROJECT_ID, _DATASET, _TABLE + "$" + _NOW, [row]): print 'Error when uploading result', new_result
def upload_interop_results_to_bq(resultset, bq_table, args): """Upload interop test results to a BQ table. Args: resultset: dictionary generated by jobset.run bq_table: string name of table to create/upload results to in BQ args: args in run_interop_tests.py, generated by argparse """ bq = big_query_utils.create_big_query() big_query_utils.create_partitioned_table( bq, _PROJECT_ID, _DATASET_ID, bq_table, _INTEROP_RESULTS_SCHEMA, _DESCRIPTION, partition_type=_PARTITION_TYPE, expiration_ms=_EXPIRATION_MS) for shortname, results in six.iteritems(resultset): for result in results: test_results = {} _get_build_metadata(test_results) test_results['elapsed_time'] = '%.2f' % result.elapsed_time test_results['result'] = result.state test_results['test_name'] = shortname test_results['suite'] = shortname.split(':')[0] test_results['client'] = shortname.split(':')[1] test_results['server'] = shortname.split(':')[2] test_results['test_case'] = shortname.split(':')[3] test_results['timestamp'] = time.strftime('%Y-%m-%d %H:%M:%S') row = big_query_utils.make_row(str(uuid.uuid4()), test_results) # TODO(jtattermusch): rows are inserted one by one, very inefficient max_retries = 3 for attempt in range(max_retries): if big_query_utils.insert_rows(bq, _PROJECT_ID, _DATASET_ID, bq_table, [row]): break else: if attempt < max_retries - 1: print('Error uploading result to bigquery, will retry.') else: print( 'Error uploading result to bigquery, all attempts failed.' ) sys.exit(1)
def upload_results_to_bq(resultset, bq_table, extra_fields): """Upload test results to a BQ table. Args: resultset: dictionary generated by jobset.run bq_table: string name of table to create/upload results to in BQ extra_fields: dict with extra values that will be uploaded along with the results """ bq = big_query_utils.create_big_query() big_query_utils.create_partitioned_table( bq, _PROJECT_ID, _DATASET_ID, bq_table, _RESULTS_SCHEMA, _DESCRIPTION, partition_type=_PARTITION_TYPE, expiration_ms=_EXPIRATION_MS) bq_rows = [] for shortname, results in six.iteritems(resultset): for result in results: test_results = {} _get_build_metadata(test_results) test_results['cpu_estimated'] = result.cpu_estimated test_results['cpu_measured'] = result.cpu_measured test_results['elapsed_time'] = '%.2f' % result.elapsed_time test_results['result'] = result.state test_results['return_code'] = result.returncode test_results['test_name'] = shortname test_results['timestamp'] = time.strftime('%Y-%m-%d %H:%M:%S') for field_name, field_value in six.iteritems(extra_fields): test_results[field_name] = field_value row = big_query_utils.make_row(str(uuid.uuid4()), test_results) bq_rows.append(row) _insert_rows_with_retries(bq, bq_table, bq_rows)
build_result['error'] = error_list return build_result # parse command line argp = argparse.ArgumentParser(description='Get build statistics.') argp.add_argument('-u', '--username', default='jenkins') argp.add_argument('-b', '--builds', choices=['all'] + sorted(_BUILDS.keys()), nargs='+', default=['all']) args = argp.parse_args() J = Jenkins('https://grpc-testing.appspot.com', args.username, 'apiToken') bq = big_query_utils.create_big_query() for build_name in _BUILDS.keys() if 'all' in args.builds else args.builds: print('====> Build: %s' % build_name) # Since get_last_completed_build() always fails due to malformatted string # error, we use get_build_metadata() instead. job = None try: job = J[build_name] except Exception as e: print('====> Failed to get build %s: %s.' % (build_name, str(e))) continue last_processed_build_number = _get_last_processed_buildnumber(build_name) last_complete_build_number = job.get_last_completed_buildnumber() # To avoid processing all builds for a project never looked at. In this case, # only examine 10 latest builds.
def initialize(self): self.bq = bq_utils.create_big_query()
return build_result # parse command line argp = argparse.ArgumentParser(description='Get build statistics.') argp.add_argument('-u', '--username', default='jenkins') argp.add_argument('-b', '--builds', choices=['all'] + sorted(_BUILDS.keys()), nargs='+', default=['all']) args = argp.parse_args() J = Jenkins('https://grpc-testing.appspot.com', args.username, 'apiToken') bq = big_query_utils.create_big_query() for build_name in _BUILDS.keys() if 'all' in args.builds else args.builds: print('====> Build: %s' % build_name) # Since get_last_completed_build() always fails due to malformatted string # error, we use get_build_metadata() instead. job = None try: job = J[build_name] except Exception as e: print('====> Failed to get build %s: %s.' % (build_name, str(e))) continue last_processed_build_number = _get_last_processed_buildnumber(build_name) last_complete_build_number = job.get_last_completed_buildnumber() # To avoid processing all builds for a project never looked at. In this case, # only examine 10 latest builds.