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

   When `KubernetesPodOperator` follows a container's logs and the read ends 
while the container still reports as running, `fetch_container_logs` reads 
again from the last logged timestamp. The log API only accepts `sinceSeconds`, 
so the new read starts up to a second earlier, and those lines were logged a 
second time. #39861 added a warning for this ("Logs generated in the last one 
second might get duplicated") but left the duplication in place.
   
   This change skips the repeated lines in the loop that already parses each 
line's timestamp, so no extra parsing is added. `PodManager` now records the 
newest timestamp read from each container and how many lines carried it. A 
resumed read drops lines before that timestamp, plus their untimestamped 
continuation lines. At that exact timestamp it drops only as many lines as were 
already read. Timestamps are parsed to the microsecond, so a burst of lines 
(such as a traceback) can share one, and a read can stop partway through it. 
The warning no longer says logs might be duplicated.
   
   We hit this in production on 10.21.0, where some task logs repeated their 
last lines and one repeated every line. We've been running the same logic as a 
`PodManager` subclass.
   
   Tests: a parametrized test covers a replayed last second, replayed 
continuation lines, and an unread line that shares the last logged timestamp. 
All three fail without the change.
   
   A possible follow-up, not changed here: on a read timeout, `consume_logs` 
resumes from the last timestamp plus 2 seconds to avoid duplicates. That can 
drop lines written in those 2 seconds, and with this change the offset is no 
longer needed.
   
   related: #39236, #33498
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes (please specify the tool below)
   
   Generated-by: Claude Code 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]

  • [PR] Skip pod log lines alread... mmenanno (via GitHub) via commits

Reply via email to