Skip to content

Commit

Permalink
fix(logging): Set default value for BundleByteLimit to 9.5 MiB to avo…
Browse files Browse the repository at this point in the history
…id payload size limits. (#9662)

* fix(logging): Set default value for BundleByteLimit to 9.5 MiB to avoid payload size limits.

* Fixed DefaultBundleByteLimit comment
  • Loading branch information
gkevinzheng authored Mar 28, 2024
1 parent 8264a96 commit d5815da
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
4 changes: 4 additions & 0 deletions logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ const (
// DefaultEntryByteThreshold is the default value for the EntryByteThreshold LoggerOption.
DefaultEntryByteThreshold = 1 << 23 // 8MiB

// DefaultBundleByteLimit is the default value for the BundleByteLimit LoggerOption.
DefaultBundleByteLimit = 9437184 // 9.5 MiB

// DefaultBufferedByteLimit is the default value for the BufferedByteLimit LoggerOption.
DefaultBufferedByteLimit = 1 << 30 // 1GiB

Expand Down Expand Up @@ -340,6 +343,7 @@ func (c *Client) Logger(logID string, opts ...LoggerOption) *Logger {
l.bundler.DelayThreshold = DefaultDelayThreshold
l.bundler.BundleCountThreshold = DefaultEntryCountThreshold
l.bundler.BundleByteThreshold = DefaultEntryByteThreshold
l.bundler.BundleByteLimit = DefaultBundleByteLimit
l.bundler.BufferedByteLimit = DefaultBufferedByteLimit
for _, opt := range opts {
opt.set(l)
Expand Down
28 changes: 26 additions & 2 deletions logging/logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1360,14 +1360,14 @@ func (f *writeLogEntriesTestHandler) WriteLogEntries(_ context.Context, e *logpb
return &logpb.WriteLogEntriesResponse{}, nil
}

func fakeClient(parent string, writeLogEntryHandler func(e *logpb.WriteLogEntriesRequest)) (*logging.Client, error) {
func fakeClient(parent string, writeLogEntryHandler func(e *logpb.WriteLogEntriesRequest), serverOptions ...grpc.ServerOption) (*logging.Client, error) {
// setup fake server
fakeBackend := &writeLogEntriesTestHandler{}
l, err := net.Listen("tcp", "localhost:0")
if err != nil {
return nil, err
}
gsrv := grpc.NewServer()
gsrv := grpc.NewServer(serverOptions...)
logpb.RegisterLoggingServiceV2Server(gsrv, fakeBackend)
fakeServerAddr := l.Addr().String()
go func() {
Expand Down Expand Up @@ -1428,6 +1428,30 @@ func TestPartialSuccessOption(t *testing.T) {
}
}

func TestWriteLogEntriesSizeLimit(t *testing.T) {
// Test that logging too many large requests at once doesn't bump up
// against WriteLogEntriesRequest size limit
sizeLimit := 10485760 // 10MiB size limit

// Create a fake client whose server can only handle messages of at most sizeLimit
client, err := fakeClient("projects/test", func(e *logpb.WriteLogEntriesRequest) {}, grpc.MaxRecvMsgSize(sizeLimit))
if err != nil {
t.Fatal(err)
}

client.OnError = func(e error) {
t.Fatalf(e.Error())
}

defer client.Close()
logger := client.Logger("test")
entry := logging.Entry{Payload: strings.Repeat("1", 250000)}

for i := 0; i < 200; i++ {
logger.Log(entry)
}
}

func TestRedirectOutputIngestion(t *testing.T) {
var hookCalled bool

Expand Down
2 changes: 1 addition & 1 deletion logging/logging_unexported_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestLoggerCreation(t *testing.T) {
DelayThreshold: DefaultDelayThreshold,
BundleCountThreshold: DefaultEntryCountThreshold,
BundleByteThreshold: DefaultEntryByteThreshold,
BundleByteLimit: 0,
BundleByteLimit: DefaultBundleByteLimit,
BufferedByteLimit: DefaultBufferedByteLimit,
}
for _, test := range []struct {
Expand Down

0 comments on commit d5815da

Please sign in to comment.