-
Notifications
You must be signed in to change notification settings - Fork 4.8k
HIVE-29563: Iceberg REST Catalog's error logs are too verbose #6425
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
base: master
Are you sure you want to change the base?
Changes from all commits
1daa058
9f0c70d
7039752
6f7886d
1526ec3
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 |
|---|---|---|
|
|
@@ -21,12 +21,13 @@ | |
|
|
||
| import com.google.common.base.Preconditions; | ||
|
|
||
| import java.io.Closeable; | ||
| import java.io.IOException; | ||
| import java.time.Clock; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.function.Consumer; | ||
| import javax.servlet.http.HttpServletResponse; | ||
| import org.apache.iceberg.BaseTable; | ||
| import org.apache.iceberg.BaseTransaction; | ||
| import org.apache.iceberg.Table; | ||
|
|
@@ -48,7 +49,6 @@ | |
| import org.apache.iceberg.exceptions.NoSuchTableException; | ||
| import org.apache.iceberg.exceptions.NoSuchViewException; | ||
| import org.apache.iceberg.exceptions.NotAuthorizedException; | ||
| import org.apache.iceberg.exceptions.RESTException; | ||
| import org.apache.iceberg.exceptions.UnprocessableEntityException; | ||
| import org.apache.iceberg.exceptions.ValidationException; | ||
| import org.apache.iceberg.relocated.com.google.common.base.Splitter; | ||
|
|
@@ -83,7 +83,7 @@ | |
| * Original @ <a href="https://github.com/apache/iceberg/blob/apache-iceberg-1.9.1/core/src/test/java/org/apache/iceberg/rest/RESTCatalogAdapter.java">RESTCatalogAdapter.java</a> | ||
| * Adaptor class to translate REST requests into {@link Catalog} API calls. | ||
| */ | ||
| public class HMSCatalogAdapter implements RESTClient { | ||
| public class HMSCatalogAdapter implements Closeable { | ||
| private static final Logger LOG = LoggerFactory.getLogger(HMSCatalogAdapter.class); | ||
| private static final Splitter SLASH = Splitter.on('/'); | ||
|
|
||
|
|
@@ -506,7 +506,7 @@ <T extends RESTResponse> T execute( | |
| String path, | ||
| Map<String, String> queryParams, | ||
| Object body, | ||
| Consumer<ErrorResponse> errorHandler) { | ||
| HttpServletResponse response) throws IOException { | ||
| ErrorResponse.Builder errorBuilder = ErrorResponse.builder(); | ||
| Pair<Route, Map<String, String>> routeAndVars = Route.from(method, path); | ||
| if (routeAndVars != null) { | ||
|
|
@@ -527,63 +527,9 @@ <T extends RESTResponse> T execute( | |
| .withMessage(String.format("No route for request: %s %s", method, path)); | ||
| } | ||
| ErrorResponse error = errorBuilder.build(); | ||
| errorHandler.accept(error); | ||
| // if the error handler doesn't throw an exception, throw a generic one | ||
| throw new RESTException("Unhandled error: %s", error); | ||
| } | ||
|
|
||
| @Override | ||
| public <T extends RESTResponse> T delete( | ||
| String path, | ||
| Class<T> responseType, | ||
| Map<String, String> headers, | ||
| Consumer<ErrorResponse> errorHandler) { | ||
| return execute(HTTPMethod.DELETE, path, null, null, errorHandler); | ||
| } | ||
|
|
||
| @Override | ||
| public <T extends RESTResponse> T delete( | ||
| String path, | ||
| Map<String, String> queryParams, | ||
| Class<T> responseType, | ||
| Map<String, String> headers, | ||
| Consumer<ErrorResponse> errorHandler) { | ||
| return execute(HTTPMethod.DELETE, path, queryParams, null, errorHandler); | ||
| } | ||
|
|
||
| @Override | ||
| public <T extends RESTResponse> T post( | ||
| String path, | ||
| RESTRequest body, | ||
| Class<T> responseType, | ||
| Map<String, String> headers, | ||
| Consumer<ErrorResponse> errorHandler) { | ||
| return execute(HTTPMethod.POST, path, null, body, errorHandler); | ||
| } | ||
|
|
||
| @Override | ||
| public <T extends RESTResponse> T get( | ||
| String path, | ||
| Map<String, String> queryParams, | ||
| Class<T> responseType, | ||
| Map<String, String> headers, | ||
| Consumer<ErrorResponse> errorHandler) { | ||
| return execute(HTTPMethod.GET, path, queryParams, null, errorHandler); | ||
| } | ||
|
|
||
| @Override | ||
| public void head(String path, Map<String, String> headers, Consumer<ErrorResponse> errorHandler) { | ||
| execute(HTTPMethod.HEAD, path, null, headers, errorHandler); | ||
| } | ||
|
|
||
| @Override | ||
| public <T extends RESTResponse> T postForm( | ||
| String path, | ||
| Map<String, String> formData, | ||
| Class<T> responseType, | ||
| Map<String, String> headers, | ||
| Consumer<ErrorResponse> errorHandler) { | ||
| return execute(HTTPMethod.POST, path, null, formData, errorHandler); | ||
| response.setStatus(error.code()); | ||
| RESTObjectMapper.mapper().writeValue(response.getWriter(), error); | ||
| return null; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -627,11 +573,15 @@ public static <T extends RESTResponse> T castResponse(Class<T> responseType, Obj | |
|
|
||
| public static void configureResponseFromException( | ||
| Exception exc, ErrorResponse.Builder errorBuilder) { | ||
| errorBuilder | ||
| .responseCode(EXCEPTION_ERROR_CODES.getOrDefault(exc.getClass(), 500)) | ||
| .withType(exc.getClass().getSimpleName()) | ||
| .withMessage(exc.getMessage()) | ||
| .withStackTrace(exc); | ||
| var errorCode = EXCEPTION_ERROR_CODES.getOrDefault(exc.getClass(), 500); | ||
| errorBuilder.responseCode(errorCode).withType(exc.getClass().getSimpleName()).withMessage(exc.getMessage()); | ||
| // avoid exposing stack traces for client errors but include them for server errors to aid debugging | ||
| if (errorCode >= 500) { | ||
| LOG.error("A server error happened while processing REST request", exc); | ||
| errorBuilder.withStackTrace(exc); | ||
| } else { | ||
| LOG.info("A client error happened while processing REST request: {}", exc.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| private static Namespace namespaceFromPathVars(Map<String, String> pathVars) { | ||
|
|
||
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.
May be also reduce exception verbosity:
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.
Is this aligned with you?
7039752
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.
Yes :-)