Skip to content

Commit

Permalink
Use TailIterator in forwarder
Browse files Browse the repository at this point in the history
This fixes a weird bug where the iterator couldn't access logs that were
written before it was created.
  • Loading branch information
barrettj12 committed Jul 4, 2023
1 parent c8cbae5 commit 8ecdd8d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internals/overlord/logstate/forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func newLogForwarder(serviceName string) *logForwarder {
}

func (f *logForwarder) forward(buffer *servicelog.RingBuffer) {
iterator := buffer.HeadIterator(0)
iterator := buffer.TailIterator()
// TODO: don't use the parser, just pull/write bytes from iterator
parser := servicelog.NewParser(iterator, 1024 /* TODO*/)

Expand Down
6 changes: 4 additions & 2 deletions internals/overlord/logstate/forwarder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ func (s *forwarderSuite) TestForwarder(c *C) {

recv1, recv2 := make(chan []servicelog.Entry), make(chan []servicelog.Entry)
gatherer1 := newLogGathererForTest(nil, 1*time.Microsecond, 5, recv1)
go gatherer1.loop()
gatherer2 := newLogGathererForTest(nil, 1*time.Microsecond, 5, recv2)
go gatherer2.loop()

forwarder := newLogForwarder(serviceName)
go forwarder.forward(ringBuffer)
Expand All @@ -50,7 +52,7 @@ func (s *forwarderSuite) TestForwarder(c *C) {
case entries := <-recv1:
c.Assert(entries, HasLen, 1)
c.Check(entries[0].Service, Equals, serviceName)
c.Check(entries[0].Message, Equals, message)
c.Check(entries[0].Message, Equals, message+"\n")
case <-time.After(10 * time.Millisecond):
c.Fatal("timeout waiting to receive logs from gatherer1")
}
Expand All @@ -59,7 +61,7 @@ func (s *forwarderSuite) TestForwarder(c *C) {
case entries := <-recv2:
c.Assert(entries, HasLen, 1)
c.Check(entries[0].Service, Equals, serviceName)
c.Check(entries[0].Message, Equals, message)
c.Check(entries[0].Message, Equals, message+"\n")
case <-time.After(10 * time.Millisecond):
c.Fatal("timeout waiting to receive logs from gatherer2")
}
Expand Down

0 comments on commit 8ecdd8d

Please sign in to comment.