/** Exports metrics to BigQuery. */
@Override
public void run() {
try {
TableDataInsertAllResponse response = bigquery.tabledata()
.insertAll(projectId, DATASET_ID, TABLE_ID, new TableDataInsertAllRequest()
.setRows(ImmutableList.of(new TableDataInsertAllRequest.Rows()
.setInsertId(insertId)
.setJson(new ImmutableMap.Builder<String, Object>()
.put("path", path)
.put("method", method)
.put("tld", tld)
.put("start_time", startTime)
.put("end_time", endTime)
.put("response_code", responseCode)
.put("activity", activity)
.build())))).execute();
if (response.getInsertErrors() != null && !response.getInsertErrors().isEmpty()) {
throw new RuntimeException(Joiner.on('\n').join(FluentIterable
.from(response.getInsertErrors())
.transform(new Function<InsertErrors, String>() {
@Override
public String apply(InsertErrors error) {
try {
return error.toPrettyString();