diff --git a/endpoints/openrtb2/auction_ow.go b/endpoints/openrtb2/auction_ow.go index f9678dfeda0..ce91e1ec5d3 100644 --- a/endpoints/openrtb2/auction_ow.go +++ b/endpoints/openrtb2/auction_ow.go @@ -60,7 +60,7 @@ func UpdateResponseExtOW(bidResponse *openrtb2.BidResponse, ao analytics.Auction } } - if rCtx.LogInfoFlag == 1 { + if rCtx.LogInfoFlag == 1 && !rCtx.LoggerDisabled { extBidResponse.OwLogInfo.Logger, _ = pubmatic.GetLogAuctionObjectAsURL(ao, rCtx, true, true) } @@ -72,7 +72,7 @@ func UpdateResponseExtOW(bidResponse *openrtb2.BidResponse, ao analytics.Auction // extBidResponse.Prebid.SeatNonBid = seatNonBids // } - if rCtx.Debug { + if rCtx.Debug && !rCtx.LoggerDisabled { extBidResponse.OwLogger, _ = pubmatic.GetLogAuctionObjectAsURL(ao, rCtx, false, true) } diff --git a/modules/pubmatic/openwrap/beforevalidationhook.go b/modules/pubmatic/openwrap/beforevalidationhook.go index 5cadcb6e8d0..095850b2e50 100644 --- a/modules/pubmatic/openwrap/beforevalidationhook.go +++ b/modules/pubmatic/openwrap/beforevalidationhook.go @@ -105,6 +105,7 @@ func (m OpenWrap) handleBeforeValidationHook( rCtx.NewReqExt = requestExt rCtx.CustomDimensions = customdimensions.GetCustomDimensions(requestExt.Prebid.BidderParams) rCtx.ReturnAllBidStatus = requestExt.Prebid.ReturnAllBidStatus + m.setAnanlyticsFlags(&rCtx) // TODO: verify preference of request.test vs queryParam test ++ this check is only for the CTV requests if payload.BidRequest.Test != 0 { @@ -931,6 +932,18 @@ func getTagID(imp openrtb2.Imp, impExt *models.ImpExtension) string { return impExt.Data.PbAdslot } +func (m OpenWrap) setAnanlyticsFlags(rCtx *models.RequestCtx) { + rCtx.LoggerDisabled, rCtx.TrackerDisabled = m.pubFeatures.IsAnalyticsTrackingThrottled(rCtx.PubID, rCtx.ProfileID) + + if rCtx.LoggerDisabled { + rCtx.MetricsEngine.RecordAnalyticsTrackingThrottled(strconv.Itoa(rCtx.PubID), strconv.Itoa(rCtx.ProfileID), models.AnanlyticsThrottlingLoggerType) + } + + if rCtx.TrackerDisabled { + rCtx.MetricsEngine.RecordAnalyticsTrackingThrottled(strconv.Itoa(rCtx.PubID), strconv.Itoa(rCtx.ProfileID), models.AnanlyticsThrottlingTrackerType) + } +} + func updateImpVideoWithVideoConfig(imp *openrtb2.Imp, configObjInVideoConfig *modelsAdunitConfig.VideoConfig) { if len(imp.Video.MIMEs) == 0 { diff --git a/modules/pubmatic/openwrap/beforevalidationhook_test.go b/modules/pubmatic/openwrap/beforevalidationhook_test.go index 057ef5d0802..d5ac47da6a1 100644 --- a/modules/pubmatic/openwrap/beforevalidationhook_test.go +++ b/modules/pubmatic/openwrap/beforevalidationhook_test.go @@ -2312,7 +2312,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) { mockEngine.EXPECT().RecordPublisherInvalidProfileRequests(rctx.Endpoint, "5890", rctx.ProfileIDStr) mockEngine.EXPECT().RecordPublisherInvalidProfileImpressions("5890", rctx.ProfileIDStr, gomock.Any()) mockFeature.EXPECT().IsTBFFeatureEnabled(gomock.Any(), gomock.Any()).Return(false) - + mockFeature.EXPECT().IsAnalyticsTrackingThrottled(gomock.Any(), gomock.Any()).Return(false, false) }, want: hookstage.HookResult[hookstage.BeforeValidationRequestPayload]{ Reject: true, @@ -2345,7 +2345,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) { mockEngine.EXPECT().RecordPublisherInvalidProfileRequests(rctx.Endpoint, "5890", rctx.ProfileIDStr) mockEngine.EXPECT().RecordPublisherInvalidProfileImpressions("5890", rctx.ProfileIDStr, gomock.Any()) mockFeature.EXPECT().IsTBFFeatureEnabled(gomock.Any(), gomock.Any()).Return(false) - + mockFeature.EXPECT().IsAnalyticsTrackingThrottled(gomock.Any(), gomock.Any()).Return(false, false) }, want: hookstage.HookResult[hookstage.BeforeValidationRequestPayload]{ Reject: true, @@ -2390,7 +2390,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) { mockEngine.EXPECT().RecordPublisherInvalidProfileRequests(rctx.Endpoint, "5890", rctx.ProfileIDStr) mockEngine.EXPECT().RecordPublisherInvalidProfileImpressions("5890", rctx.ProfileIDStr, gomock.Any()) mockFeature.EXPECT().IsTBFFeatureEnabled(gomock.Any(), gomock.Any()).Return(false) - + mockFeature.EXPECT().IsAnalyticsTrackingThrottled(gomock.Any(), gomock.Any()).Return(false, false) }, want: hookstage.HookResult[hookstage.BeforeValidationRequestPayload]{ Reject: true, @@ -2436,6 +2436,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) { mockEngine.EXPECT().RecordNobidErrPrebidServerRequests("5890", int(nbr.AllPartnerThrottled)) mockEngine.EXPECT().RecordPublisherRequests(rctx.Endpoint, "5890", rctx.Platform) mockFeature.EXPECT().IsTBFFeatureEnabled(gomock.Any(), gomock.Any()).Return(false) + mockFeature.EXPECT().IsAnalyticsTrackingThrottled(gomock.Any(), gomock.Any()).Return(false, false) }, want: hookstage.HookResult[hookstage.BeforeValidationRequestPayload]{ Reject: true, @@ -2481,6 +2482,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) { mockEngine.EXPECT().RecordNobidErrPrebidServerRequests("5890", int(nbr.InvalidImpressionTagID)) mockEngine.EXPECT().RecordPublisherRequests(rctx.Endpoint, "5890", rctx.Platform) mockFeature.EXPECT().IsTBFFeatureEnabled(gomock.Any(), gomock.Any()).Return(false) + mockFeature.EXPECT().IsAnalyticsTrackingThrottled(gomock.Any(), gomock.Any()).Return(false, false) }, want: hookstage.HookResult[hookstage.BeforeValidationRequestPayload]{ Reject: true, @@ -2530,6 +2532,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) { mockEngine.EXPECT().RecordNobidErrPrebidServerRequests("5890", int(nbr.InvalidImpressionTagID)) mockEngine.EXPECT().RecordPublisherRequests(models.EndpointWebS2S, "5890", rctx.Platform) mockFeature.EXPECT().IsTBFFeatureEnabled(gomock.Any(), gomock.Any()).Return(false) + mockFeature.EXPECT().IsAnalyticsTrackingThrottled(gomock.Any(), gomock.Any()).Return(false, false) }, want: hookstage.HookResult[hookstage.BeforeValidationRequestPayload]{ Reject: true, @@ -2575,6 +2578,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) { mockEngine.EXPECT().RecordNobidErrPrebidServerRequests("5890", int(nbr.InternalError)) mockEngine.EXPECT().RecordPublisherRequests(rctx.Endpoint, "5890", rctx.Platform) mockFeature.EXPECT().IsTBFFeatureEnabled(gomock.Any(), gomock.Any()).Return(false) + mockFeature.EXPECT().IsAnalyticsTrackingThrottled(gomock.Any(), gomock.Any()).Return(false, false) }, want: hookstage.HookResult[hookstage.BeforeValidationRequestPayload]{ Reject: true, @@ -2664,6 +2668,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) { mockEngine.EXPECT().RecordImpDisabledViaConfigStats(models.ImpTypeVideo, "5890", "1234") mockEngine.EXPECT().RecordImpDisabledViaConfigStats(models.ImpTypeBanner, "5890", "1234") mockFeature.EXPECT().IsTBFFeatureEnabled(gomock.Any(), gomock.Any()).Return(false) + mockFeature.EXPECT().IsAnalyticsTrackingThrottled(gomock.Any(), gomock.Any()).Return(false, false) }, want: hookstage.HookResult[hookstage.BeforeValidationRequestPayload]{ Reject: true, @@ -2767,6 +2772,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) { mockEngine.EXPECT().RecordImpDisabledViaConfigStats(models.ImpTypeVideo, "5890", "1234") mockEngine.EXPECT().RecordImpDisabledViaConfigStats(models.ImpTypeBanner, "5890", "1234") mockFeature.EXPECT().IsTBFFeatureEnabled(gomock.Any(), gomock.Any()).Return(false) + mockFeature.EXPECT().IsAnalyticsTrackingThrottled(gomock.Any(), gomock.Any()).Return(false, false) }, want: hookstage.HookResult[hookstage.BeforeValidationRequestPayload]{ Reject: false, @@ -2844,7 +2850,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) { mockEngine.EXPECT().RecordNobidErrPrebidServerRequests("5890", int(nbr.ServerSidePartnerNotConfigured)) mockEngine.EXPECT().RecordPublisherRequests(rctx.Endpoint, "5890", rctx.Platform) mockFeature.EXPECT().IsTBFFeatureEnabled(gomock.Any(), gomock.Any()).Return(false) - + mockFeature.EXPECT().IsAnalyticsTrackingThrottled(gomock.Any(), gomock.Any()).Return(false, false) }, want: hookstage.HookResult[hookstage.BeforeValidationRequestPayload]{ Reject: true, @@ -2955,6 +2961,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) { mockEngine.EXPECT().RecordPlatformPublisherPartnerReqStats(rctx.Platform, "5890", "appnexus") mockEngine.EXPECT().RecordPlatformPublisherPartnerReqStats(rctx.Platform, "5890", "dm-alias") mockFeature.EXPECT().IsTBFFeatureEnabled(gomock.Any(), gomock.Any()).Return(false) + mockFeature.EXPECT().IsAnalyticsTrackingThrottled(gomock.Any(), gomock.Any()).Return(false, false) }, want: hookstage.HookResult[hookstage.BeforeValidationRequestPayload]{ Reject: false, @@ -3046,6 +3053,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) { mockEngine.EXPECT().RecordPublisherRequests(rctx.Endpoint, "5890", rctx.Platform) mockEngine.EXPECT().RecordPlatformPublisherPartnerReqStats(rctx.Platform, "5890", "appnexus") mockFeature.EXPECT().IsTBFFeatureEnabled(gomock.Any(), gomock.Any()).Return(false) + mockFeature.EXPECT().IsAnalyticsTrackingThrottled(gomock.Any(), gomock.Any()).Return(false, false) }, want: hookstage.HookResult[hookstage.BeforeValidationRequestPayload]{ Reject: false, @@ -3206,6 +3214,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) { mockEngine.EXPECT().RecordPlatformPublisherPartnerReqStats("amp", "5890", "appnexus") mockFeature.EXPECT().IsAmpMultiformatEnabled(5890).Return(true) mockFeature.EXPECT().IsTBFFeatureEnabled(gomock.Any(), gomock.Any()).Return(false) + mockFeature.EXPECT().IsAnalyticsTrackingThrottled(gomock.Any(), gomock.Any()).Return(false, false) }, want: hookstage.HookResult[hookstage.BeforeValidationRequestPayload]{ Reject: false, @@ -3459,11 +3468,11 @@ func TestVASTUnwrap_handleBeforeValidationHook(t *testing.T) { }, }, nil) mockCache.EXPECT().GetAdunitConfigFromCache(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(&adunitconfig.AdUnitConfig{}) - mockEngine.EXPECT().RecordPlatformPublisherPartnerReqStats(rctx.Platform, "5890", "appnexus") mockEngine.EXPECT().RecordPublisherRequests(rctx.Endpoint, "5890", rctx.Platform) mockEngine.EXPECT().RecordPublisherProfileRequests("5890", "1234") mockFeature.EXPECT().IsTBFFeatureEnabled(gomock.Any(), gomock.Any()).Return(false) + mockFeature.EXPECT().IsAnalyticsTrackingThrottled(gomock.Any(), gomock.Any()).Return(false, false) }, want: want{ rctx: &models.RequestCtx{ @@ -3520,11 +3529,11 @@ func TestVASTUnwrap_handleBeforeValidationHook(t *testing.T) { }, }, nil) mockCache.EXPECT().GetAdunitConfigFromCache(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(&adunitconfig.AdUnitConfig{}) - mockEngine.EXPECT().RecordPlatformPublisherPartnerReqStats(rctx.Platform, "5890", "appnexus") mockEngine.EXPECT().RecordPublisherRequests(rctx.Endpoint, "5890", rctx.Platform) mockEngine.EXPECT().RecordPublisherProfileRequests("5890", "1234") mockFeature.EXPECT().IsTBFFeatureEnabled(gomock.Any(), gomock.Any()).Return(false) + mockFeature.EXPECT().IsAnalyticsTrackingThrottled(gomock.Any(), gomock.Any()).Return(false, false) }, want: want{ rctx: &models.RequestCtx{ @@ -3586,11 +3595,11 @@ func TestVASTUnwrap_handleBeforeValidationHook(t *testing.T) { }, }, nil) mockCache.EXPECT().GetAdunitConfigFromCache(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(&adunitconfig.AdUnitConfig{}) - mockEngine.EXPECT().RecordPlatformPublisherPartnerReqStats(rctx.Platform, "5890", "appnexus") mockEngine.EXPECT().RecordPublisherRequests(rctx.Endpoint, "5890", rctx.Platform) mockEngine.EXPECT().RecordPublisherProfileRequests("5890", "1234") mockFeature.EXPECT().IsTBFFeatureEnabled(gomock.Any(), gomock.Any()).Return(false) + mockFeature.EXPECT().IsAnalyticsTrackingThrottled(gomock.Any(), gomock.Any()).Return(false, false) }, want: want{ rctx: &models.RequestCtx{ @@ -3653,11 +3662,11 @@ func TestVASTUnwrap_handleBeforeValidationHook(t *testing.T) { }, }, nil) mockCache.EXPECT().GetAdunitConfigFromCache(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(&adunitconfig.AdUnitConfig{}) - mockEngine.EXPECT().RecordPlatformPublisherPartnerReqStats(rctx.Platform, "5890", "appnexus") mockEngine.EXPECT().RecordPublisherRequests(rctx.Endpoint, "5890", rctx.Platform) mockEngine.EXPECT().RecordPublisherProfileRequests("5890", "1234") mockFeature.EXPECT().IsTBFFeatureEnabled(gomock.Any(), gomock.Any()).Return(false) + mockFeature.EXPECT().IsAnalyticsTrackingThrottled(gomock.Any(), gomock.Any()).Return(false, false) }, want: want{ rctx: &models.RequestCtx{ @@ -3715,11 +3724,11 @@ func TestVASTUnwrap_handleBeforeValidationHook(t *testing.T) { }, }, nil) mockCache.EXPECT().GetAdunitConfigFromCache(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(&adunitconfig.AdUnitConfig{}) - mockEngine.EXPECT().RecordPlatformPublisherPartnerReqStats(rctx.Platform, "5890", "appnexus") mockEngine.EXPECT().RecordPublisherRequests(rctx.Endpoint, "5890", rctx.Platform) mockEngine.EXPECT().RecordPublisherProfileRequests("5890", "1234") mockFeature.EXPECT().IsTBFFeatureEnabled(gomock.Any(), gomock.Any()).Return(false) + mockFeature.EXPECT().IsAnalyticsTrackingThrottled(gomock.Any(), gomock.Any()).Return(false, false) }, want: want{ rctx: &models.RequestCtx{ @@ -3821,6 +3830,7 @@ func TestImpBidCtx_handleBeforeValidationHook(t *testing.T) { mockEngine.EXPECT().RecordPublisherInvalidProfileRequests(rctx.Endpoint, "5890", rctx.ProfileIDStr) mockEngine.EXPECT().RecordPublisherInvalidProfileImpressions("5890", rctx.ProfileIDStr, gomock.Any()) mockFeature.EXPECT().IsTBFFeatureEnabled(gomock.Any(), gomock.Any()).Return(false) + mockFeature.EXPECT().IsAnalyticsTrackingThrottled(gomock.Any(), gomock.Any()).Return(false, false) }, want: want{ rctx: &models.RequestCtx{ @@ -3873,7 +3883,7 @@ func TestImpBidCtx_handleBeforeValidationHook(t *testing.T) { mockEngine.EXPECT().RecordPublisherInvalidProfileRequests(rctx.Endpoint, "5890", rctx.ProfileIDStr) mockEngine.EXPECT().RecordPublisherInvalidProfileImpressions("5890", rctx.ProfileIDStr, gomock.Any()) mockFeature.EXPECT().IsTBFFeatureEnabled(gomock.Any(), gomock.Any()).Return(false) - + mockFeature.EXPECT().IsAnalyticsTrackingThrottled(gomock.Any(), gomock.Any()).Return(false, false) }, want: want{ rctx: &models.RequestCtx{ @@ -3927,6 +3937,7 @@ func TestImpBidCtx_handleBeforeValidationHook(t *testing.T) { mockEngine.EXPECT().RecordNobidErrPrebidServerRequests("5890", int(nbr.AllPartnerThrottled)) mockEngine.EXPECT().RecordPublisherRequests(rctx.Endpoint, "5890", rctx.Platform) mockFeature.EXPECT().IsTBFFeatureEnabled(gomock.Any(), gomock.Any()).Return(false) + mockFeature.EXPECT().IsAnalyticsTrackingThrottled(gomock.Any(), gomock.Any()).Return(false, false) }, want: want{ error: false, @@ -3980,6 +3991,7 @@ func TestImpBidCtx_handleBeforeValidationHook(t *testing.T) { mockEngine.EXPECT().RecordNobidErrPrebidServerRequests("5890", int(nbr.InvalidImpressionTagID)) mockEngine.EXPECT().RecordPublisherRequests(rctx.Endpoint, "5890", rctx.Platform) mockFeature.EXPECT().IsTBFFeatureEnabled(gomock.Any(), gomock.Any()).Return(false) + mockFeature.EXPECT().IsAnalyticsTrackingThrottled(gomock.Any(), gomock.Any()).Return(false, false) }, want: want{ rctx: &models.RequestCtx{ @@ -4025,6 +4037,7 @@ func TestImpBidCtx_handleBeforeValidationHook(t *testing.T) { mockEngine.EXPECT().RecordNobidErrPrebidServerRequests("5890", int(nbr.InternalError)) mockEngine.EXPECT().RecordPublisherRequests(rctx.Endpoint, "5890", rctx.Platform) mockFeature.EXPECT().IsTBFFeatureEnabled(gomock.Any(), gomock.Any()).Return(false) + mockFeature.EXPECT().IsAnalyticsTrackingThrottled(gomock.Any(), gomock.Any()).Return(false, false) }, want: want{ rctx: &models.RequestCtx{ diff --git a/modules/pubmatic/openwrap/database/mysql/adunit_config.go b/modules/pubmatic/openwrap/database/mysql/adunit_config.go index 98fbf8dd0a2..d3a27c2edaa 100644 --- a/modules/pubmatic/openwrap/database/mysql/adunit_config.go +++ b/modules/pubmatic/openwrap/database/mysql/adunit_config.go @@ -1,10 +1,12 @@ package mysql import ( + "context" "database/sql" "encoding/json" "strconv" "strings" + "time" "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models" "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models/adunitconfig" @@ -19,8 +21,11 @@ func (db *mySqlDB) GetAdunitConfig(profileID, displayVersion int) (*adunitconfig adunitConfigQuery = strings.Replace(adunitConfigQuery, profileIdKey, strconv.Itoa(profileID), -1) adunitConfigQuery = strings.Replace(adunitConfigQuery, displayVersionKey, strconv.Itoa(displayVersion), -1) + ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Millisecond*time.Duration(db.cfg.MaxDbContextTimeout))) + defer cancel() + var adunitConfigJSON string - err := db.conn.QueryRow(adunitConfigQuery).Scan(&adunitConfigJSON) + err := db.conn.QueryRowContext(ctx, adunitConfigQuery).Scan(&adunitConfigJSON) if err != nil { if err == sql.ErrNoRows { return nil, nil diff --git a/modules/pubmatic/openwrap/database/mysql/adunit_config_test.go b/modules/pubmatic/openwrap/database/mysql/adunit_config_test.go index 75968ed56b0..2e370c385f0 100644 --- a/modules/pubmatic/openwrap/database/mysql/adunit_config_test.go +++ b/modules/pubmatic/openwrap/database/mysql/adunit_config_test.go @@ -47,6 +47,7 @@ func Test_mySqlDB_GetAdunitConfig(t *testing.T) { Queries: config.Queries{ GetAdunitConfigForLiveVersion: "^SELECT (.+) FROM wrapper_media_config (.+) LIVE", }, + MaxDbContextTimeout: 1000, }, }, args: args{ @@ -72,6 +73,7 @@ func Test_mySqlDB_GetAdunitConfig(t *testing.T) { Queries: config.Queries{ GetAdunitConfigForLiveVersion: "^SELECT (.+) FROM wrapper_media_config (.+) LIVE", }, + MaxDbContextTimeout: 1000, }, }, args: args{ @@ -102,6 +104,7 @@ func Test_mySqlDB_GetAdunitConfig(t *testing.T) { Queries: config.Queries{ GetAdunitConfigQuery: "^SELECT (.+) FROM wrapper_media_config (.+)", }, + MaxDbContextTimeout: 1000, }, }, args: args{ @@ -132,6 +135,7 @@ func Test_mySqlDB_GetAdunitConfig(t *testing.T) { Queries: config.Queries{ GetAdunitConfigForLiveVersion: "^SELECT (.+) FROM wrapper_media_config (.+) LIVE", }, + MaxDbContextTimeout: 1000, }, }, args: args{ @@ -157,6 +161,7 @@ func Test_mySqlDB_GetAdunitConfig(t *testing.T) { Queries: config.Queries{ GetAdunitConfigQuery: "^SELECT (.+) FROM wrapper_media_config (.+)", }, + MaxDbContextTimeout: 1000, }, }, args: args{ @@ -187,6 +192,7 @@ func Test_mySqlDB_GetAdunitConfig(t *testing.T) { Queries: config.Queries{ GetAdunitConfigQuery: "^SELECT (.+) FROM wrapper_media_config (.+)", }, + MaxDbContextTimeout: 1000, }, }, args: args{ @@ -218,6 +224,7 @@ func Test_mySqlDB_GetAdunitConfig(t *testing.T) { Queries: config.Queries{ GetAdunitConfigQuery: "^SELECT (.+) FROM wrapper_media_config (.+)", }, + MaxDbContextTimeout: 1000, }, }, args: args{ diff --git a/modules/pubmatic/openwrap/database/mysql/fullscreenclickability.go b/modules/pubmatic/openwrap/database/mysql/fullscreenclickability.go index f0a1e8ecfb6..05999d60f67 100644 --- a/modules/pubmatic/openwrap/database/mysql/fullscreenclickability.go +++ b/modules/pubmatic/openwrap/database/mysql/fullscreenclickability.go @@ -1,13 +1,18 @@ package mysql import ( + "context" "strconv" + "time" "github.com/golang/glog" ) func (db *mySqlDB) GetFSCThresholdPerDSP() (map[int]int, error) { - rows, err := db.conn.Query(db.cfg.Queries.GetAllDspFscPcntQuery) + ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Millisecond*time.Duration(db.cfg.MaxDbContextTimeout))) + defer cancel() + + rows, err := db.conn.QueryContext(ctx, db.cfg.Queries.GetAllDspFscPcntQuery) if err != nil { return nil, err } diff --git a/modules/pubmatic/openwrap/database/mysql/fullscreenclickability_test.go b/modules/pubmatic/openwrap/database/mysql/fullscreenclickability_test.go index c1aca4b29ee..811494e6f23 100644 --- a/modules/pubmatic/openwrap/database/mysql/fullscreenclickability_test.go +++ b/modules/pubmatic/openwrap/database/mysql/fullscreenclickability_test.go @@ -40,6 +40,7 @@ func Test_mySqlDB_GetFSCThresholdPerDSP(t *testing.T) { Queries: config.Queries{ GetAllDspFscPcntQuery: "^SELECT (.+) FROM wrapper_feature_dsp_mapping (.+)", }, + MaxDbContextTimeout: 1000, }, }, want: map[int]int{}, @@ -61,6 +62,7 @@ func Test_mySqlDB_GetFSCThresholdPerDSP(t *testing.T) { Queries: config.Queries{ GetAllDspFscPcntQuery: "^SELECT (.+) FROM wrapper_feature_dsp_mapping (.+)", }, + MaxDbContextTimeout: 1000, }, }, want: map[int]int{ diff --git a/modules/pubmatic/openwrap/database/mysql/partner_config_test.go b/modules/pubmatic/openwrap/database/mysql/partner_config_test.go index 4a81171d7b2..ea89b8b2116 100644 --- a/modules/pubmatic/openwrap/database/mysql/partner_config_test.go +++ b/modules/pubmatic/openwrap/database/mysql/partner_config_test.go @@ -34,6 +34,7 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) { Queries: config.Queries{ LiveVersionInnerQuery: "^SELECT (.+) FROM wrapper_version (.+) LIVE", }, + MaxDbContextTimeout: 1000, }, }, args: args{ @@ -63,6 +64,7 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) { Queries: config.Queries{ LiveVersionInnerQuery: "^SELECT (.+) FROM wrapper_version (.+) LIVE", }, + MaxDbContextTimeout: 1000, }, }, args: args{ diff --git a/modules/pubmatic/openwrap/database/mysql/publisher_feature.go b/modules/pubmatic/openwrap/database/mysql/publisher_feature.go index 66fbc3fbc52..a5c20f9568e 100644 --- a/modules/pubmatic/openwrap/database/mysql/publisher_feature.go +++ b/modules/pubmatic/openwrap/database/mysql/publisher_feature.go @@ -1,14 +1,19 @@ package mysql import ( + "context" "database/sql" + "time" "github.com/golang/glog" "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models" ) func (db *mySqlDB) GetPublisherFeatureMap() (map[int]map[int]models.FeatureData, error) { - rows, err := db.conn.Query(db.cfg.Queries.GetPublisherFeatureMapQuery) + ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Millisecond*time.Duration(db.cfg.MaxDbContextTimeout))) + defer cancel() + + rows, err := db.conn.QueryContext(ctx, db.cfg.Queries.GetPublisherFeatureMapQuery) if err != nil { return nil, err } diff --git a/modules/pubmatic/openwrap/database/mysql/publisher_feature_test.go b/modules/pubmatic/openwrap/database/mysql/publisher_feature_test.go index 4892e0f49de..fa13d09e01f 100644 --- a/modules/pubmatic/openwrap/database/mysql/publisher_feature_test.go +++ b/modules/pubmatic/openwrap/database/mysql/publisher_feature_test.go @@ -41,6 +41,7 @@ func Test_mySqlDB_GetPublisherFeatureMap(t *testing.T) { Queries: config.Queries{ GetPublisherFeatureMapQuery: "^SELECT (.+) FROM test_wrapper_table (.+)", }, + MaxDbContextTimeout: 1000, }, }, want: map[int]map[int]models.FeatureData{}, @@ -62,6 +63,7 @@ func Test_mySqlDB_GetPublisherFeatureMap(t *testing.T) { Queries: config.Queries{ GetPublisherFeatureMapQuery: "^SELECT (.+) FROM test_wrapper_table (.+)", }, + MaxDbContextTimeout: 1000, }, }, want: map[int]map[int]models.FeatureData{ @@ -99,6 +101,7 @@ func Test_mySqlDB_GetPublisherFeatureMap(t *testing.T) { Queries: config.Queries{ GetPublisherFeatureMapQuery: "^SELECT (.+) FROM test_wrapper_table (.+)", }, + MaxDbContextTimeout: 1000, }, }, want: map[int]map[int]models.FeatureData{}, diff --git a/modules/pubmatic/openwrap/database/mysql/slot_mapping.go b/modules/pubmatic/openwrap/database/mysql/slot_mapping.go index 11135599a1f..0cbf4f26a09 100644 --- a/modules/pubmatic/openwrap/database/mysql/slot_mapping.go +++ b/modules/pubmatic/openwrap/database/mysql/slot_mapping.go @@ -1,10 +1,12 @@ package mysql import ( + "context" "errors" "fmt" "strconv" "strings" + "time" "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models" ) @@ -14,7 +16,11 @@ func (db *mySqlDB) GetPublisherSlotNameHash(pubID int) (map[string]string, error nameHashMap := make(map[string]string) query := db.formSlotNameHashQuery(pubID) - rows, err := db.conn.Query(query) + + ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Millisecond*time.Duration(db.cfg.MaxDbContextTimeout))) + defer cancel() + + rows, err := db.conn.QueryContext(ctx, query) if err != nil { return nameHashMap, err } diff --git a/modules/pubmatic/openwrap/database/mysql/slot_mapping_test.go b/modules/pubmatic/openwrap/database/mysql/slot_mapping_test.go index 313714d7c9d..68c48566481 100644 --- a/modules/pubmatic/openwrap/database/mysql/slot_mapping_test.go +++ b/modules/pubmatic/openwrap/database/mysql/slot_mapping_test.go @@ -45,6 +45,7 @@ func Test_mySqlDB_GetPublisherSlotNameHash(t *testing.T) { Queries: config.Queries{ GetSlotNameHash: "^SELECT (.+) FROM wrapper_publisher_slot (.+)", }, + MaxDbContextTimeout: 1000, }, }, args: args{ @@ -77,6 +78,7 @@ func Test_mySqlDB_GetPublisherSlotNameHash(t *testing.T) { Queries: config.Queries{ GetSlotNameHash: "^SELECT (.+) FROM wrapper_publisher_slot (.+)", }, + MaxDbContextTimeout: 1000, }, }, args: args{ diff --git a/modules/pubmatic/openwrap/database/mysql/vasttags.go b/modules/pubmatic/openwrap/database/mysql/vasttags.go index 6b036ac00a5..380bcdada32 100644 --- a/modules/pubmatic/openwrap/database/mysql/vasttags.go +++ b/modules/pubmatic/openwrap/database/mysql/vasttags.go @@ -1,24 +1,21 @@ package mysql import ( + "context" "fmt" + "time" "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models" ) // GetPublisherVASTTags - Method to get vast tags associated with publisher id from giym DB func (db *mySqlDB) GetPublisherVASTTags(pubID int) (models.PublisherVASTTags, error) { - - /* - //TOOD:VIRAL Remove Hook once UI/API changes are in place - if out := vastTagHookPublisherVASTTags(rtbReqId, pubID); nil != out { - return out, nil - } - */ - getActiveVASTTagsQuery := fmt.Sprintf(db.cfg.Queries.GetPublisherVASTTagsQuery, pubID) - rows, err := db.conn.Query(getActiveVASTTagsQuery) + ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Millisecond*time.Duration(db.cfg.MaxDbContextTimeout))) + defer cancel() + + rows, err := db.conn.QueryContext(ctx, getActiveVASTTagsQuery) if err != nil { return nil, err } diff --git a/modules/pubmatic/openwrap/database/mysql/vasttags_test.go b/modules/pubmatic/openwrap/database/mysql/vasttags_test.go index 7e8b183d951..1709cd9ff93 100644 --- a/modules/pubmatic/openwrap/database/mysql/vasttags_test.go +++ b/modules/pubmatic/openwrap/database/mysql/vasttags_test.go @@ -45,6 +45,7 @@ func Test_mySqlDB_GetPublisherVASTTags(t *testing.T) { Queries: config.Queries{ GetPublisherVASTTagsQuery: "^SELECT (.+) FROM wrapper_publisher_partner_vast_tag (.+)", }, + MaxDbContextTimeout: 1000, }, }, args: args{ @@ -75,6 +76,7 @@ func Test_mySqlDB_GetPublisherVASTTags(t *testing.T) { Queries: config.Queries{ GetPublisherVASTTagsQuery: "^SELECT (.+) FROM wrapper_publisher_partner_vast_tag (.+)", }, + MaxDbContextTimeout: 1000, }, }, args: args{ diff --git a/modules/pubmatic/openwrap/entrypointhook.go b/modules/pubmatic/openwrap/entrypointhook.go index b6470994fb8..7e619b8f65f 100644 --- a/modules/pubmatic/openwrap/entrypointhook.go +++ b/modules/pubmatic/openwrap/entrypointhook.go @@ -133,8 +133,6 @@ func (m OpenWrap) handleEntrypointHook( rCtx.PubID = pubid } - rCtx.LoggerDisabled, rCtx.TrackerDisabled = m.pubFeatures.IsAnalyticsTrackingThrottled(rCtx.PubID, rCtx.ProfileID) - result.Reject = false return result, nil } diff --git a/modules/pubmatic/openwrap/entrypointhook_test.go b/modules/pubmatic/openwrap/entrypointhook_test.go index d1a588a7dc1..317c73c1681 100644 --- a/modules/pubmatic/openwrap/entrypointhook_test.go +++ b/modules/pubmatic/openwrap/entrypointhook_test.go @@ -13,7 +13,6 @@ import ( mock_metrics "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/metrics/mock" "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models" "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models/nbr" - mock_publisherfeatures "github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/publisherfeature/mock" "github.com/prebid/prebid-server/v2/openrtb_ext" "github.com/stretchr/testify/assert" ) @@ -32,7 +31,7 @@ func TestOpenWrap_handleEntrypointHook(t *testing.T) { in0 context.Context miCtx hookstage.ModuleInvocationContext payload hookstage.EntrypointPayload - setup func(*mock_metrics.MockMetricsEngine, *mock_publisherfeatures.MockFeature) + setup func(*mock_metrics.MockMetricsEngine) } tests := []struct { name string @@ -59,7 +58,7 @@ func TestOpenWrap_handleEntrypointHook(t *testing.T) { }(), Body: []byte(`{"ext":{"wrapper":{"profileid":5890,"versionid":1}}}`), }, - setup: func(mme *mock_metrics.MockMetricsEngine, mpf *mock_publisherfeatures.MockFeature) {}, + setup: func(mme *mock_metrics.MockMetricsEngine) {}, }, want: hookstage.HookResult[hookstage.EntrypointPayload]{ ModuleContext: hookstage.ModuleContext{ @@ -96,9 +95,7 @@ func TestOpenWrap_handleEntrypointHook(t *testing.T) { }(), Body: []byte(`{"ext":{"wrapper":{"profileid":5890,"versionid":1}}}`), }, - setup: func(mme *mock_metrics.MockMetricsEngine, mpf *mock_publisherfeatures.MockFeature) { - mpf.EXPECT().IsAnalyticsTrackingThrottled(gomock.Any(), gomock.Any()) - }, + setup: func(mme *mock_metrics.MockMetricsEngine) {}, }, want: hookstage.HookResult[hookstage.EntrypointPayload]{ ModuleContext: hookstage.ModuleContext{ @@ -161,9 +158,7 @@ func TestOpenWrap_handleEntrypointHook(t *testing.T) { }(), Body: []byte(`{"ext":{"wrapper":{"profileid":5890,"versionid":1,"wiid":"4df09505-d0b2-4d70-94d9-dc41e8e777f7"}}}`), }, - setup: func(mme *mock_metrics.MockMetricsEngine, mpf *mock_publisherfeatures.MockFeature) { - mpf.EXPECT().IsAnalyticsTrackingThrottled(gomock.Any(), gomock.Any()) - }, + setup: func(mme *mock_metrics.MockMetricsEngine) {}, }, want: hookstage.HookResult[hookstage.EntrypointPayload]{ ModuleContext: hookstage.ModuleContext{ @@ -211,7 +206,7 @@ func TestOpenWrap_handleEntrypointHook(t *testing.T) { }(), Body: []byte(`{"ext":{"wrapper":{"profileids":5890,"versionid":1}}}`), }, - setup: func(mme *mock_metrics.MockMetricsEngine, mpf *mock_publisherfeatures.MockFeature) { + setup: func(mme *mock_metrics.MockMetricsEngine) { mme.EXPECT().RecordBadRequests(gomock.Any(), 700) }, }, @@ -244,9 +239,7 @@ func TestOpenWrap_handleEntrypointHook(t *testing.T) { }(), Body: []byte(`{"imp":[{"tagid":"/43743431/DMDemo","ext":{"prebid":{"bidder":{"pubmatic":{"publisherId":"5890"}},"adunitcode":"div-gpt-ad-1460505748561-0"}},"id":"div-gpt-ad-1460505748561-0","banner":{"topframe":1,"format":[{"w":300,"h":250}]}}],"site":{"domain":"localhost:9999","publisher":{"domain":"localhost:9999","id":"5890"},"page":"http://localhost:9999/integrationExamples/gpt/owServer_example.html"},"device":{"w":1792,"h":446,"dnt":0,"ua":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36","language":"en","sua":{"source":1,"platform":{"brand":"macOS"},"browsers":[{"brand":"Google Chrome","version":["117"]},{"brand":"Not;A=Brand","version":["8"]},{"brand":"Chromium","version":["117"]}],"mobile":0}},"ext":{"prebid":{"auctiontimestamp":1697191822565,"targeting":{"includewinners":true,"includebidderkeys":true},"bidderparams":{"pubmatic":{"publisherId":"5890","wrapper":{"profileid":43563,"versionid":1}}},"channel":{"name":"pbjs","version":"v8.7.0-pre"},"createtids":false}},"id":"5bdd7da5-1166-40fe-a9cb-3bf3c3164cd3","test":0,"tmax":3000}`), }, - setup: func(mme *mock_metrics.MockMetricsEngine, mpf *mock_publisherfeatures.MockFeature) { - mpf.EXPECT().IsAnalyticsTrackingThrottled(gomock.Any(), gomock.Any()) - }, + setup: func(mme *mock_metrics.MockMetricsEngine) {}, }, want: hookstage.HookResult[hookstage.EntrypointPayload]{ ModuleContext: hookstage.ModuleContext{ @@ -305,9 +298,7 @@ func TestOpenWrap_handleEntrypointHook(t *testing.T) { }(), Body: []byte(`{"imp":[{"tagid":"/43743431/DMDemo","ext":{"prebid":{"bidder":{"pubmatic":{"publisherId":"5890"}},"adunitcode":"div-gpt-ad-1460505748561-0"}},"id":"div-gpt-ad-1460505748561-0","banner":{"topframe":1,"format":[{"w":300,"h":250}]}}],"site":{"domain":"localhost:9999","publisher":{"domain":"localhost:9999","id":"5890"},"page":"http://localhost:9999/integrationExamples/gpt/owServer_example.html"},"device":{"w":1792,"h":446,"dnt":0,"ua":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36","language":"en","sua":{"source":1,"platform":{"brand":"macOS"},"browsers":[{"brand":"Google Chrome","version":["117"]},{"brand":"Not;A=Brand","version":["8"]},{"brand":"Chromium","version":["117"]}],"mobile":0}},"ext":{"prebid":{"auctiontimestamp":1697191822565,"targeting":{"includewinners":true,"includebidderkeys":true},"bidderparams":{"pubmatic":{"publisherId":"5890","wrapper":{"profileid":43563,"versionid":1}}},"channel":{"name":"pbjs","version":"v8.7.0-pre"},"createtids":false,"debug":true}},"id":"5bdd7da5-1166-40fe-a9cb-3bf3c3164cd3","test":0,"tmax":3000}`), }, - setup: func(mme *mock_metrics.MockMetricsEngine, mpf *mock_publisherfeatures.MockFeature) { - mpf.EXPECT().IsAnalyticsTrackingThrottled(gomock.Any(), gomock.Any()) - }, + setup: func(mme *mock_metrics.MockMetricsEngine) {}, }, want: hookstage.HookResult[hookstage.EntrypointPayload]{ ModuleContext: hookstage.ModuleContext{ @@ -366,7 +357,7 @@ func TestOpenWrap_handleEntrypointHook(t *testing.T) { }(), Body: []byte(`{"imp":[{"tagid":"/43743431/DMDemo","ext":{"prebid":{"bidder":{"pubmatic":{"publisherId":"5890"}},"adunitcode":"div-gpt-ad-1460505748561-0"}},"id":"div-gpt-ad-1460505748561-0","banner":{"topframe":1,"format":[{"w":300,"h":250}]}}],"site":{"domain":"localhost:9999","publisher":{"domain":"localhost:9999","id":"5890"},"page":"http://localhost:9999/integrationExamples/gpt/owServer_example.html"},"device":{"w":1792,"h":446,"dnt":0,"ua":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36","language":"en","sua":{"source":1,"platform":{"brand":"macOS"},"browsers":[{"brand":"Google Chrome","version":["117"]},{"brand":"Not;A=Brand","version":["8"]},{"brand":"Chromium","version":["117"]}],"mobile":0}},"ext":{"prebid":{"auctiontimestamp":1697191822565,"targeting":{"includewinners":true,"includebidderkeys":true},"bidderparams":{"pubmatic":{"publisherId":"5890","wrapper":{}}},"channel":{"name":"pbjs","version":"v8.7.0-pre"},"createtids":false}},"id":"5bdd7da5-1166-40fe-a9cb-3bf3c3164cd3","test":0,"tmax":3000}`), }, - setup: func(mme *mock_metrics.MockMetricsEngine, mpf *mock_publisherfeatures.MockFeature) { + setup: func(mme *mock_metrics.MockMetricsEngine) { mme.EXPECT().RecordBadRequests(gomock.Any(), 700) }, }, @@ -399,7 +390,7 @@ func TestOpenWrap_handleEntrypointHook(t *testing.T) { }(), Body: []byte(`{"imp":[{"tagid":"/43743431/DMDemo","ext":{"prebid":{"bidder":{"pubmatic":{"publisherId":"5890"}},"adunitcode":"div-gpt-ad-1460505748561-0"}},"id":"div-gpt-ad-1460505748561-0","banner":{"topframe":1,"format":[{"w":300,"h":250}]}}],"site":{"domain":"localhost:9999","publisher":{"domain":"localhost:9999","id":"5890"},"page":"http://localhost:9999/integrationExamples/gpt/owServer_example.html"},"device":{"w":1792,"h":446,"dnt":0,"ua":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36","language":"en","sua":{"source":1,"platform":{"brand":"macOS"},"browsers":[{"brand":"Google Chrome","version":["117"]},{"brand":"Not;A=Brand","version":["8"]},{"brand":"Chromium","version":["117"]}],"mobile":0}},"ext":{"prebid":{"auctiontimestamp":1697191822565,"targeting":{"includewinners":true,"includebidderkeys":true},"bidderparams":{"pubmatic":{"publisherId":"5890","wrapper":{}}},"channel":{"name":"pbjs","version":"v8.7.0-pre"},"createtids":false}},"id":"5bdd7da5-1166-40fe-a9cb-3bf3c3164cd3","test":0,"tmax":3000}`), }, - setup: func(mme *mock_metrics.MockMetricsEngine, mpf *mock_publisherfeatures.MockFeature) {}, + setup: func(mme *mock_metrics.MockMetricsEngine) {}, }, want: hookstage.HookResult[hookstage.EntrypointPayload]{ ModuleContext: hookstage.ModuleContext{ @@ -428,7 +419,7 @@ func TestOpenWrap_handleEntrypointHook(t *testing.T) { }(), Body: []byte(`{"ext":{"wrapper":{"profileid":5890,"versionid":1}}}`), }, - setup: func(mme *mock_metrics.MockMetricsEngine, mpf *mock_publisherfeatures.MockFeature) {}, + setup: func(mme *mock_metrics.MockMetricsEngine) {}, }, want: hookstage.HookResult[hookstage.EntrypointPayload]{ ModuleContext: hookstage.ModuleContext{ @@ -466,9 +457,7 @@ func TestOpenWrap_handleEntrypointHook(t *testing.T) { }(), Body: []byte(`{"ext":{"wrapper":{"profileid":5890,"versionid":1}}}`), }, - setup: func(mme *mock_metrics.MockMetricsEngine, mpf *mock_publisherfeatures.MockFeature) { - mpf.EXPECT().IsAnalyticsTrackingThrottled(gomock.Any(), gomock.Any()) - }, + setup: func(mme *mock_metrics.MockMetricsEngine) {}, }, want: hookstage.HookResult[hookstage.EntrypointPayload]{ ModuleContext: hookstage.ModuleContext{ @@ -508,14 +497,11 @@ func TestOpenWrap_handleEntrypointHook(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - mockPubFeature := mock_publisherfeatures.NewMockFeature(ctrl) - - tt.args.setup(mockEngine, mockPubFeature) + tt.args.setup(mockEngine) m := OpenWrap{ cfg: tt.fields.cfg, cache: tt.fields.cache, metricEngine: mockEngine, - pubFeatures: mockPubFeature, } got, err := m.handleEntrypointHook(tt.args.in0, tt.args.miCtx, tt.args.payload) assert.Equal(t, err, tt.wantErr) diff --git a/modules/pubmatic/openwrap/models/constants.go b/modules/pubmatic/openwrap/models/constants.go index 82e44955498..376a4b46824 100755 --- a/modules/pubmatic/openwrap/models/constants.go +++ b/modules/pubmatic/openwrap/models/constants.go @@ -435,6 +435,11 @@ const ( ContextOWLoggerKey contextKey = "owlogger" ) +const ( + AnanlyticsThrottlingLoggerType = "wl" + AnanlyticsThrottlingTrackerType = "wt" +) + const ( Pipe = "|" BidIdSeparator = "::"