Skip to content

[FLINK-39367][connector-http] Add configurable error logging with detailed context#35

Open
featzhang wants to merge 6 commits into
apache:mainfrom
featzhang:feature/improve-error-logging
Open

[FLINK-39367][connector-http] Add configurable error logging with detailed context#35
featzhang wants to merge 6 commits into
apache:mainfrom
featzhang:feature/improve-error-logging

Conversation

@featzhang
Copy link
Copy Markdown
Member

Purpose

This PR improves HTTP request error logging in the HTTP connector by adding configurable error logging with detailed context. Previously, HTTP errors were logged with minimal information, making it difficult to diagnose issues in production environments. This enhancement provides more comprehensive error details including HTTP status codes, response bodies (configurable), and configurable log levels.

Change log

  • Added HttpErrorLogLevel enum for configurable error log levels (ERROR/WARN/INFO)
  • Added HttpErrorLogger class for enhanced error logging with detailed context
  • Added configuration options:
    • http.error.log.level: Controls error log level (default: ERROR)
    • http.error.log.include.body: Whether to include response body in logs (default: false)
    • http.error.log.body.max.size: Maximum body size to log in bytes (default: 1024)
  • Integrated HttpErrorLogger in JavaNetHttpPollingClient and JavaNetSinkHttpClient

Verifying

  • All existing tests pass
  • Added comprehensive unit tests for HttpErrorLogger (12 tests, all passing)
  • Code style checks pass (Checkstyle and Spotless)
  • Manual testing confirmed:
    • Error logging works with different log levels
    • Response body inclusion is configurable
    • Body size limit is enforced
    • Logs include all relevant context information

Affected Components

  • flink-connector-http-core: Core HTTP client implementation
  • Configuration system: New configuration parameters for error logging

Documentation

Configuration documentation should be updated to include the new error logging parameters:

  • http.error.log.level
  • http.error.log.include.body
  • http.error.log.body.max.size

Backward Compatibility

This change is fully backward compatible. All new configuration parameters have sensible defaults, and existing code will continue to work without modifications.

@featzhang featzhang changed the title [HTTP] Improve HTTP request error logging [FLINK-39367][connector-http] Add configurable error logging with detailed context Mar 31, 2026
Introduce HttpErrorLogger to surface HTTP errors at a configurable SLF4J
severity level (ERROR/WARN/INFO), independently of the existing
http.logging.level mechanism which controls content verbosity at DEBUG.

New configuration options:
- http.error.log.level        : log level for errors (default: ERROR)
- http.error.log.include.body : include request/response body (default: false)
- http.error.log.body.max.size: max body characters logged (default: 1024)

Sensitive headers (authorization, cookie, api-key, x-api-key) are
automatically masked in all HttpErrorLogger output.

Behavior respects continue-on-error:
- continue-on-error=false: errors are thrown and logged at configured level
- continue-on-error=true : errors are tolerated and logged at DEBUG only,
  since ERROR/WARN would be misleading when the connector is functioning
  as configured

Also adds a dedicated logSinkError overload for status-code-only failures
to avoid constructing synthetic Exception objects when no exception occurred.
@featzhang featzhang force-pushed the feature/improve-error-logging branch from 97a703b to ca2e622 Compare March 31, 2026 11:30

// -------------- Error logging configuration --------------

public static final String ERROR_LOG_LEVEL = FLINK_CONNECTOR_HTTP + "error.log.level";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we should fit in with the existing configuration based logging . We added this so that potentially sensitive information in the http messages could be obfuscated. We agreed that it would be possible to log out the clear content for development debugging. I suggest we use the existing controls and scope and extend them to to cover sink

featzhang and others added 5 commits April 23, 2026 00:35
Per reviewer feedback, removed HttpErrorLogger class and integrated
error logging functionality directly into the existing HttpLogger.

Changes:
- Extended HttpLogger with http.error.log.severity config (OFF/ERROR/WARN/INFO)
- Enhanced logLookupError() and logSinkError() to respect error severity level
- Maintained http.logging.level (MIN/REQ_RESP/MAX) for content verbosity
- Two orthogonal dimensions: content detail × error severity
- Backward compatible: default behavior unchanged (errors at DEBUG)
- Production-friendly: set http.error.log.severity=ERROR for monitoring

Removed:
- HttpErrorLogger class and related files
- Duplicate error logging configuration (ERROR_LOG_LEVEL, ERROR_LOG_INCLUDE_BODY, ERROR_LOG_BODY_MAX_SIZE)

Kept:
- Existing HttpLogger infrastructure
- Sensitive header masking
- Continue-on-error awareness (DEBUG when tolerated)

The refactored design provides:
1. http.logging.level (MIN/REQ_RESP/MAX) controls content verbosity
2. http.error.log.severity (OFF/INFO/WARN/ERROR) controls log level for actual errors
3. Errors with continue-on-error=true always log at DEBUG (tolerated errors)
4. Errors with continue-on-error=false respect http.error.log.severity setting
- Remove 9 trailing whitespace violations detected by Checkstyle
- Lines fixed: 53, 125, 131, 212, 215, 237, 257, 260, 319
- No functional changes, formatting only
- Fix Javadoc line length in HttpConnectorConfigConstants
- Reformat multiline method calls to match Google Java Style
- Fix indentation in log method calls (8 spaces for continuation)
- Files updated:
  * HttpConnectorConfigConstants.java
  * HttpLogger.java
  * JavaNetSinkHttpClient.java
  * JavaNetHttpPollingClient.java
- Consolidate method signatures to single line where possible
- Reformat nested String.format() calls with proper indentation
- Apply consistent 8-space continuation indent
- StringBuilder initialization formatting
- Consolidate String.format calls to single line
- Applies to two 'Request Headers' append operations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants