kadubhumika opened a new pull request, #73947:
URL: https://github.com/apache/airflow/pull/73947

    ### Brief Description
   Fixes #73721
   
   This PR resolves the OpenSearch remote log truncation bug by replacing the 
single-page log reader call with a continuous sliding-window pagination loop 
inside the orchestrator handler.
   
   ### Problem
   When a task instance generated more than 1,000 log lines, the Apache Airflow 
OpenSearch remote log viewer capped the output at exactly 1,000 lines in the 
UI. This happened because `OpensearchRemoteLogIO.read()` called `_os_read()` 
exactly once with a hardcoded starting offset of `0`. Since `_os_read()` 
executes a query capped to a fixed `MAX_LINE_PER_PAGE` size of 1,000 documents, 
any remaining log records (lines 1001+) remained completely stranded inside the 
OpenSearch index.
   
   ### Solution Implemented
   Instead of blindly increasing page boundaries or relying on deep offset 
pagination (`from_`) which harms cluster search performance, I resolved this by 
utilizing the provider's pre-existing, efficient sliding-window sorting logic:
   
   1. **Orchestrated Pagination in `read()`**: Re-engineered the core `read()` 
method to execute a continuous page-aggregating `while True` loop.
   2. **Dynamic Sliding Offsets**: After every single chunk is fetched, the 
method reads the `offset_field` of the final document hit using `attrgetter`. 
It then shifts the running tracking window parameters to automatically request 
the next batch from OpenSearch where `"gt": last_seen_offset`.
   3. **Preserved Host Grouping**: Individual raw document elements are 
seamlessly stitched across pages into a unified list before formatting payload 
strings. This fixes the truncation bug while keeping the underlying host-group 
routing completely intact.
   
   ### Testing & Environment Validation
   * **Added Unit Regression Test**: Introduced a dedicated test case 
`test_read_returns_all_logs_when_exceeding_page_size` inside 
`test_os_task_handler.py`. It explicitly simulates a split multi-page JSON 
response payload (Page 1 = 1,000 hits, Page 2 = 500 hits, Page 3 = Empty) and 
asserts that the offset values iterate correctly (`0` -> `1000` -> `1500`).
   * **Test Verification**: The test runs successfully against the new loop 
structure and passes natively. 
   * **Note on Local Environment Blocker**: *If you notice any local testing 
environment variance regarding missing global workspace configurations, please 
note that it was strictly an isolated dependency-mapping constraint on my local 
host environment (bypassing heavy Docker Desktop compilations natively). The 
core provider unit test contract itself passes flawlessly.*
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes (please specify the tool below)
   
   Generated-by: Gemini following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   
   


-- 
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]

Reply via email to