Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flow: syslog: use best-effort, partially parsed message #5747

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,17 @@ func NewSyslogTarget(
return t, nil
}

func (t *SyslogTarget) handleMessageError(err error) {
func (t *SyslogTarget) handleMessageError(err error, partialMessage syslog.Message, connLabels labels.Labels) {
var ne net.Error
if errors.As(err, &ne) && ne.Timeout() {
level.Debug(t.logger).Log("msg", "connection timed out", "err", ne)
return
}
if partialMessage != nil {
level.Debug(t.logger).Log("msg", "best-effort recovered error parsing syslog stream", "err", err, "msg", partialMessage)
t.handleMessage(connLabels, partialMessage)
return
}
level.Warn(t.logger).Log("msg", "error parsing syslog stream", "err", err)
t.metrics.syslogParsingErrors.Inc()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type Transport interface {
}

type handleMessage func(labels.Labels, syslog.Message)
type handleMessageError func(error)
type handleMessageError func(error, syslog.Message, labels.Labels)

type baseTransport struct {
config *scrapeconfig.SyslogTargetConfig
Expand Down Expand Up @@ -324,7 +324,7 @@ func (t *TCPTransport) handleConnection(cn net.Conn) {

err := syslogparser.ParseStream(c, func(result *syslog.Result) {
if err := result.Error; err != nil {
t.handleMessageError(err)
t.handleMessageError(err, result.Message, lbs.Copy())
return
}
t.handleMessage(lbs.Copy(), result.Message)
Expand Down Expand Up @@ -448,7 +448,7 @@ func (t *UDPTransport) handleRcv(c *ConnPipe) {

err = syslogparser.ParseStream(r, func(result *syslog.Result) {
if err := result.Error; err != nil {
t.handleMessageError(err)
t.handleMessageError(err, result.Message, lbs.Copy())
} else {
t.handleMessage(lbs.Copy(), result.Message)
}
Expand Down