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

fixed reader logic to support chunked messages #2

Merged
merged 5 commits into from
Apr 21, 2022

Conversation

vlad-diachenko
Copy link

@vlad-diachenko vlad-diachenko commented Apr 15, 2022

Fixed reader logic to support the case when between chunks of one message the reader receives the chunks from another message or not chunked message.
more info grafana/loki#5644

Notes for Reviewers

  • The commit history must be preserved - please use the rebase-merge or standard merge option instead of squash-merge
  • Sync up with the author before merging

Signed-off-by: Vladyslav Diachenko <vlad.diachenko@grafana.com>
Copy link

@simonswine simonswine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this. I have put a couple of thoughts together testing/reading to your code.

In general I feel you would need to add a couple more comments to make sure the code is easily understood/read at a later point. So for example make it clear that the 128 fragment limit is coming from the protocol itself: https://docs.graylog.org/docs/gelf

I also think there are a couple of edge cases that we need to cover, as pretty much anything can happen to UDP packets on the network. I would also love to see cases with modified data covered by the tests.

Nit: I also wonder if "assembler" is the best name, I think "defragmentation" is quite common thinking about networking protocols.

gelf/udpwriter.go Outdated Show resolved Hide resolved
gelf/udpwriter.go Outdated Show resolved Hide resolved
gelf/assembler.go Outdated Show resolved Hide resolved
gelf/assembler.go Outdated Show resolved Hide resolved
gelf/assembler.go Outdated Show resolved Hide resolved
gelf/assembler.go Outdated Show resolved Hide resolved
gelf/reader.go Outdated Show resolved Hide resolved
gelf/reader.go Show resolved Hide resolved
gelf/reader.go Show resolved Hide resolved
gelf/reader_test.go Show resolved Hide resolved
Signed-off-by: Vladyslav Diachenko <vlad.diachenko@grafana.com>
Copy link

@simonswine simonswine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for incorporating my feedback. I think there are only minor things now. See my suggestions inline.

I think it's also worth running golangci-lint. As those look all relevant:

gelf/reader_test.go:185:8: ineffectual assignment to err (ineffassign)
        conn, err := net.DialUDP("udp", nil, addr)
              ^
gelf/reader_test.go:74:4: SA5001: should check returned error before deferring conn.Close() (staticcheck)
                        defer conn.Close()
                        ^
gelf/reader_test.go:186:2: SA5001: should check returned error before deferring conn.Close() (staticcheck)
        defer conn.Close()
        ^
gelf/reader.go:91:2: SA4006: this value of `cBuf` is never used (staticcheck)
        cBuf := make([]byte, ChunkSize)

go.mod Outdated Show resolved Hide resolved
gelf/reader.go Outdated Show resolved Hide resolved
gelf/udpwriter.go Outdated Show resolved Hide resolved
gelf/reader_test.go Outdated Show resolved Hide resolved
gelf/reader.go Show resolved Hide resolved
gelf/reader_test.go Outdated Show resolved Hide resolved
gelf/reader_test.go Show resolved Hide resolved
@vlad-diachenko
Copy link
Author

Yep, thanks. I have fixed all issues in reader and reader_test files.
The rest of the issues are not related to this PR. I decided to not fix it here to not add redundant changes to this RP.

 golangci-lint run
gelf/tcpreader.go:115:19: Error return value of `conn.SetDeadline` is not checked (errcheck)
                conn.SetDeadline(time.Now().Add(2 * time.Second))
                                ^
gelf/udpwriter_test.go:244:12: Error return value of `io.Copy` is not checked (errcheck)
        go io.Copy(ioutil.Discard, r)
                  ^
gelf/udpwriter_test.go:252:17: Error return value of `w.WriteMessage` is not checked (errcheck)
                w.WriteMessage(&Message{
                              ^
gelf/udpwriter_test.go:270:12: Error return value of `io.Copy` is not checked (errcheck)
        go io.Copy(ioutil.Discard, r)
                  ^
gelf/udpwriter_test.go:278:17: Error return value of `w.WriteMessage` is not checked (errcheck)
                w.WriteMessage(&Message{
                              ^
gelf/udpwriter_test.go:296:12: Error return value of `io.Copy` is not checked (errcheck)
        go io.Copy(ioutil.Discard, r)
                  ^
gelf/udpwriter_test.go:304:17: Error return value of `w.WriteMessage` is not checked (errcheck)
                w.WriteMessage(&Message{
                              ^
gelf/writer.go:21:2: `addr` is unused (structcheck)
        addr     string
        ^
gelf/writer.go:23:2: `hostname` is unused (structcheck)
        hostname string
        ^
gelf/writer.go:25:2: `proto` is unused (structcheck)
        proto    string
        ^
gelf/tcpreader.go:13:2: `conn` is unused (structcheck)
        conn     net.Conn
        ^

Signed-off-by: Vladyslav Diachenko <vlad.diachenko@grafana.com>
gelf/reader_test.go Outdated Show resolved Hide resolved
@simonswine
Copy link

Yep, thanks. I have fixed all issues in reader and reader_test files. The rest of the issues are not related to this PR. I decided to not fix it here to not add redundant changes to this RP.

Yes do not worry about pre-existing linting issues 🙂

Signed-off-by: Vladyslav Diachenko <vlad.diachenko@grafana.com>
Signed-off-by: Vladyslav Diachenko <vlad.diachenko@grafana.com>
Copy link

@simonswine simonswine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one. Thanks for addressing my suggestions so patiently 🙂

LGTM 🚀

@vlad-diachenko vlad-diachenko merged commit 1cbd636 into v2 Apr 21, 2022
@vlad-diachenko vlad-diachenko deleted the changed_reader_behavior branch April 21, 2022 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants