Skip to content

destination-bigquery: print BQ error when sync fails #8694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@

package io.airbyte.integrations.destination.bigquery.helpers;

import com.google.cloud.bigquery.BigQueryError;
import com.google.cloud.bigquery.Job;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -24,4 +29,12 @@ public static void printHeapMemoryConsumption() {
LOGGER.info("Max Memory (xmx) : mb = {}", xmx);
}

public static String getJobErrorMessage(List<BigQueryError> errors, Job job) {
if (!errors.isEmpty()) {
return String.format("Error is happened during execution for job: %s, \n For more details see Big Query Error collection: %s:", job,
errors.stream().map(BigQueryError::toString).collect(Collectors.joining(",\n ")));
}
return StringUtils.EMPTY;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

package io.airbyte.integrations.destination.bigquery.strategy;

import static io.airbyte.integrations.destination.bigquery.helpers.LoggerHelper.getJobErrorMessage;
import static io.airbyte.integrations.destination.bigquery.helpers.LoggerHelper.printHeapMemoryConsumption;

import com.fasterxml.jackson.databind.JsonNode;
import com.google.cloud.bigquery.BigQuery;
import com.google.cloud.bigquery.BigQueryException;
import com.google.cloud.bigquery.CopyJobConfiguration;
import com.google.cloud.bigquery.Field;
import com.google.cloud.bigquery.Job;
Expand Down Expand Up @@ -103,15 +105,16 @@ public void close(List<BigQueryWriteConfig> writeConfigList, boolean hasFailed,

LOGGER.info("Waiting for jobs to be finished/closed");
writeConfigList.forEach(bigQueryWriteConfig -> Exceptions.toRuntime(() -> {
if (bigQueryWriteConfig.getWriter().getJob() != null) {
Job job = bigQueryWriteConfig.getWriter().getJob();
if (job != null) {
try {
bigQueryWriteConfig.getWriter().getJob().waitFor();
job.waitFor();
} catch (final BigQueryException e) {
String errorMessage = getJobErrorMessage(e.getErrors(), job);
logErrorAndHeapParameters(bigQueryWriteConfig, job, errorMessage);
throw new RuntimeException(errorMessage, e);
} catch (final RuntimeException e) {
LOGGER.error(
String.format("Failed to process a message for job: %s, \nStreams numbers: %s, \nSyncMode: %s, \nTableName: %s, \nTmpTableName: %s",
bigQueryWriteConfig.getWriter().getJob(), catalog.getStreams().size(), bigQueryWriteConfig.getSyncMode(),
bigQueryWriteConfig.getTable(), bigQueryWriteConfig.getTmpTable()));
printHeapMemoryConsumption();
logErrorAndHeapParameters(bigQueryWriteConfig, job);
throw new RuntimeException(e);
}
}
Expand Down Expand Up @@ -221,4 +224,16 @@ protected String getCreatePartitionedTableFromSelectQuery(final Schema schema,
+ String.format(" from `%s.%s.%s`", projectId, destinationTableId.getDataset(), destinationTableId.getTable());
}

private void logErrorAndHeapParameters(BigQueryWriteConfig bigQueryWriteConfig, Job job) {
LOGGER.error(String.format("Failed to process a message for job: %s, \nStreams numbers: %s, \nSyncMode: %s, \nTableName: %s, \nTmpTableName: %s",
job, catalog.getStreams().size(), bigQueryWriteConfig.getSyncMode(),
bigQueryWriteConfig.getTable(), bigQueryWriteConfig.getTmpTable()));
printHeapMemoryConsumption();
}

private void logErrorAndHeapParameters(BigQueryWriteConfig bigQueryWriteConfig, Job job, String errorCollection) {
logErrorAndHeapParameters(bigQueryWriteConfig, job);
LOGGER.error(errorCollection);
}

}