Skip to content

Commit

Permalink
app: enable configuring logs queue size
Browse files Browse the repository at this point in the history
  • Loading branch information
andrestc committed Dec 7, 2018
1 parent 687c901 commit b017fbf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/globalsign/mgo/bson"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/tsuru/config"
"github.com/tsuru/tsuru/api/shutdown"
"github.com/tsuru/tsuru/db"
"github.com/tsuru/tsuru/log"
Expand Down Expand Up @@ -334,12 +335,16 @@ type bulkProcessor struct {
}

func initBulkProcessor(maxWait time.Duration, bulkSize int, appName string) *bulkProcessor {
queueSize, err := config.GetInt("logs:queue-size")
if err != nil || queueSize == 0 {
queueSize = bulkQueueMaxSize
}
return &bulkProcessor{
appName: appName,
maxWaitTime: maxWait,
bulkSize: bulkSize,
finished: make(chan struct{}),
ch: make(chan *msgWithTS, bulkQueueMaxSize),
ch: make(chan *msgWithTS, queueSize),
nextNotify: time.NewTimer(0),
}
}
Expand Down
12 changes: 12 additions & 0 deletions app/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,15 @@ loop:
}
dispatcher.Shutdown(context.Background())
}

func (s *S) TestBulkProcessorQueueSizeDefault(c *check.C) {
processor := initBulkProcessor(time.Second, 100, "")
c.Assert(cap(processor.ch), check.Equals, bulkQueueMaxSize)
}

func (s *S) TestBulkProcessorCustomQueueSize(c *check.C) {
config.Set("logs:queue-size", 10)
defer config.Unset("logs:queue-size")
processor := initBulkProcessor(time.Second, 100, "")
c.Assert(cap(processor.ch), check.Equals, 10)
}

0 comments on commit b017fbf

Please sign in to comment.