Skip to content

Commit d5815da

Browse files
authored
fix(logging): Set default value for BundleByteLimit to 9.5 MiB to avoid payload size limits. (#9662)
* fix(logging): Set default value for BundleByteLimit to 9.5 MiB to avoid payload size limits. * Fixed DefaultBundleByteLimit comment
1 parent 8264a96 commit d5815da

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

logging/logging.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ const (
8484
// DefaultEntryByteThreshold is the default value for the EntryByteThreshold LoggerOption.
8585
DefaultEntryByteThreshold = 1 << 23 // 8MiB
8686

87+
// DefaultBundleByteLimit is the default value for the BundleByteLimit LoggerOption.
88+
DefaultBundleByteLimit = 9437184 // 9.5 MiB
89+
8790
// DefaultBufferedByteLimit is the default value for the BufferedByteLimit LoggerOption.
8891
DefaultBufferedByteLimit = 1 << 30 // 1GiB
8992

@@ -340,6 +343,7 @@ func (c *Client) Logger(logID string, opts ...LoggerOption) *Logger {
340343
l.bundler.DelayThreshold = DefaultDelayThreshold
341344
l.bundler.BundleCountThreshold = DefaultEntryCountThreshold
342345
l.bundler.BundleByteThreshold = DefaultEntryByteThreshold
346+
l.bundler.BundleByteLimit = DefaultBundleByteLimit
343347
l.bundler.BufferedByteLimit = DefaultBufferedByteLimit
344348
for _, opt := range opts {
345349
opt.set(l)

logging/logging_test.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,14 +1360,14 @@ func (f *writeLogEntriesTestHandler) WriteLogEntries(_ context.Context, e *logpb
13601360
return &logpb.WriteLogEntriesResponse{}, nil
13611361
}
13621362

1363-
func fakeClient(parent string, writeLogEntryHandler func(e *logpb.WriteLogEntriesRequest)) (*logging.Client, error) {
1363+
func fakeClient(parent string, writeLogEntryHandler func(e *logpb.WriteLogEntriesRequest), serverOptions ...grpc.ServerOption) (*logging.Client, error) {
13641364
// setup fake server
13651365
fakeBackend := &writeLogEntriesTestHandler{}
13661366
l, err := net.Listen("tcp", "localhost:0")
13671367
if err != nil {
13681368
return nil, err
13691369
}
1370-
gsrv := grpc.NewServer()
1370+
gsrv := grpc.NewServer(serverOptions...)
13711371
logpb.RegisterLoggingServiceV2Server(gsrv, fakeBackend)
13721372
fakeServerAddr := l.Addr().String()
13731373
go func() {
@@ -1428,6 +1428,30 @@ func TestPartialSuccessOption(t *testing.T) {
14281428
}
14291429
}
14301430

1431+
func TestWriteLogEntriesSizeLimit(t *testing.T) {
1432+
// Test that logging too many large requests at once doesn't bump up
1433+
// against WriteLogEntriesRequest size limit
1434+
sizeLimit := 10485760 // 10MiB size limit
1435+
1436+
// Create a fake client whose server can only handle messages of at most sizeLimit
1437+
client, err := fakeClient("projects/test", func(e *logpb.WriteLogEntriesRequest) {}, grpc.MaxRecvMsgSize(sizeLimit))
1438+
if err != nil {
1439+
t.Fatal(err)
1440+
}
1441+
1442+
client.OnError = func(e error) {
1443+
t.Fatalf(e.Error())
1444+
}
1445+
1446+
defer client.Close()
1447+
logger := client.Logger("test")
1448+
entry := logging.Entry{Payload: strings.Repeat("1", 250000)}
1449+
1450+
for i := 0; i < 200; i++ {
1451+
logger.Log(entry)
1452+
}
1453+
}
1454+
14311455
func TestRedirectOutputIngestion(t *testing.T) {
14321456
var hookCalled bool
14331457

logging/logging_unexported_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func TestLoggerCreation(t *testing.T) {
8282
DelayThreshold: DefaultDelayThreshold,
8383
BundleCountThreshold: DefaultEntryCountThreshold,
8484
BundleByteThreshold: DefaultEntryByteThreshold,
85-
BundleByteLimit: 0,
85+
BundleByteLimit: DefaultBundleByteLimit,
8686
BufferedByteLimit: DefaultBufferedByteLimit,
8787
}
8888
for _, test := range []struct {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy