Skip to content

Commit

Permalink
Merge pull request grpc#6191 from jtattermusch/benchmark_populate_mor…
Browse files Browse the repository at this point in the history
…e_data

Populate metadata about jenkins build in benchmark results
  • Loading branch information
jtattermusch committed Apr 15, 2016
2 parents ec138dd + 4843b51 commit 8910349
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tools/run_tests/performance/bq_upload_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
# Uploads performance benchmark result file to bigquery.

import argparse
import calendar
import json
import os
import sys
import time
import uuid


Expand All @@ -60,6 +62,7 @@ def _upload_scenario_result_to_bigquery(dataset_id, table_id, result_file):

def _insert_result(bq, dataset_id, table_id, scenario_result):
_flatten_result_inplace(scenario_result)
_populate_metadata_inplace(scenario_result)
row = big_query_utils.make_row(str(uuid.uuid4()), scenario_result)
return big_query_utils.insert_rows(bq,
_PROJECT_ID,
Expand Down Expand Up @@ -90,6 +93,35 @@ def _flatten_result_inplace(scenario_result):
scenario_result['serverCores'] = json.dumps(scenario_result['serverCores'])


def _populate_metadata_inplace(scenario_result):
"""Populates metadata based on environment variables set by Jenkins."""
# NOTE: Grabbing the Jenkins environment variables will only work if the
# driver is running locally on the same machine where Jenkins has started
# the job. For our setup, this is currently the case, so just assume that.
build_number = os.getenv('BUILD_NUMBER')
build_url = os.getenv('BUILD_URL')
job_name = os.getenv('JOB_NAME')
git_commit = os.getenv('GIT_COMMIT')
# actual commit is the actual head of PR that is getting tested
git_actual_commit = os.getenv('ghprbActualCommit')

utc_timestamp = str(calendar.timegm(time.gmtime()))
metadata = {'created': utc_timestamp}

if build_number:
metadata['buildNumber'] = build_number
if build_url:
metadata['buildUrl'] = build_url
if job_name:
metadata['jobName'] = job_name
if git_commit:
metadata['gitCommit'] = git_commit
if git_actual_commit:
metadata['gitActualCommit'] = git_actual_commit

scenario_result['metadata'] = metadata


argp = argparse.ArgumentParser(description='Upload result to big query.')
argp.add_argument('--bq_result_table', required=True, default=None, type=str,
help='Bigquery "dataset.table" to upload results to.')
Expand Down

0 comments on commit 8910349

Please sign in to comment.