File tree Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -74,15 +74,35 @@ type Converter struct {
74
74
logger * zap.Logger
75
75
}
76
76
77
- func NewConverter (logger * zap.Logger ) * Converter {
78
- return & Converter {
77
+ type converterOption interface {
78
+ apply (* Converter )
79
+ }
80
+
81
+ func withWorkerCount (workerCount int ) converterOption {
82
+ return workerCountOption {workerCount }
83
+ }
84
+
85
+ type workerCountOption struct {
86
+ workerCount int
87
+ }
88
+
89
+ func (o workerCountOption ) apply (c * Converter ) {
90
+ c .workerCount = o .workerCount
91
+ }
92
+
93
+ func NewConverter (logger * zap.Logger , opts ... converterOption ) * Converter {
94
+ c := & Converter {
79
95
workerChan : make (chan []* entry.Entry ),
80
96
workerCount : int (math .Max (1 , float64 (runtime .NumCPU ()/ 4 ))),
81
97
pLogsChan : make (chan plog.Logs ),
82
98
stopChan : make (chan struct {}),
83
99
flushChan : make (chan plog.Logs ),
84
100
logger : logger ,
85
101
}
102
+ for _ , opt := range opts {
103
+ opt .apply (c )
104
+ }
105
+ return c
86
106
}
87
107
88
108
func (c * Converter ) Start () {
Original file line number Diff line number Diff line change @@ -822,12 +822,11 @@ func BenchmarkConverter(b *testing.B) {
822
822
b .Run (fmt .Sprintf ("worker_count=%d" , wc ), func (b * testing.B ) {
823
823
for i := 0 ; i < b .N ; i ++ {
824
824
825
- converter := NewConverter (zap .NewNop ())
825
+ converter := NewConverter (zap .NewNop (), withWorkerCount ( wc ) )
826
826
converter .Start ()
827
827
defer converter .Stop ()
828
828
829
829
b .ReportAllocs ()
830
- b .ResetTimer ()
831
830
832
831
go func () {
833
832
for from := 0 ; from < entryCount ; from += int (batchSize ) {
You can’t perform that action at this time.
0 commit comments