suvodeep-pyne opened a new pull request, #16747:
URL: https://github.com/apache/pinot/pull/16747
## Summary
This PR implements request body capturing functionality for the audit
logging system in Pinot. The implementation safely captures HTTP request bodies
while preserving the input stream for downstream consumers.
## Changes
### Core Implementation (`AuditRequestProcessor.java`)
- Added `readRequestBody` method to capture request bodies from Jersey
`ContainerRequestContext`
- Uses `BufferedInputStream` with mark/reset pattern for non-destructive
stream reading
- Implements payload size limits with graceful truncation (adds
`...[truncated]` marker when exceeded)
- Leverages Guava's `ByteStreams` utilities for efficient stream handling
- Ensures stream remains readable for downstream consumers even on audit
failures
- Proper UTF-8 encoding support
### Configuration (`AuditConfig.java`)
- Added `MAX_AUDIT_PAYLOAD_SIZE_BYTES` constant (65536 bytes) as hard limit
- Updated default `maxPayloadSize` to 8192 bytes
- Fixed JSON property name to `request.payload.size.max.bytes`
### Testing (`AuditRequestProcessorTest.java`)
- Comprehensive test suite with 15 test methods covering:
- Stream preservation for downstream consumers
- Payload truncation at configured limits
- Error handling and recovery scenarios
- UTF-8 character encoding
- JSON payload handling (simple, large, nested)
- Edge cases (null stream, empty body, no entity)
## Key Design Decisions
1. **Stream Preservation**: Uses `BufferedInputStream` with mark/reset to
ensure the original request can still be processed even if audit logging fails
2. **Efficient Truncation**: Directly appends truncation marker without
unnecessary string copying
3. **Graceful Degradation**: Audit failures never impact the main request
processing
4. **Package-Private Testing**: Method is package-private with
`@VisibleForTesting` annotation for clean testing without reflection
## Testing
All tests pass successfully. The implementation has been tested with various
payload types including plain text, JSON, and UTF-8 encoded content.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]