tidy logging

This commit is contained in:
rasmus 2022-11-06 22:24:33 +02:00
parent 1424096176
commit ce3f67754a
4 changed files with 10 additions and 10 deletions

View File

@ -62,7 +62,7 @@ func parseSingleContainerLine(line []byte) (u singleLine, err error) {
return u, err return u, err
} }
func (s *submitter) parseContainerLines(unparsed <-chan rawLine, parsed chan<- singleLine) { func (s *submitter) parseContainerLogLines(unparsed <-chan rawLine, parsed chan<- singleLine) {
for { for {
raw, ok := <-unparsed raw, ok := <-unparsed
if !ok { if !ok {
@ -73,7 +73,7 @@ func (s *submitter) parseContainerLines(unparsed <-chan rawLine, parsed chan<- s
line, err := parseSingleContainerLine(raw.line) line, err := parseSingleContainerLine(raw.line)
if err != nil { if err != nil {
promRecordPrefixParsingErr.WithLabelValues(raw.File).Add(1) promRecordPrefixParsingErr.WithLabelValues(raw.File).Add(1)
s.l.Error("parsing single container line", zap.Error(err), zap.String("file", raw.File)) s.l.Error("parsing container log line", zap.Error(err), zap.String("file", raw.File))
} }
line.mLog.recordMetadata = raw.recordMetadata line.mLog.recordMetadata = raw.recordMetadata
@ -84,7 +84,7 @@ func (s *submitter) parseContainerLines(unparsed <-chan rawLine, parsed chan<- s
// assumes all lines are from same file // assumes all lines are from same file
func (s *submitter) parseLines(bufferLimitBytes int, unparsed <-chan rawLine, parsed chan<- mLog) { func (s *submitter) parseLines(bufferLimitBytes int, unparsed <-chan rawLine, parsed chan<- mLog) {
lines := make(chan singleLine) lines := make(chan singleLine)
go s.parseContainerLines(unparsed, lines) go s.parseContainerLogLines(unparsed, lines)
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(2) wg.Add(2)
@ -151,6 +151,7 @@ func (s *submitter) parseStdChannel(bufferLimitBytes int, lines <-chan singleLin
if len(buffer) > bufferLimitBytes { if len(buffer) > bufferLimitBytes {
buffer = nil buffer = nil
promRecordDroppedTooLarge.WithLabelValues(line.File).Add(1) promRecordDroppedTooLarge.WithLabelValues(line.File).Add(1)
s.l.Warn("dropped record: too large", zap.Int("cap_bytes", bufferLimitBytes))
continue continue
} }

View File

@ -2,7 +2,6 @@ package logmower
import ( import (
"context" "context"
"fmt"
"time" "time"
prom "github.com/prometheus/client_golang/prometheus" prom "github.com/prometheus/client_golang/prometheus"
@ -45,7 +44,7 @@ func mongoMonitoredClientOptions(l *zap.Logger) *mongoOpt.ClientOptions {
}, },
ServerHeartbeatFailed: func(ev *mongoEvent.ServerHeartbeatFailedEvent) { ServerHeartbeatFailed: func(ev *mongoEvent.ServerHeartbeatFailedEvent) {
promDbHeartbeat.WithLabelValues(ev.ConnectionID).Observe(0) promDbHeartbeat.WithLabelValues(ev.ConnectionID).Observe(0)
l.Error("database heartbeat", zap.Error(ev.Failure), zap.String("connection_id", ev.ConnectionID)) l.Warn("database heartbeat", zap.Error(ev.Failure), zap.String("connection_id", ev.ConnectionID))
}, },
}). }).
SetMonitor(&mongoEvent.CommandMonitor{ SetMonitor(&mongoEvent.CommandMonitor{
@ -56,7 +55,6 @@ func mongoMonitoredClientOptions(l *zap.Logger) *mongoOpt.ClientOptions {
promDbCmd.WithLabelValues(ev.ConnectionID, ev.CommandName).Observe(time.Duration(ev.DurationNanos).Seconds()) promDbCmd.WithLabelValues(ev.ConnectionID, ev.CommandName).Observe(time.Duration(ev.DurationNanos).Seconds())
promDbCmdErr.WithLabelValues(ev.ConnectionID, ev.CommandName).Add(1) promDbCmdErr.WithLabelValues(ev.ConnectionID, ev.CommandName).Add(1)
l.Error("database command", zap.Error(fmt.Errorf("%s", ev.Failure)), zap.String("connection_id", ev.ConnectionID), zap.String("command_name", ev.CommandName)) // TODO: https://github.com/mongodb/mongo-go-driver/pull/1105
}, },
}) })
} }

View File

@ -97,11 +97,12 @@ func (s *submitter) sender(name string, sendQueue <-chan mLog) {
} }
result, err := s.db.InsertMany(mongoTimeoutCtx(context.Background()), batchBson, nil) result, err := s.db.InsertMany(mongoTimeoutCtx(context.Background()), batchBson, nil)
promShipperDbSent.WithLabelValues(baseName).Add(float64(
len(result.InsertedIDs)))
if err != nil { if err != nil {
s.l.Error("submission to database", zap.Error(err)) // TODO: add some selective retry here or something s.l.Error("submission to database", zap.Error(err)) // TODO: add some selective retry here or something
continue
} }
promShipperDbSent.WithLabelValues(baseName).Add(float64(
len(result.InsertedIDs)))
} }
} }

View File

@ -184,11 +184,11 @@ var App = &cli.App{
_, ok = parseLogName(event.Name) _, ok = parseLogName(event.Name)
if !ok { if !ok {
promWatcherFilesSkipped.Add(1) promWatcherFilesSkipped.Add(1)
l.Warn("skipped file with unparsable name", zap.String("name", event.Name))
continue continue
} }
promWatcherFilesStarted.Add(1) promWatcherFilesStarted.Add(1)
l.Debug("digesting new file", zap.String("name", event.Name))
wg.Add(1) wg.Add(1)
go func() { go func() {