implement Simulate and globalize BufferLimit
This commit is contained in:
@@ -2,6 +2,7 @@ package sender
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
@@ -56,13 +57,7 @@ func (queue Queue) Sender(db *mongo.Collection, metricsFilename string, cancelOn
|
||||
|
||||
promShipperSynced.WithLabelValues(metricsFilename).Set(0)
|
||||
|
||||
var batchBson []interface{} // mongo does not like typing
|
||||
for _, b := range batch {
|
||||
batchBson = append(batchBson, b.ToBson())
|
||||
}
|
||||
|
||||
tru := true
|
||||
result, err := db.InsertMany(globals.MongoTimeout(context.Background()), batchBson, &options.InsertManyOptions{Ordered: &tru})
|
||||
result, err := insertManyWithSimulate(db, batch)
|
||||
|
||||
var succeedCount int
|
||||
if result != nil {
|
||||
@@ -89,3 +84,24 @@ func (queue Queue) Sender(db *mongo.Collection, metricsFilename string, cancelOn
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func insertManyWithSimulate(db *mongo.Collection, batch []m.Record) (*mongo.InsertManyResult, error) {
|
||||
if !globals.Simulate {
|
||||
var batchBson []interface{} // mongo does not like typing
|
||||
for _, b := range batch {
|
||||
batchBson = append(batchBson, b.ToBson())
|
||||
}
|
||||
|
||||
tru := true
|
||||
return db.InsertMany(globals.MongoTimeout(context.Background()), batchBson, &options.InsertManyOptions{Ordered: &tru})
|
||||
}
|
||||
|
||||
fmt.Printf("simulating successful database bulk write: %v", batch)
|
||||
|
||||
var res mongo.InsertManyResult
|
||||
for range batch {
|
||||
res.InsertedIDs = append(res.InsertedIDs, nil)
|
||||
}
|
||||
|
||||
return &res, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user