15 """Helper to upload Jenkins test results to BQ"""
17 from __future__
import print_function
26 gcp_utils_dir = os.path.abspath(
27 os.path.join(os.path.dirname(__file__),
'../../gcp/utils'))
28 sys.path.append(gcp_utils_dir)
29 import big_query_utils
31 _DATASET_ID =
'jenkins_test_results'
32 _DESCRIPTION =
'Test results from master job run on Jenkins'
34 _EXPIRATION_MS = 365 * 24 * 60 * 60 * 1000
35 _PARTITION_TYPE =
'DAY'
36 _PROJECT_ID =
'grpc-testing'
38 (
'job_name',
'STRING',
'Name of Jenkins job'),
39 (
'build_id',
'INTEGER',
'Build ID of Jenkins job'),
40 (
'build_url',
'STRING',
'URL of Jenkins job'),
41 (
'test_name',
'STRING',
'Individual test name'),
42 (
'language',
'STRING',
'Language of test'),
43 (
'platform',
'STRING',
'Platform used for test'),
44 (
'config',
'STRING',
'Config used for test'),
45 (
'compiler',
'STRING',
'Compiler used for test'),
46 (
'iomgr_platform',
'STRING',
'Iomgr used for test'),
47 (
'result',
'STRING',
'Test result: PASSED, TIMEOUT, FAILED, or SKIPPED'),
48 (
'timestamp',
'TIMESTAMP',
'Timestamp of test run'),
49 (
'elapsed_time',
'FLOAT',
'How long test took to run'),
50 (
'cpu_estimated',
'FLOAT',
'Estimated CPU usage of test'),
51 (
'cpu_measured',
'FLOAT',
'Actual CPU usage of test'),
52 (
'return_code',
'INTEGER',
'Exit code of test'),
54 _INTEROP_RESULTS_SCHEMA = [
55 (
'job_name',
'STRING',
'Name of Jenkins/Kokoro job'),
56 (
'build_id',
'INTEGER',
'Build ID of Jenkins/Kokoro job'),
57 (
'build_url',
'STRING',
'URL of Jenkins/Kokoro job'),
58 (
'test_name',
'STRING',
59 'Unique test name combining client, server, and test_name'),
61 'Test suite: cloud_to_cloud, cloud_to_prod, or cloud_to_prod_auth'),
62 (
'client',
'STRING',
'Client language'),
63 (
'server',
'STRING',
'Server host name'),
64 (
'test_case',
'STRING',
'Name of test case'),
65 (
'result',
'STRING',
'Test result: PASSED, TIMEOUT, FAILED, or SKIPPED'),
66 (
'timestamp',
'TIMESTAMP',
'Timestamp of test run'),
67 (
'elapsed_time',
'FLOAT',
'How long test took to run'),
72 """Add Kokoro build metadata to test_results based on environment
73 variables set by Kokoro.
75 build_id = os.getenv(
'KOKORO_BUILD_NUMBER')
76 build_url =
'https://source.cloud.google.com/results/invocations/%s' % os.getenv(
78 job_name = os.getenv(
'KOKORO_JOB_NAME')
81 test_results[
'build_id'] = build_id
83 test_results[
'build_url'] = build_url
85 test_results[
'job_name'] = job_name
89 """Insert rows to bq table. Retry on error."""
91 for i
in range((
len(bq_rows) // 1000) + 1):
93 for attempt
in range(max_retries):
96 bq_rows[i * 1000:(i + 1) * 1000]):
99 if attempt < max_retries - 1:
100 print(
'Error uploading result to bigquery, will retry.')
103 'Error uploading result to bigquery, all attempts failed.'
109 """Upload test results to a BQ table.
112 resultset: dictionary generated by jobset.run
113 bq_table: string name of table to create/upload results to in BQ
114 extra_fields: dict with extra values that will be uploaded along with the results
123 partition_type=_PARTITION_TYPE,
124 expiration_ms=_EXPIRATION_MS)
127 for shortname, results
in six.iteritems(resultset):
128 for result
in results:
131 test_results[
'cpu_estimated'] = result.cpu_estimated
132 test_results[
'cpu_measured'] = result.cpu_measured
133 test_results[
'elapsed_time'] =
'%.2f' % result.elapsed_time
134 test_results[
'result'] = result.state
135 test_results[
'return_code'] = result.returncode
136 test_results[
'test_name'] = shortname
137 test_results[
'timestamp'] = time.strftime(
'%Y-%m-%d %H:%M:%S')
138 for field_name, field_value
in six.iteritems(extra_fields):
139 test_results[field_name] = field_value
146 """Upload interop test results to a BQ table.
149 resultset: dictionary generated by jobset.run
150 bq_table: string name of table to create/upload results to in BQ
157 _INTEROP_RESULTS_SCHEMA,
159 partition_type=_PARTITION_TYPE,
160 expiration_ms=_EXPIRATION_MS)
163 for shortname, results
in six.iteritems(resultset):
164 for result
in results:
167 test_results[
'elapsed_time'] =
'%.2f' % result.elapsed_time
168 test_results[
'result'] = result.state
169 test_results[
'test_name'] = shortname
170 test_results[
'suite'] = shortname.split(
':')[0]
171 test_results[
'client'] = shortname.split(
':')[1]
172 test_results[
'server'] = shortname.split(
':')[2]
173 test_results[
'test_case'] = shortname.split(
':')[3]
174 test_results[
'timestamp'] = time.strftime(
'%Y-%m-%d %H:%M:%S')