Skip to content

Commit

Permalink
fix(promtail): Fix UDP receiver on syslog transport (#10708)
Browse files Browse the repository at this point in the history
Co-authored-by: Callum Styan <[email protected]>
  • Loading branch information
joshuapare and cstyan authored Apr 22, 2024
1 parent 425a2d6 commit a00f1f1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ Starting with the 3.0 release we began using [conventional commits](https://www.

##### Fixes

* [10708](https://github.com/grafana/loki/pull/10708) **joshuapare**: Fix UDP receiver on syslog transport
* [10631](https://github.com/grafana/loki/pull/10631) **thampiotr**: Fix race condition in cleaning up metrics when stopping to tail files.
* [10798](https://github.com/grafana/loki/pull/10798) **hainenber**: Fix agent panicking after reloaded due to duplicate metric collector registration.
* [10848](https://github.com/grafana/loki/pull/10848) **rgroothuijsen**: Correctly parse list of drop stage sources from YAML.
Expand Down
33 changes: 25 additions & 8 deletions clients/pkg/promtail/targets/syslog/transport.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package syslog

import (
"bytes"
"context"
"crypto/tls"
"crypto/x509"
Expand Down Expand Up @@ -380,16 +381,32 @@ func (t *UDPTransport) handleRcv(c *ConnPipe) {
defer t.openConnections.Done()

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

for {
datagram := make([]byte, t.maxMessageLength())
n, err := c.Read(datagram)
if err != nil {
if err == io.EOF {
break
}

level.Warn(t.logger).Log("msg", "error reading from pipe", "err", err)
continue
}
}, t.maxMessageLength())

if err != nil {
level.Warn(t.logger).Log("msg", "error parsing syslog stream", "err", err)
r := bytes.NewReader(datagram[:n])

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

if err != nil {
level.Warn(t.logger).Log("msg", "error parsing syslog stream", "err", err)
}
}
}

Expand Down

0 comments on commit a00f1f1

Please sign in to comment.