fix: improve log retry logic (#3580)

* fix: improve log retry logic

* fix: streamline log retry logic and improve error handling
mine
Ümüt Özalp 2025-09-27 16:51:43 +02:00 committed by GitHub
parent 5b877f5807
commit 2ed7206896
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 9 deletions

View File

@ -372,6 +372,12 @@ func tailLogs(ctx context.Context, logger Logger, opts *LogOptions) LogChan {
delay := logBackoffInitial
for range logRetryCount {
req, err := logger.Logs(opts.Path, podOpts)
if err != nil {
slog.Error("Log request failed",
slogs.Container, opts.Info(),
slogs.Error, err,
)
// Check if we should stop retrying based on pod status
if pod, ok := logger.(*Pod); ok && pod.shouldStopRetrying(opts.Path) {
slog.Debug("Stopping log retry - pod is terminating or deleted",
@ -379,13 +385,6 @@ func tailLogs(ctx context.Context, logger Logger, opts *LogOptions) LogChan {
)
return
}
req, err := logger.Logs(opts.Path, podOpts)
if err != nil {
slog.Error("Log request failed",
slogs.Container, opts.Info(),
slogs.Error, err,
)
select {
case <-ctx.Done():
return
@ -403,6 +402,13 @@ func tailLogs(ctx context.Context, logger Logger, opts *LogOptions) LogChan {
slogs.Error, e,
slogs.Container, opts.Info(),
)
// Check if we should stop retrying based on pod status
if pod, ok := logger.(*Pod); ok && pod.shouldStopRetrying(opts.Path) {
slog.Debug("Stopping log retry - pod is terminating or deleted",
slogs.Container, opts.Info(),
)
return
}
select {
case <-ctx.Done():
return
@ -466,7 +472,7 @@ func tailLogs(ctx context.Context, logger Logger, opts *LogOptions) LogChan {
func readLogs(ctx context.Context, stream io.ReadCloser, out chan<- *LogItem, opts *LogOptions) streamResult {
defer func() {
if err := stream.Close(); err != nil && !errors.Is(err, io.ErrClosedPipe) {
slog.Error("Fail to close stream",
slog.Error("Failed to close stream",
slogs.Container, opts.Info(),
slogs.Error, err,
)