-
Notifications
You must be signed in to change notification settings - Fork 29
[PLUGIN-1826] Error Management HTTP Source and Sink and fix sonar issues #180
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
[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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should use official documentations link: https://datatracker.ietf.org/doc/html/rfc7231#section-6
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.
updated
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't do redundant Error message: %s
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.
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'", |
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.
errorReason
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.
updated
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not an actional error reason
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.
updated
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar comment here
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.
updated
| if (!shouldRetry) { | ||
| messageBuffer.clear(); | ||
| retryCount = 0; | ||
| String errorMessage = String.format("Unable to execute HTTP request to %s.", url); |
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.
errorReason
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.
updated
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar comment here
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.
updated
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove empty line
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.
removed
| } 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar comment here
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.
updated
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert unintended changes.
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.
Reverted !
| new UsernamePasswordCredentials( | ||
| config.getProxyUsername(), config.getProxyPassword())); |
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.
revert unintended changes
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.
Reverted !
| headers.put("Content-Type", contentType); | ||
| } | ||
|
|
||
|
|
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.
nit: remove empty line
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.
removed
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert unintended changes
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.
reverted !
| .await().with() | ||
| .pollInterval(pollInterval) | ||
| .pollDelay(config.getWaitTimeBetweenPages(), TimeUnit.MILLISECONDS) | ||
| .timeout(config.getMaxRetryDuration(), TimeUnit.SECONDS) | ||
| .until(this::executeHTTPServiceAndCheckStatusCode); |
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.
revert unintended changes
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.
Revertd !
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar comment here
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.
Also don't we have status code information here?
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.
updated
| } 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add http request information here?
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.
added
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar comment for this file, if responseCode first check if response code is not 200.
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.
updated
| getHttpClient().close(); | ||
| } | ||
| } catch (IOException e) { | ||
| String errorMessage = "Failed to close http client."; |
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.
String errorMessage = String.format("Failed to close http client with message: %s.", e.getMessage());
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.
updated
| try { | ||
| response.close(); | ||
| } catch (IOException e) { | ||
| String errorMessage = "Failed to close response."; |
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.
String errorMessage = String.format("Failed to close http response with message: %s.", e.getMessage());
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.
updated
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String errorReason = String.format("Unable to read line from http page buffer with message: %s, e.getMessage()")
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.
updated
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
updated
psainics
left a comment
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.
FIX Unit Tests !
fixed |
| ErrorHandling postRetryStrategy) { | ||
| return PageFactory.createInstance(config, httpResponse, httpErrorHandler, | ||
| !postRetryStrategy.equals(ErrorHandling.SUCCESS)); | ||
| !postRetryStrategy.equals(ErrorHandling.SUCCESS)); |
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.
revert unintended changes.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is exception not added as cause here?
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.
updated
| case JSON: | ||
| return new JsonPage(config, httpResponse); | ||
| case XML: | ||
| return new XmlPage(config, httpResponse); |
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.
why not similar try & catch in JsonPage & XmlPage?
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.
added
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revet unintended changes
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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);
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.
updated
| "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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why cause is null?
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.
updated
itsankit-google
left a comment
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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, |
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.
nit: %s
itsankit-google
left a comment
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.
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" } ]