feat(plugins): support long-lived files streaming #742
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🎯 Overview
This PR introduces a new file completion strategy system that allows users to control when files should be marked as
COMPLETED, addressing the limitations of the previous immediate completion on EOF behavior. This is particularly valuable for long-lived, continuously appended files such as daily log files.💡 Motivation
Problem
Previously, Kafka Connect File Pulse would always mark files as
COMPLETEDimmediately when they were fully read (EOF reached). While this works perfectly for static files, it creates significant challenges for continuously appended files:app-2025-12-08.log) would be marked complete as soon as they're first read, preventing the connector from reading additional data appended laterSolution
I have implemented a strategy pattern that allows users to:
🏗️ Architecture
New Components
1.
FileCompletionStrategyInterface (API)Location:
connect-file-pulse-api/src/main/java/io/streamthoughts/kafka/connect/filepulse/source/FileCompletionStrategy.javaCore strategy interface that defines:
2.
LongLivedFileReadStrategyInterface (API)Location:
connect-file-pulse-api/src/main/java/io/streamthoughts/kafka/connect/filepulse/source/LongLivedFileReadStrategy.javaOptional interface for strategies managing long-lived files:
This interface enables read deferral - strategies can signal to the connector when NOT to attempt reading a file (e.g., when no new data is expected), avoiding unnecessary polling and timeouts while still allowing eventual completion.
3.
EofCompletionStrategy(Default)Location:
connect-file-pulse-plugin/src/main/java/io/streamthoughts/kafka/connect/filepulse/source/EofCompletionStrategy.javaDefault implementation that maintains 100% backward compatibility:
COMPLETEDimmediately when fully read4.
DailyCompletionStrategyLocation:
connect-file-pulse-plugin/src/main/java/io/streamthoughts/kafka/connect/filepulse/source/DailyCompletionStrategy.javaNew strategy for daily files that:
Example:
logs-2025-12-08.log(created Dec 8, 2025 at 6:00 AM)01:00:005.
DailyCompletionStrategyConfigLocation:
connect-file-pulse-plugin/src/main/java/io/streamthoughts/kafka/connect/filepulse/config/DailyCompletionStrategyConfig.javaConfiguration class with validators for:
daily.completion.schedule.time: Time in HH:mm:ss format (default:00:01:00)daily.completion.schedule.date.pattern: Regex to extract date (default:.*?(\\d{4}-\\d{2}-\\d{2}).*)daily.completion.schedule.date.format: Date format pattern (default:yyyy-MM-dd)Modified Components
1.
CommonSourceConfigFS_COMPLETION_STRATEGY_CLASS_CONFIGconfiguration propertyEofCompletionStrategy.class(backward compatible)getFileCompletionStrategy()method to instantiate configured strategy2.
DefaultFileRecordsPollingConsumerFileCompletionStrategyinto the polling logicshouldComplete()to determine when to mark files asCOMPLETED3.
DefaultFileSystemMonitorLongLivedFileReadStrategysupportshouldAttemptRead()to avoid unnecessary polling4.
FilePulseSourceTask&FilePulseSourceConnectorFileCompletionStrategyto consumer🔄 Backward Compatibility
100% Backward Compatible
EofCompletionStrategy(immediate completion)Migration Path
Existing configurations continue to work as-is:
{ "name": "my-existing-connector", "connector.class": "io.streamthoughts.kafka.connect.filepulse.source.FilePulseSourceConnector" // No fs.completion.strategy.class specified = uses EofCompletionStrategy (default) }To adopt new functionality, simply add the configuration:
{ "name": "my-connector", "connector.class": "io.streamthoughts.kafka.connect.filepulse.source.FilePulseSourceConnector", "fs.completion.strategy.class": "io.streamthoughts.kafka.connect.filepulse.source.DailyCompletionStrategy", "daily.completion.schedule.time": "01:00:00", "daily.completion.schedule.date.pattern": ".*?(\\d{4}-\\d{2}-\\d{2}).*", "daily.completion.schedule.date.format": "yyyy-MM-dd" }📋 Configuration
Common Configuration
fs.completion.strategy.classEofCompletionStrategyDailyCompletionStrategy Configuration
daily.completion.schedule.time00:01:00daily.completion.schedule.date.pattern.*?(\\d{4}-\\d{2}-\\d{2}).*daily.completion.schedule.date.formatyyyy-MM-dd🎯 Use Cases
Use Case 1: Daily Log Files
Scenario: Application writes to
app-2025-12-08.logthroughout December 8th. You want to continuously read new data but only mark the file complete at 1 AM on December 9th.Configuration:
{ "fs.completion.strategy.class": "io.streamthoughts.kafka.connect.filepulse.source.DailyCompletionStrategy", "daily.completion.schedule.time": "01:00:00", "daily.completion.schedule.date.pattern": ".*?(\\d{4}-\\d{2}-\\d{2}).*", "daily.completion.schedule.date.format": "yyyy-MM-dd" }Use Case 2: Static Files (Backward Compatible)
Scenario: Standard file ingestion - complete files immediately when fully read.
Configuration: None needed (default behavior).
Use Case 3: Custom Completion Logic
Scenario: Implement your own completion strategy based on file size, record count, external triggers, etc.
Implementation: Implement
FileCompletionStrategyinterface and configure your custom class.🚀 Benefits
LongLivedFileReadStrategyreduces unnecessary polling and resource usage