-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make the scanner's buffer be 1MiB, to support longer lines
closes #53
- Loading branch information
Showing
58 changed files
with
23,047 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package bufsink | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/humanlogio/humanlog/internal/pkg/model" | ||
"github.com/humanlogio/humanlog/internal/pkg/sink" | ||
) | ||
|
||
type SizedBuffer struct { | ||
Buffered []model.Event | ||
flush sink.BatchSink | ||
} | ||
|
||
var _ sink.Sink = (*SizedBuffer)(nil) | ||
|
||
func NewSizedBufferedSink(size int, flush sink.BatchSink) *SizedBuffer { | ||
return &SizedBuffer{ | ||
Buffered: make([]model.Event, 0, size), | ||
flush: flush, | ||
} | ||
} | ||
|
||
func (sn *SizedBuffer) Receive(ctx context.Context, ev *model.Event) error { | ||
sn.Buffered = append(sn.Buffered, *ev) | ||
if len(sn.Buffered) == cap(sn.Buffered) { | ||
if err := sn.flush.ReceiveBatch(ctx, sn.Buffered); err != nil { | ||
sn.Buffered = sn.Buffered[:len(sn.Buffered)-1] | ||
return err | ||
} | ||
sn.Buffered = sn.Buffered[:0] | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
package sink | ||
|
||
import "github.com/humanlogio/humanlog/internal/pkg/model" | ||
import ( | ||
"context" | ||
|
||
"github.com/humanlogio/humanlog/internal/pkg/model" | ||
) | ||
|
||
type Sink interface { | ||
Receive(*model.Event) error | ||
Receive(ctx context.Context, ev *model.Event) error | ||
} | ||
|
||
type BatchSink interface { | ||
ReceiveBatch(ctx context.Context, evs []model.Event) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package humanlog | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/humanlogio/humanlog/internal/pkg/model" | ||
"github.com/humanlogio/humanlog/internal/pkg/sink/bufsink" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestScannerLongLine(t *testing.T) { | ||
data := `{"msg":"` + strings.Repeat("a", 1023*1024) + `"}` | ||
ctx := context.Background() | ||
src := strings.NewReader(data) | ||
want := []model.Event{ | ||
{Raw: []byte(data), Structured: &model.Structured{Msg: strings.Repeat("a", 1023*1024)}}, | ||
} | ||
sink := bufsink.NewSizedBufferedSink(100, nil) | ||
err := Scan(ctx, src, sink, DefaultOptions) | ||
require.NoError(t, err, "got %#v", err) | ||
require.Equal(t, want, sink.Buffered) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.