Skip to content

Conversation

@Amit-CloudSufi
Copy link
Contributor

@Amit-CloudSufi Amit-CloudSufi commented Dec 6, 2024

image

[
  {
    "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"
  }
]
2025-01-28 17:59:23,034 - ERROR [Executor task launch worker for task 0.0 in stage 0.0 (TID 0):o.a.s.u.Utils@98] - Aborting task
io.cdap.cdap.api.exception.WrappedStageException: Stage 'HTTP' encountered : io.cdap.cdap.api.exception.ProgramFailureException: 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'.
	at io.cdap.cdap.etl.common.ErrorDetails.handleException(ErrorDetails.java:77)
	at io.cdap.cdap.etl.spark.io.StageTrackingRecordReader.nextKeyValue(StageTrackingRecordReader.java:71)
	at org.apache.spark.rdd.NewHadoopRDD$$anon$1.hasNext(NewHadoopRDD.scala:251)
	at org.apache.spark.InterruptibleIterator.hasNext(InterruptibleIterator.scala:37)
	at scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:491)
	at scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:491)
	at scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:491)
	at org.apache.spark.internal.io.SparkHadoopWriter$.$anonfun$executeTask$1(SparkHadoopWriter.scala:136)
	at org.apache.spark.util.Utils$.tryWithSafeFinallyAndFailureCallbacks(Utils.scala:1538)
	at org.apache.spark.internal.io.SparkHadoopWriter$.executeTask(SparkHadoopWriter.scala:135)
	at org.apache.spark.internal.io.SparkHadoopWriter$.$anonfun$write$1(SparkHadoopWriter.scala:88)
	at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:90)
	at org.apache.spark.scheduler.Task.run(Task.scala:136)
	at org.apache.spark.executor.Executor$TaskRunner.$anonfun$run$3(Executor.scala:548)
	at org.apache.spark.util.Utils$.tryWithSafeFinally(Utils.scala:1504)
	at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:551)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:750)
Caused by: io.cdap.cdap.api.exception.ProgramFailureException: 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'.
	at io.cdap.cdap.api.exception.ProgramFailureException$Builder.build(ProgramFailureException.java:229)
	at io.cdap.cdap.api.exception.ErrorUtils.getProgramFailureException(ErrorUtils.java:198)
	at io.cdap.plugin.http.common.pagination.BaseHttpPaginationIterator.getNextPage(BaseHttpPaginationIterator.java:156)
	at io.cdap.plugin.http.common.pagination.BaseHttpPaginationIterator.ensurePageIterable(BaseHttpPaginationIterator.java:193)
	at io.cdap.plugin.http.common.pagination.BaseHttpPaginationIterator.hasNext(BaseHttpPaginationIterator.java:231)
	at io.cdap.plugin.http.source.batch.HttpRecordReader.nextKeyValue(HttpRecordReader.java:64)
	at io.cdap.cdap.etl.spark.io.TrackingRecordReader.nextKeyValue(TrackingRecordReader.java:47)
	at io.cdap.cdap.etl.spark.io.StageTrackingRecordReader.nextKeyValue(StageTrackingRecordReader.java:69)
	... 17 common frames omitted

@google-cla

This comment was marked as resolved.

@psainics psainics added the build label Dec 9, 2024
@Amit-CloudSufi Amit-CloudSufi changed the title Added HTTP error detail provider and refactored HTTP-sink and source package to handle error provider and fix sonar issues [PLUGIN-1826] Error Management HTTP Source and Sink and fix sonar issues Dec 9, 2024
@Amit-CloudSufi Amit-CloudSufi force-pushed the httpPluginErrorMang branch 2 times, most recently from e612cd0 to d273336 Compare December 12, 2024 11:59
@psainics psainics added build and removed build labels Dec 18, 2024
Copy link
Contributor

@itsankit-google itsankit-google left a 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));
Copy link
Contributor

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

Copy link
Contributor Author

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),
Copy link
Contributor

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

Copy link
Contributor Author

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'",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errorReason

Copy link
Contributor Author

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. ";
Copy link
Contributor

@itsankit-google itsankit-google Dec 20, 2024

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

Copy link
Contributor Author

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar comment here

Copy link
Contributor Author

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errorReason

Copy link
Contributor Author

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar comment here

Copy link
Contributor Author

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);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove empty line

Copy link
Contributor Author

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar comment here

Copy link
Contributor Author

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()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert unintended changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted !

Comment on lines 274 to 275
new UsernamePasswordCredentials(
config.getProxyUsername(), config.getProxyPassword()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert unintended changes

Copy link
Contributor

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);
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove empty line

Copy link
Contributor Author

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))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert unintended changes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted !

Comment on lines 366 to 370
.await().with()
.pollInterval(pollInterval)
.pollDelay(config.getWaitTimeBetweenPages(), TimeUnit.MILLISECONDS)
.timeout(config.getMaxRetryDuration(), TimeUnit.SECONDS)
.until(this::executeHTTPServiceAndCheckStatusCode);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert unintended changes

Copy link
Contributor

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar comment here

Copy link
Contributor

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?

Copy link
Contributor Author

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" +
Copy link
Contributor

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?

Copy link
Contributor Author

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());
Copy link
Contributor

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.

Copy link
Contributor Author

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.";
Copy link
Contributor

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());

Copy link
Contributor Author

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.";
Copy link
Contributor

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());

Copy link
Contributor Author

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.";
Copy link
Contributor

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()")

Copy link
Contributor Author

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),
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Copy link
Contributor

@psainics psainics left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIX Unit Tests !

@Amit-CloudSufi
Copy link
Contributor Author

FIX Unit Tests !

fixed

ErrorHandling postRetryStrategy) {
return PageFactory.createInstance(config, httpResponse, httpErrorHandler,
!postRetryStrategy.equals(ErrorHandling.SUCCESS));
!postRetryStrategy.equals(ErrorHandling.SUCCESS));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert unintended changes.

Copy link
Contributor Author

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revet unintended changes

Copy link
Contributor Author

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

Comment on lines 65 to 67
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);
Copy link
Contributor

@itsankit-google itsankit-google Jan 27, 2025

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);

Copy link
Contributor Author

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why cause is null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Copy link
Contributor

@itsankit-google itsankit-google left a 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.

@Amit-CloudSufi
Copy link
Contributor Author

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

Copy link
Contributor

@itsankit-google itsankit-google left a 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.

@Amit-CloudSufi
Copy link
Contributor Author

For more details, see %s, supportDocUrl

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: %s

Copy link
Contributor

@itsankit-google itsankit-google left a 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
@psainics psainics merged commit 4a33a28 into data-integrations:develop Jan 29, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants