[PLUGIN-1826] Error Management HTTP Source and Sink and fix sonar issues#180
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
4cad117 to
fac0c1a
Compare
e612cd0 to
d273336
Compare
0af6ccc to
a41b2f6
Compare
4f1d5f5 to
2e321fa
Compare
itsankit-google
left a comment
There was a problem hiding this comment.
please fix unit tests
| errorMessage, String.format("Error message: %s", errorMessage), | ||
| ErrorUtils.getActionErrorByStatusCode(httpStatusCode).getErrorType(), | ||
| true, ErrorCodeType.HTTP, String.valueOf(httpStatusCode), | ||
| "https://developer.mozilla.org/en-US/docs/Web/HTTP/Status", new IllegalStateException(errorMessage)); |
There was a problem hiding this comment.
we should use official documentations link: https://datatracker.ietf.org/doc/html/rfc7231#section-6
| String errorMessage = String.format("Fetching from url '%s' returned status code '%d' and body '%s'", | ||
| nextPageUrl, httpStatusCode, response.getBody()); | ||
| throw ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), | ||
| errorMessage, String.format("Error message: %s", errorMessage), |
There was a problem hiding this comment.
don't do redundant Error message: %s
There was a problem hiding this comment.
removed from all files
| case STOP: | ||
| throw new IllegalStateException(String.format("Fetching from url '%s' returned status code '%d' and body '%s'", | ||
| nextPageUrl, httpStatusCode, response.getBody())); | ||
| String errorMessage = String.format("Fetching from url '%s' returned status code '%d' and body '%s'", |
| throw new IllegalArgumentException("Invalid URL: " + configURL, e); | ||
| } catch (IOException e) { | ||
| LOG.warn("Error making {} request to URL {}.", config.getMethod(), config.getUrl()); | ||
| String errorMessage = "Unable to make request. "; |
There was a problem hiding this comment.
this is not an actional error reason
| LOG.warn("Error making {} request to URL {}.", config.getMethod(), config.getUrl()); | ||
| String errorMessage = "Unable to make request. "; | ||
| throw ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), | ||
| errorMessage, String.format("Error message: %s", errorMessage), ErrorType.UNKNOWN, true, e); |
There was a problem hiding this comment.
similar comment here
| if (!shouldRetry) { | ||
| messageBuffer.clear(); | ||
| retryCount = 0; | ||
| String errorMessage = String.format("Unable to execute HTTP request to %s.", url); |
| retryCount = 0; | ||
| String errorMessage = String.format("Unable to execute HTTP request to %s.", url); | ||
| throw ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), | ||
| errorMessage, String.format("Error message: %s", errorMessage), ErrorType.SYSTEM, true, e); |
There was a problem hiding this comment.
similar comment here
| String errorMessage = String.format("Unable to execute HTTP request to %s.", url); | ||
| throw ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), | ||
| errorMessage, String.format("Error message: %s", errorMessage), ErrorType.SYSTEM, true, e); | ||
|
|
There was a problem hiding this comment.
nit: remove empty line
| } catch (Exception e) { | ||
| String errorMessage = String.format("Unexpected error occurred while executing HTTP request to URL: %s", url); | ||
| throw ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), | ||
| errorMessage, String.format("Error message: %s", errorMessage), ErrorType.UNKNOWN, true, e); |
There was a problem hiding this comment.
similar comment here
| AuthScope authScope = new AuthScope(new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme())); | ||
| credentialsProvider.setCredentials(authScope, | ||
| new UsernamePasswordCredentials(config.getUsername(), config.getPassword())); | ||
| new UsernamePasswordCredentials(config.getUsername(), config.getPassword())); |
There was a problem hiding this comment.
revert unintended changes.
| new UsernamePasswordCredentials( | ||
| config.getProxyUsername(), config.getProxyPassword())); |
There was a problem hiding this comment.
revert unintended changes
| headers.put("Content-Type", contentType); | ||
| } | ||
|
|
||
|
|
There was a problem hiding this comment.
nit: remove empty line
| List<PlaceholderBean> placeholderList = new ArrayList<>(); | ||
| if (!(config.getMethod().equals(REQUEST_METHOD_PUT) || config.getMethod().equals(REQUEST_METHOD_PATCH) || | ||
| config.getMethod().equals(REQUEST_METHOD_DELETE))) { | ||
| config.getMethod().equals(REQUEST_METHOD_DELETE))) { |
There was a problem hiding this comment.
revert unintended changes
| .await().with() | ||
| .pollInterval(pollInterval) | ||
| .pollDelay(config.getWaitTimeBetweenPages(), TimeUnit.MILLISECONDS) | ||
| .timeout(config.getMaxRetryDuration(), TimeUnit.SECONDS) | ||
| .until(this::executeHTTPServiceAndCheckStatusCode); |
There was a problem hiding this comment.
revert unintended changes
| String errorMessage = "Error while executing http request for remaining input messages" + | ||
| " after the batch execution."; | ||
| throw ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), | ||
| errorMessage, String.format("Error message: %s", errorMessage), ErrorType.UNKNOWN, true, |
There was a problem hiding this comment.
similar comment here
There was a problem hiding this comment.
Also don't we have status code information here?
| } catch (Exception e) { | ||
| throw new RuntimeException("Error while executing http request for remaining input messages " + | ||
| "after the batch execution. " + e); | ||
| String errorMessage = "Error while executing http request for remaining input messages" + |
There was a problem hiding this comment.
can we add http request information here?
| return new DelimitedPage(config, httpResponse, "\t"); | ||
| } catch (IOException e) { | ||
| String errorMessage = | ||
| String.format("Failed to read TSV page with status code '%s'", httpResponse.getStatusCode()); |
There was a problem hiding this comment.
similar comment for this file, if responseCode first check if response code is not 200.
| getHttpClient().close(); | ||
| } | ||
| } catch (IOException e) { | ||
| String errorMessage = "Failed to close http client."; |
There was a problem hiding this comment.
String errorMessage = String.format("Failed to close http client with message: %s.", e.getMessage());
| try { | ||
| response.close(); | ||
| } catch (IOException e) { | ||
| String errorMessage = "Failed to close response."; |
There was a problem hiding this comment.
String errorMessage = String.format("Failed to close http response with message: %s.", e.getMessage());
| errorMessage, errorMessage, pair.getErrorType(), true, ErrorCodeType.HTTP, | ||
| String.valueOf(httpResponse.getStatusCode()), HttpErrorDetailsProvider.getSupportedDocumentUrl(), e); | ||
| } else { | ||
| String errorReason = "Unable to read line from http page buffer."; |
There was a problem hiding this comment.
String errorReason = String.format("Unable to read line from http page buffer with message: %s, e.getMessage()")
| String errorMessage = | ||
| String.format("Unable to read line from http page buffer: %s. %s", httpResponse.getStatusCode(), | ||
| pair.getCorrectiveAction()); | ||
| throw ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), |
There was a problem hiding this comment.
similar comment here,
String errorReason = String.format("Unable to read line from http page buffer: %s. %s", httpResponse.getStatusCode(), pair.getCorrectiveAction());
String errorMessage = String.format("Unable to read line from http page buffer with code: %s, message: %s", httpResponse.getStatusCode(), e.getMessage());
similar comments for whole PR.
fixed |
| ErrorHandling postRetryStrategy) { | ||
| return PageFactory.createInstance(config, httpResponse, httpErrorHandler, | ||
| !postRetryStrategy.equals(ErrorHandling.SUCCESS)); | ||
| !postRetryStrategy.equals(ErrorHandling.SUCCESS)); |
There was a problem hiding this comment.
revert unintended changes.
There was a problem hiding this comment.
these changes are due to the new check style file added in IDE which u recommended
| e.getMessage()); | ||
| return ErrorUtils.getProgramFailureException( | ||
| new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), errorReason, errorReason, | ||
| ErrorType.SYSTEM, true, null); |
There was a problem hiding this comment.
why is exception not added as cause here?
| @@ -38,15 +45,51 @@ public static BasePage createInstance(BaseHttpSourceConfig config, HttpResponse | |||
| case XML: | |||
| return new XmlPage(config, httpResponse); | |||
There was a problem hiding this comment.
why not similar try & catch in JsonPage & XmlPage?
| boolean followRedirects, boolean disableSSLValidation, @Nullable String httpErrorsHandling, | ||
| String errorHandling, String retryPolicy, @Nullable Long linearRetryInterval, | ||
| Long maxRetryDuration, @Nullable int readTimeout, @Nullable int connectTimeout, | ||
| Long maxRetryDuration, int readTimeout, int connectTimeout, |
There was a problem hiding this comment.
revet unintended changes
There was a problem hiding this comment.
these changes are due to the new check style file added in IDE which u recommended
| String errorMessage = "Unable to close the buffered reader for the http response."; | ||
| throw ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), | ||
| errorMessage, errorMessage, ErrorType.SYSTEM, true, null); |
There was a problem hiding this comment.
errorReason = "Unable to close the buffered reader for the http response."
errorMessage = String.format("Unable to close the buffered reader for the http response, %s: %s", e.getClass().getName(), e.getMessage())
throw ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), errorReason, errorMessage, ErrorType.SYSTEM, false, e);
| "Unable to read line from http page buffer with message: %s", e.getMessage()); | ||
| throw ErrorUtils.getProgramFailureException( | ||
| new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), errorReason, | ||
| errorReason, ErrorType.SYSTEM, true, null); |
There was a problem hiding this comment.
why cause is null?
itsankit-google
left a comment
There was a problem hiding this comment.
The screenshot of logs added in description is not visible. Please add screenshots of error management UI & API response in the description.
updated the screenshot |
itsankit-google
left a comment
There was a problem hiding this comment.
For more details, see %s, supportDocUrl
please add the above information to errorReason and remove it from errorMessage.
This comment applies to whole PR.
Updated at all places |
| ErrorUtils.ActionErrorPair pair = ErrorUtils.getActionErrorByStatusCode( | ||
| httpResponse.getStatusCode()); | ||
| String errorReason = String.format( | ||
| "Failed to read %S page with status code: %s. %s. For more details, see %s", fileFormat, |
itsankit-google
left a comment
There was a problem hiding this comment.
one minor comment, rest LGTM.
Please update screenshots in PR description before merge.
…ckage to handle error provider, fix sonar issues and added Validation error for linear retry duration
a123dd8 to
bdafbf1
Compare
[ { "stageName": "HTTP", "errorCategory": "Plugin-'HTTP'", "errorReason": "Unable to read new page: 403. Please check you have permission to access this resource.. For more details, see https://datatracker.ietf.org/doc/html/rfc7231#section-6", "errorMessage": "Retry failed! Unable to read new page and execute request. Fetching from 'https://storage.googleapis.com/range_dw_demo_goog/5data.csv' returned http error status code '403'.", "errorType": "USER", "dependency": "true", "errorCodeType": "HTTP", "errorCode": "403", "supportedDocumentationUrl": "https://datatracker.ietf.org/doc/html/rfc7231#section-6" } ]