-
Notifications
You must be signed in to change notification settings - Fork 129
feat(bigquery): Add custom ExceptionHandler to BigQueryOptions #3937
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
Changes from 4 commits
84a10b7
669e643
a57704d
1353913
2b0152f
12f463b
2918cb4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,8 @@ | |
| package com.google.cloud.bigquery; | ||
|
|
||
| import com.google.api.core.BetaApi; | ||
| import com.google.cloud.BaseService; | ||
| import com.google.cloud.ExceptionHandler; | ||
| import com.google.cloud.ServiceDefaults; | ||
| import com.google.cloud.ServiceOptions; | ||
| import com.google.cloud.ServiceRpc; | ||
|
|
@@ -43,6 +45,7 @@ public class BigQueryOptions extends ServiceOptions<BigQuery, BigQueryOptions> { | |
| private JobCreationMode defaultJobCreationMode = JobCreationMode.JOB_CREATION_MODE_UNSPECIFIED; | ||
| private boolean enableOpenTelemetryTracing; | ||
| private Tracer openTelemetryTracer; | ||
| private ExceptionHandler exceptionHandler; | ||
|
|
||
| public static class DefaultBigQueryFactory implements BigQueryFactory { | ||
|
|
||
|
|
@@ -70,11 +73,14 @@ public static class Builder extends ServiceOptions.Builder<BigQuery, BigQueryOpt | |
| private boolean useInt64Timestamps; | ||
| private boolean enableOpenTelemetryTracing; | ||
| private Tracer openTelemetryTracer; | ||
| private boolean customExceptionHandler; | ||
| private ExceptionHandler.Builder exceptionHandlerBuilder; | ||
|
|
||
| private Builder() {} | ||
|
|
||
| private Builder(BigQueryOptions options) { | ||
| super(options); | ||
| customExceptionHandler = false; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -118,6 +124,24 @@ public Builder setOpenTelemetryTracer(Tracer tracer) { | |
| return this; | ||
| } | ||
|
|
||
| public Builder abortOn(Class<? extends Exception> exception) { | ||
|
||
| if (!customExceptionHandler) { | ||
| exceptionHandlerBuilder = ExceptionHandler.newBuilder(); | ||
| customExceptionHandler = true; | ||
| } | ||
| this.exceptionHandlerBuilder.abortOn(exception); | ||
| return this; | ||
| } | ||
|
|
||
| public Builder retryOn(Class<? extends Exception> exception) { | ||
| if (!customExceptionHandler) { | ||
| exceptionHandlerBuilder = ExceptionHandler.newBuilder(); | ||
| customExceptionHandler = true; | ||
| } | ||
| this.exceptionHandlerBuilder.retryOn(exception); | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public BigQueryOptions build() { | ||
| return new BigQueryOptions(this); | ||
|
|
@@ -130,6 +154,15 @@ private BigQueryOptions(Builder builder) { | |
| this.useInt64Timestamps = builder.useInt64Timestamps; | ||
| this.enableOpenTelemetryTracing = builder.enableOpenTelemetryTracing; | ||
| this.openTelemetryTracer = builder.openTelemetryTracer; | ||
| if (builder.customExceptionHandler) { | ||
| this.exceptionHandler = | ||
| builder | ||
| .exceptionHandlerBuilder | ||
| .addInterceptors(BaseService.EXCEPTION_HANDLER_INTERCEPTOR) | ||
| .build(); | ||
| } else { | ||
| this.exceptionHandler = BigQueryBaseService.DEFAULT_BIGQUERY_EXCEPTION_HANDLER; | ||
| } | ||
| } | ||
|
|
||
| private static class BigQueryDefaults implements ServiceDefaults<BigQuery, BigQueryOptions> { | ||
|
|
@@ -221,6 +254,10 @@ public Tracer getOpenTelemetryTracer() { | |
| return openTelemetryTracer; | ||
| } | ||
|
|
||
| public ExceptionHandler getExceptionHandler() { | ||
| return exceptionHandler; | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| @Override | ||
| public Builder toBuilder() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
customExceptionHandler is no longer needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, good catch thanks! Removed customExceptionHandler from bq options.