99 "strconv"
1010 "strings"
1111 "sync"
12+ "sync/atomic"
1213 "time"
1314
1415 backendconfig "github.com/rudderlabs/rudder-server/backend-config"
@@ -21,6 +22,7 @@ import (
2122 "github.com/samber/lo"
2223
2324 "github.com/rudderlabs/rudder-go-kit/config"
25+ "github.com/rudderlabs/rudder-go-kit/filemanager"
2426 "github.com/rudderlabs/rudder-go-kit/logger"
2527 "github.com/rudderlabs/rudder-go-kit/stats"
2628
@@ -72,15 +74,18 @@ func New(conf *config.Config, log logger.Logger, stat stats.Stats, opts ...Opt)
7274 handle .config .maxRetryBackoffInterval = conf .GetReloadableDurationVar (30 , time .Second , "Processor.DestinationTransformer.maxRetryBackoffInterval" , "Processor.maxRetryBackoffInterval" )
7375 handle .config .batchSize = conf .GetReloadableIntVar (100 , 1 , "Processor.DestinationTransformer.batchSize" , "Processor.transformBatchSize" )
7476
75- handle .config .maxLoggedEvents = conf .GetReloadableIntVar (10000 , 1 , "Processor.DestinationTransformer.maxLoggedEvents" )
77+ handle .config .maxLoggedEvents = conf .GetReloadableIntVar (100 , 1 , "Processor.DestinationTransformer.maxLoggedEvents" )
7678
7779 handle .stats .comparisonTime = handle .stat .NewStat ("embedded_destination_transform_comparison_time" , stats .TimerType )
7880 handle .stats .matchedEvents = handle .stat .NewStat ("embedded_destination_transform_matched_events" , stats .CountType )
7981 handle .stats .mismatchedEvents = handle .stat .NewStat ("embedded_destination_transform_mismatched_events" , stats .CountType )
8082
81- handle .loggedEvents = 0
82- handle .loggedEventsMu = sync.Mutex {}
83- handle .loggedFileName = generateLogFileName ()
83+ var err error
84+ handle .samplingFileManager , err = getSamplingUploader (conf , log )
85+ if err != nil {
86+ log .Errorn ("failed to create dt sampling file manager" , obskit .Error (err ))
87+ handle .samplingFileManager = nil
88+ }
8489
8590 handle .config .compactionEnabled = conf .GetReloadableBoolVar (false , "Processor.DestinationTransformer.compactionEnabled" , "Transformer.compactionEnabled" )
8691
@@ -116,9 +121,8 @@ type Client struct {
116121 mismatchedEvents stats.Counter
117122 }
118123
119- loggedEventsMu sync.Mutex
120- loggedEvents int64
121- loggedFileName string
124+ loggedEvents atomic.Int64
125+ samplingFileManager * filemanager.S3Manager
122126}
123127
124128func (d * Client ) transform (ctx context.Context , clientEvents []types.TransformerEvent ) types.Response {
@@ -391,7 +395,9 @@ func (c *Client) Transform(ctx context.Context, clientEvents []types.Transformer
391395 legacyTransformerResponse := c .transform (ctx , clientEvents )
392396 embeddedTransformerResponse := impl (ctx , clientEvents )
393397
394- c .CompareAndLog (embeddedTransformerResponse , legacyTransformerResponse )
398+ go func () {
399+ c .CompareAndLog (ctx , embeddedTransformerResponse , legacyTransformerResponse )
400+ }()
395401
396402 return legacyTransformerResponse
397403 }
@@ -429,3 +435,32 @@ func (d *Client) getRequestPayload(data []types.TransformerEvent, compactRequest
429435 }
430436 return jsonrs .Marshal (data )
431437}
438+
439+ func getSamplingUploader (conf * config.Config , log logger.Logger ) (* filemanager.S3Manager , error ) {
440+ var (
441+ bucket = conf .GetString ("DTSampling.Bucket" , "processor-dt-sampling" )
442+ endpoint = conf .GetString ("DTSampling.Endpoint" , "" )
443+ accessKeyID = conf .GetStringVar ("" , "DTSampling.AccessKeyId" , "AWS_ACCESS_KEY_ID" )
444+ accessKey = conf .GetStringVar ("" , "DTSampling.AccessKey" , "AWS_SECRET_ACCESS_KEY" )
445+ s3ForcePathStyle = conf .GetBool ("DTSampling.S3ForcePathStyle" , false )
446+ disableSSL = conf .GetBool ("DTSampling.DisableSsl" , false )
447+ enableSSE = conf .GetBoolVar (false , "DTSampling.EnableSse" , "AWS_ENABLE_SSE" )
448+ useGlue = conf .GetBool ("DTSampling.UseGlue" , false )
449+ region = conf .GetStringVar ("us-east-1" , "DTSampling.Region" , "AWS_DEFAULT_REGION" )
450+ )
451+ s3Config := map [string ]any {
452+ "bucketName" : bucket ,
453+ "endpoint" : endpoint ,
454+ "accessKeyID" : accessKeyID ,
455+ "accessKey" : accessKey ,
456+ "s3ForcePathStyle" : s3ForcePathStyle ,
457+ "disableSSL" : disableSSL ,
458+ "enableSSE" : enableSSE ,
459+ "useGlue" : useGlue ,
460+ "region" : region ,
461+ }
462+
463+ return filemanager .NewS3Manager (s3Config , log .Withn (logger .NewStringField ("component" , "dt-uploader" )), func () time.Duration {
464+ return conf .GetDuration ("DTSampling.Timeout" , 120 , time .Second )
465+ })
466+ }
0 commit comments