log errors in lines, and ignore empty lines

This commit is contained in:
rasmus 2022-11-06 15:57:18 +02:00
parent b03c845406
commit 1ddc479e4b

View File

@ -73,7 +73,7 @@ func (s *submitter) shipFile(ctx context.Context, name string, deleteAfterRead b
} }
promFileErr.WithLabelValues(baseName).Add(1) promFileErr.WithLabelValues(baseName).Add(1)
s.l.Error("shipping file", zap.String("filename", baseName), zap.Error(err)) s.l.Error("shipping file", zap.String("filename", name), zap.Error(err))
return false, nil // nil since we want to loop and keep retrying indefinitely return false, nil // nil since we want to loop and keep retrying indefinitely
}) })
} }
@ -135,6 +135,10 @@ func (s *submitter) shipFileRoutine(ctx context.Context, name string, sendQueue
} }
} }
if line.String == "" {
continue
}
var collectTime time.Time var collectTime time.Time
var stdErr, format, log string var stdErr, format, log string
@ -142,6 +146,7 @@ func (s *submitter) shipFileRoutine(ctx context.Context, name string, sendQueue
if len(split) != 4 { if len(split) != 4 {
log = line.String log = line.String
promLineParsingErr.WithLabelValues(baseName).Add(1) promLineParsingErr.WithLabelValues(baseName).Add(1)
s.l.Error("parsing line", zap.Error(fmt.Errorf("expected at least 3 spaces in container log")), zap.Int("got", len(split)-1), zap.String("file", name))
} else { } else {
stdErr, format, log = split[1], split[2], split[3] stdErr, format, log = split[1], split[2], split[3]
@ -149,6 +154,7 @@ func (s *submitter) shipFileRoutine(ctx context.Context, name string, sendQueue
collectTime, err = time.Parse(time.RFC3339Nano, split[0]) collectTime, err = time.Parse(time.RFC3339Nano, split[0])
if err != nil { if err != nil {
promLineParsingErr.WithLabelValues(baseName).Add(1) promLineParsingErr.WithLabelValues(baseName).Add(1)
s.l.Error("parsing line time", zap.Error(err), zap.String("file", name))
} }
} }