Skip to content

Commit 4743889

Browse files
Count number of corrupt lines + allow non-existent files to be… (letsencrypt#4631)
Fixes letsencrypt#4612.
1 parent f1894f8 commit 4743889

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

cmd/log-validator/main.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"strings"
1111

1212
"github.com/hpcloud/tail"
13+
"github.com/prometheus/client_golang/prometheus"
1314

1415
"github.com/letsencrypt/boulder/cmd"
1516
blog "github.com/letsencrypt/boulder/log"
@@ -83,21 +84,27 @@ func main() {
8384
}
8485

8586
var config struct {
86-
Syslog cmd.SyslogConfig
87-
Files []string
87+
Syslog cmd.SyslogConfig
88+
DebugAddr string
89+
Files []string
8890
}
8991
configBytes, err := ioutil.ReadFile(*configPath)
9092
cmd.FailOnError(err, "failed to read config file")
9193
err = json.Unmarshal(configBytes, &config)
9294
cmd.FailOnError(err, "failed to parse config file")
9395

94-
logger := cmd.NewLogger(config.Syslog)
96+
stats, logger := cmd.StatsAndLogging(config.Syslog, config.DebugAddr)
97+
badLineCounter := prometheus.NewCounterVec(prometheus.CounterOpts{
98+
Name: "bad_log_lines",
99+
Help: "A counter of corrupt log lines",
100+
}, []string{"filename"})
101+
stats.MustRegister(badLineCounter)
95102

96103
var tailers []*tail.Tail
97104
for _, filename := range config.Files {
98105
t, err := tail.TailFile(filename, tail.Config{
99106
ReOpen: true,
100-
MustExist: true,
107+
MustExist: false, // sometimes files won't exist, so we must tolerate that
101108
Follow: true,
102109
})
103110
cmd.FailOnError(err, "failed to tail file")
@@ -110,6 +117,7 @@ func main() {
110117
continue
111118
}
112119
if err := lineValid(line.Text); err != nil {
120+
badLineCounter.WithLabelValues(t.Filename).Inc()
113121
logger.Errf("%s: %s %q", t.Filename, err, line.Text)
114122
}
115123
}

0 commit comments

Comments
 (0)