Skip to content

Commit 8b2395a

Browse files
committed
Make proxy buffer size configurable
1 parent 9f871fc commit 8b2395a

File tree

5 files changed

+25
-12
lines changed

5 files changed

+25
-12
lines changed

docs/config-misc.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ sidebar_label: Misc
1313
**Optional**
1414

1515
- `hosts` A list of host strings that BuildBudy should connect and forward events to.
16+
- `buffer_size` The number of build events to buffer locally when proxying build events.
1617

1718
## Example section
1819

@@ -21,4 +22,5 @@ build_event_proxy:
2122
hosts:
2223
- "grpc://localhost:1985"
2324
- "grpc://events.buildbuddy.io:1985"
25+
buffer_size: 1000
2426
```

server/build_event_protocol/build_event_proxy/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ go_library(
77
visibility = ["//visibility:public"],
88
deps = [
99
"//proto:publish_build_event_go_proto",
10+
"//server/environment:go_default_library",
1011
"//server/util/grpc_client:go_default_library",
1112
"@io_bazel_rules_go//proto/wkt:empty_go_proto",
1213
"@org_golang_google_grpc//:go_default_library",

server/build_event_protocol/build_event_proxy/build_event_proxy.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ import (
55
"log"
66
"sync"
77

8+
"github.com/buildbuddy-io/buildbuddy/server/environment"
89
"github.com/buildbuddy-io/buildbuddy/server/util/grpc_client"
910
"github.com/golang/protobuf/ptypes/empty"
1011
"google.golang.org/grpc"
1112

1213
pepb "github.com/buildbuddy-io/buildbuddy/proto/publish_build_event"
1314
)
1415

15-
const eventBufferSize = 100
16-
1716
type BuildEventProxyClient struct {
18-
target string
19-
clientMux sync.Mutex // PROTECTS(client)
20-
client pepb.PublishBuildEventClient
21-
rootCtx context.Context
17+
target string
18+
clientMux sync.Mutex // PROTECTS(client)
19+
client pepb.PublishBuildEventClient
20+
rootCtx context.Context
21+
eventBufferSize int
2222
}
2323

2424
func (c *BuildEventProxyClient) reconnectIfNecessary() {
@@ -36,10 +36,15 @@ func (c *BuildEventProxyClient) reconnectIfNecessary() {
3636
c.client = pepb.NewPublishBuildEventClient(conn)
3737
}
3838

39-
func NewBuildEventProxyClient(target string) *BuildEventProxyClient {
39+
func NewBuildEventProxyClient(env environment.Env, target string) *BuildEventProxyClient {
40+
bufferSize := 100
41+
if configuredBufferSize := env.GetConfigurator().GetBuildEventProxyBufferSize(); configuredBufferSize != 0 {
42+
bufferSize = configuredBufferSize
43+
}
4044
c := &BuildEventProxyClient{
41-
target: target,
42-
rootCtx: context.Background(),
45+
target: target,
46+
rootCtx: context.Background(),
47+
eventBufferSize: bufferSize,
4348
}
4449
c.reconnectIfNecessary()
4550
return c
@@ -65,7 +70,7 @@ type asyncStreamProxy struct {
6570
func (c *BuildEventProxyClient) newAsyncStreamProxy(ctx context.Context, opts ...grpc.CallOption) *asyncStreamProxy {
6671
asp := &asyncStreamProxy{
6772
ctx: ctx,
68-
events: make(chan pepb.PublishBuildToolEventStreamRequest, eventBufferSize),
73+
events: make(chan pepb.PublishBuildToolEventStreamRequest, c.eventBufferSize),
6974
}
7075
// Start a goroutine that will open the stream and pass along events.
7176
go func() {

server/config/config.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ type appConfig struct {
4545
}
4646

4747
type buildEventProxy struct {
48-
Hosts []string `yaml:"hosts" usage:"The list of hosts to pass build events onto."`
48+
Hosts []string `yaml:"hosts" usage:"The list of hosts to pass build events onto."`
49+
BufferSize int `yaml:"buffer_size" usage:"The number of build events to buffer locally when proxying build events."`
4950
}
5051

5152
type DatabaseConfig struct {
@@ -379,6 +380,10 @@ func (c *Configurator) GetBuildEventProxyHosts() []string {
379380
return c.gc.BuildEventProxy.Hosts
380381
}
381382

383+
func (c *Configurator) GetBuildEventProxyBufferSize() int {
384+
return c.gc.BuildEventProxy.BufferSize
385+
}
386+
382387
func (c *Configurator) GetCacheMaxSizeBytes() int64 {
383388
return c.gc.Cache.MaxSizeBytes
384389
}

server/libmain/libmain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func GetConfiguredEnvironmentOrDie(configurator *config.Configurator, healthChec
119119
for _, target := range configurator.GetBuildEventProxyHosts() {
120120
// NB: This can block for up to a second on connecting. This would be a
121121
// great place to have our health checker and mark these as optional.
122-
buildEventProxyClients = append(buildEventProxyClients, build_event_proxy.NewBuildEventProxyClient(target))
122+
buildEventProxyClients = append(buildEventProxyClients, build_event_proxy.NewBuildEventProxyClient(realEnv, target))
123123
log.Printf("Proxy: forwarding build events to: %s", target)
124124
}
125125
realEnv.SetBuildEventProxyClients(buildEventProxyClients)

0 commit comments

Comments
 (0)