Skip to content

Commit 4786a24

Browse files
AutomationDev85mangal-vairalkar
authored andcommitted
Throttle HTTPError during consume pod logs (apache#54761)
Co-authored-by: AutomationDev85 <AutomationDev85>
1 parent fce5ce2 commit 4786a24

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

  • providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/utils

providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/utils/pod_manager.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -560,10 +560,17 @@ def consume_logs(*, since_time: DateTime | None = None) -> tuple[DateTime | None
560560
return val.add(seconds=2), e
561561
except HTTPError as e:
562562
exception = e
563-
self.log.exception(
564-
"Reading of logs interrupted for container %r; will retry.",
565-
container_name,
566-
)
563+
self._http_error_timestamps = getattr(self, "_http_error_timestamps", [])
564+
self._http_error_timestamps = [
565+
t for t in self._http_error_timestamps if t > utcnow() - timedelta(seconds=60)
566+
]
567+
self._http_error_timestamps.append(utcnow())
568+
# Log only if more than 2 errors occurred in the last 60 seconds
569+
if len(self._http_error_timestamps) > 2:
570+
self.log.exception(
571+
"Reading of logs interrupted for container %r; will retry.",
572+
container_name,
573+
)
567574
return last_captured_timestamp or since_time, exception
568575

569576
# note: `read_pod_logs` follows the logs, so we shouldn't necessarily *need* to

0 commit comments

Comments
 (0)