Skip to content

Commit

Permalink
Calculate document size correctly and don't skip to write some useful…
Browse files Browse the repository at this point in the history
… data (#165)

Fixes #154
  • Loading branch information
furkansenharputlu authored and buger committed Nov 5, 2019
1 parent c0cf0fb commit 8bfdb36
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions pumps/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ package pumps

import (
"crypto/tls"
"net"
"strconv"
"strings"
"time"

"encoding/base64"
"github.com/TykTechnologies/logrus"
"github.com/TykTechnologies/tyk-pump/analytics"
"github.com/kelseyhightower/envconfig"
"github.com/mitchellh/mapstructure"
"gopkg.in/mgo.v2"
"gopkg.in/vmihailenco/msgpack.v2"

"github.com/TykTechnologies/logrus"
"github.com/TykTechnologies/tyk-pump/analytics"
"net"
"strconv"
"strings"
"time"
)

const (
Expand Down Expand Up @@ -327,15 +326,19 @@ func (m *MongoPump) AccumulateSet(data []interface{}) [][]interface{} {
if thisItem.ResponseCode == -1 {
continue
}
sizeBytes := len([]byte(thisItem.RawRequest)) + len([]byte(thisItem.RawRequest))

// Add 1 KB for metadata as average
sizeBytes := len(thisItem.RawRequest) + len(thisItem.RawResponse) + 1024

log.Debug("Size is: ", sizeBytes)

if sizeBytes > m.dbConf.MaxDocumentSizeBytes {
log.WithFields(logrus.Fields{
"prefix": mongoPrefix,
}).Warning("Document too large, skipping!")
continue
}).Warning("Document too large, not writing raw request and raw response!")

thisItem.RawRequest = ""
thisItem.RawResponse = base64.StdEncoding.EncodeToString([]byte("Document too large, not writing raw request and raw response!"))
}

if (accumulatorTotal + sizeBytes) < m.dbConf.MaxInsertBatchSizeBytes {
Expand Down

0 comments on commit 8bfdb36

Please sign in to comment.