Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 25 additions & 23 deletions modules/pubmatic/openwrap/beforevalidationhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4008,7 +4008,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) {
fields fields
args args
want want
setup func()
setup func(mockEngine *mock_metrics.MockMetricsEngine)
}{
{
name: "request_with_sshb=1",
Expand Down Expand Up @@ -4111,7 +4111,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) {
cache: mockCache,
metricEngine: mockEngine,
},
setup: func() {
setup: func(mockEngine *mock_metrics.MockMetricsEngine) {
mockEngine.EXPECT().RecordPublisherProfileRequests("5890", "1234")
mockEngine.EXPECT().RecordBadRequests(rctx.Endpoint, "5890", getPubmaticErrorCode(nbr.InvalidRequestExt))
mockEngine.EXPECT().RecordNobidErrPrebidServerRequests("5890", int(nbr.InvalidRequestExt))
Expand Down Expand Up @@ -4142,7 +4142,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) {
cache: mockCache,
metricEngine: mockEngine,
},
setup: func() {
setup: func(mockEngine *mock_metrics.MockMetricsEngine) {
mockCache.EXPECT().GetPartnerConfigMap(gomock.Any(), gomock.Any(), gomock.Any()).Return(map[int]map[string]string{
2: {
models.PARTNER_ID: "2",
Expand Down Expand Up @@ -4190,7 +4190,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) {
cache: mockCache,
metricEngine: mockEngine,
},
setup: func() {
setup: func(mockEngine *mock_metrics.MockMetricsEngine) {
mockCache.EXPECT().GetPartnerConfigMap(gomock.Any(), gomock.Any(), gomock.Any()).Return(map[int]map[string]string{}, nil)
//prometheus metrics
mockEngine.EXPECT().RecordPublisherProfileRequests("5890", "1234")
Expand Down Expand Up @@ -4225,7 +4225,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) {
cache: mockCache,
metricEngine: mockEngine,
},
setup: func() {
setup: func(mockEngine *mock_metrics.MockMetricsEngine) {
mockCache.EXPECT().GetPartnerConfigMap(gomock.Any(), gomock.Any(), gomock.Any()).Return(map[int]map[string]string{
2: {
models.PARTNER_ID: "2",
Expand Down Expand Up @@ -4272,7 +4272,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) {
cache: mockCache,
metricEngine: mockEngine,
},
setup: func() {
setup: func(mockEngine *mock_metrics.MockMetricsEngine) {
mockCache.EXPECT().GetPartnerConfigMap(gomock.Any(), gomock.Any(), gomock.Any()).Return(map[int]map[string]string{
2: {
models.PARTNER_ID: "2",
Expand Down Expand Up @@ -4322,7 +4322,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) {
cache: mockCache,
metricEngine: mockEngine,
},
setup: func() {
setup: func(mockEngine *mock_metrics.MockMetricsEngine) {
mockCache.EXPECT().GetPartnerConfigMap(gomock.Any(), gomock.Any(), gomock.Any()).Return(map[int]map[string]string{
2: {
models.PARTNER_ID: "2",
Expand Down Expand Up @@ -4383,7 +4383,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) {
cache: mockCache,
metricEngine: mockEngine,
},
setup: func() {
setup: func(mockEngine *mock_metrics.MockMetricsEngine) {
mockCache.EXPECT().GetPartnerConfigMap(gomock.Any(), gomock.Any(), gomock.Any()).Return(map[int]map[string]string{
2: {
models.PARTNER_ID: "2",
Expand Down Expand Up @@ -4435,7 +4435,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) {
cache: mockCache,
metricEngine: mockEngine,
},
setup: func() {
setup: func(mockEngine *mock_metrics.MockMetricsEngine) {
mockCache.EXPECT().GetPartnerConfigMap(gomock.Any(), gomock.Any(), gomock.Any()).Return(map[int]map[string]string{
2: {
models.PARTNER_ID: "2",
Expand Down Expand Up @@ -4489,7 +4489,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) {
cache: mockCache,
metricEngine: mockEngine,
},
setup: func() {
setup: func(mockEngine *mock_metrics.MockMetricsEngine) {
mockCache.EXPECT().GetPartnerConfigMap(gomock.Any(), gomock.Any(), gomock.Any()).Return(map[int]map[string]string{
2: {
models.PARTNER_ID: "2",
Expand Down Expand Up @@ -4539,7 +4539,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) {
cache: mockCache,
metricEngine: mockEngine,
},
setup: func() {
setup: func(mockEngine *mock_metrics.MockMetricsEngine) {
mockCache.EXPECT().GetPartnerConfigMap(gomock.Any(), gomock.Any(), gomock.Any()).Return(map[int]map[string]string{
2: {
models.PARTNER_ID: "2",
Expand Down Expand Up @@ -4619,7 +4619,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) {
cache: mockCache,
metricEngine: mockEngine,
},
setup: func() {
setup: func(mockEngine *mock_metrics.MockMetricsEngine) {
mockCache.EXPECT().GetPartnerConfigMap(gomock.Any(), gomock.Any(), gomock.Any()).Return(map[int]map[string]string{
2: {
models.PARTNER_ID: "2",
Expand Down Expand Up @@ -4715,7 +4715,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) {
cache: mockCache,
metricEngine: mockEngine,
},
setup: func() {
setup: func(mockEngine *mock_metrics.MockMetricsEngine) {
mockCache.EXPECT().GetPartnerConfigMap(gomock.Any(), gomock.Any(), gomock.Any()).Return(map[int]map[string]string{
2: {
models.PARTNER_ID: "2",
Expand Down Expand Up @@ -4830,7 +4830,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) {
cache: mockCache,
metricEngine: mockEngine,
},
setup: func() {
setup: func(mockEngine *mock_metrics.MockMetricsEngine) {
mockCache.EXPECT().GetPartnerConfigMap(gomock.Any(), gomock.Any(), gomock.Any()).Return(map[int]map[string]string{
2: {
models.PREBID_PARTNER_NAME: "appnexus",
Expand Down Expand Up @@ -4909,7 +4909,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) {
cache: mockCache,
metricEngine: mockEngine,
},
setup: func() {
setup: func(mockEngine *mock_metrics.MockMetricsEngine) {
mockCache.EXPECT().GetMappingsFromCacheV25(gomock.Any(), gomock.Any()).Return(map[string]models.SlotMapping{
"adunit@700x900": {
SlotName: "adunit@700x900",
Expand Down Expand Up @@ -5030,7 +5030,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) {
cache: mockCache,
metricEngine: mockEngine,
},
setup: func() {
setup: func(mockEngine *mock_metrics.MockMetricsEngine) {
mockCache.EXPECT().GetMappingsFromCacheV25(gomock.Any(), gomock.Any()).Return(map[string]models.SlotMapping{
"adunit@700x900": {
SlotName: "adunit@700x900",
Expand Down Expand Up @@ -5102,7 +5102,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) {
cache: mockCache,
metricEngine: mockEngine,
},
setup: func() {
setup: func(mockEngine *mock_metrics.MockMetricsEngine) {
mockEngine.EXPECT().RecordBadRequests(models.EndpointV25, "1234", 18)
mockEngine.EXPECT().RecordNobidErrPrebidServerRequests("1234", 604)
},
Expand Down Expand Up @@ -5130,7 +5130,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) {
cache: mockCache,
metricEngine: mockEngine,
},
setup: func() {
setup: func(mockEngine *mock_metrics.MockMetricsEngine) {
mockEngine.EXPECT().RecordBadRequests(models.EndpointV25, "1234", 18)
mockEngine.EXPECT().RecordNobidErrPrebidServerRequests("1234", 604)
},
Expand Down Expand Up @@ -5185,7 +5185,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) {
cache: mockCache,
metricEngine: mockEngine,
},
setup: func() {
setup: func(mockEngine *mock_metrics.MockMetricsEngine) {
mockCache.EXPECT().GetMappingsFromCacheV25(gomock.Any(), gomock.Any()).Return(map[string]models.SlotMapping{
"adunit@700x900": {
SlotName: "adunit@700x900",
Expand Down Expand Up @@ -5302,7 +5302,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) {
cache: mockCache,
metricEngine: mockEngine,
},
setup: func() {
setup: func(mockEngine *mock_metrics.MockMetricsEngine) {
mockCache.EXPECT().GetMappingsFromCacheV25(gomock.Any(), gomock.Any()).Return(map[string]models.SlotMapping{
"adunit@0x0": {
SlotName: "adunit@0x0",
Expand Down Expand Up @@ -5439,7 +5439,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) {
cache: mockCache,
metricEngine: mockEngine,
},
setup: func() {
setup: func(mockEngine *mock_metrics.MockMetricsEngine) {
mockCache.EXPECT().GetMappingsFromCacheV25(gomock.Any(), gomock.Any()).Return(map[string]models.SlotMapping{
"adunit@0x0": {
SlotName: "adunit@0x0",
Expand Down Expand Up @@ -5545,7 +5545,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) {
cache: mockCache,
metricEngine: mockEngine,
},
setup: func() {
setup: func(mockEngine *mock_metrics.MockMetricsEngine) {
mockCache.EXPECT().GetMappingsFromCacheV25(gomock.Any(), gomock.Any()).Return(map[string]models.SlotMapping{
"adunit@700x900": {
SlotName: "adunit@700x900",
Expand Down Expand Up @@ -5587,8 +5587,10 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) {
mockFeature.EXPECT().IsMaxFloorsEnabled(gomock.Any()).Return(false)
mockFeature.EXPECT().IsMBMFCountry(gomock.Any()).Return(true)
mockFeature.EXPECT().IsMBMFPublisherEnabled(gomock.Any()).Return(true)
mockFeature.EXPECT().IsPubIdMBMFPhase1Enabled(5890).Return(false)
mockFeature.EXPECT().GetProfileAdUnitMultiFloors(1234).Return(map[string]*models.MultiFloors{"adunit": {IsActive: true, Tier1: 1.1, Tier2: 2.1, Tier3: 3.1}})
mockProfileMetaData.EXPECT().GetProfileTypePlatform(gomock.Any()).Return(0, false)
mockEngine.EXPECT().RecordMBMFRequests("5890", 0)
},
want: want{
hookResult: hookstage.HookResult[hookstage.BeforeValidationRequestPayload]{
Expand All @@ -5608,7 +5610,7 @@ func TestOpenWrapHandleBeforeValidationHook(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.setup != nil {
tt.setup()
tt.setup(mockEngine)
}
m := OpenWrap{
cfg: tt.fields.cfg,
Expand Down
1 change: 1 addition & 0 deletions modules/pubmatic/openwrap/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Cache interface {
GetAppSubIntegrationPaths() (map[string]int, error)
GetGDPRCountryCodes() (models.HashSet, error)
GetProfileAdUnitMultiFloors() (models.ProfileAdUnitMultiFloors, error)
GetMBMFPhase1PubId() (map[int]struct{}, error)

Set(key string, value interface{})
Get(key string) (interface{}, bool)
Expand Down
11 changes: 11 additions & 0 deletions modules/pubmatic/openwrap/cache/gocache/mbmf.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,14 @@ func (c *cache) GetProfileAdUnitMultiFloors() (models.ProfileAdUnitMultiFloors,
}
return profileAdUnitMultiFloors, nil
}

// GetMBMFPhase1PubId returns phase1pubidmultifloors fetched from DB which will be saved in publisherFeatureMap
func (c *cache) GetMBMFPhase1PubId() (map[int]struct{}, error) {
pubIdMultiFloors, err := c.db.GetMBMFPhase1PubId()
if err != nil {
c.metricEngine.RecordDBQueryFailure(models.MBMFPhase1PubIdQuery, "", "")
glog.Errorf(models.ErrDBQueryFailed, models.MBMFPhase1PubIdQuery, "", "", err)
return pubIdMultiFloors, err
}
return pubIdMultiFloors, nil
}
15 changes: 15 additions & 0 deletions modules/pubmatic/openwrap/cache/mock/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions modules/pubmatic/openwrap/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type Queries struct {
GetGDPRCountryCodes string
GetBannerSizesQuery string
GetProfileAdUnitMultiFloors string
GetMBMFPhase1PubId string
}

type Cache struct {
Expand Down
1 change: 1 addition & 0 deletions modules/pubmatic/openwrap/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ type Database interface {
GetAppSubIntegrationPaths() (map[string]int, error)
GetGDPRCountryCodes() (models.HashSet, error)
GetProfileAdUnitMultiFloors() (models.ProfileAdUnitMultiFloors, error)
GetMBMFPhase1PubId() (map[int]struct{}, error)
}
15 changes: 15 additions & 0 deletions modules/pubmatic/openwrap/database/mock/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions modules/pubmatic/openwrap/database/mysql/mbmf.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,32 @@ func (db *mySqlDB) GetProfileAdUnitMultiFloors() (models.ProfileAdUnitMultiFloor
}
return profileAdUnitMultiFloors, nil
}

func (db *mySqlDB) GetMBMFPhase1PubId() (map[int]struct{}, error) {
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.GetMBMFPhase1PubId)
if err != nil {
return nil, err
}
defer rows.Close()

var (
pubId int
// map to store the pubIds
pubIds = make(map[int]struct{})
)
for rows.Next() {
if err := rows.Scan(&pubId); err != nil {
glog.Errorf(models.ErrDBRowScanFailed, models.MBMFPhase1PubIdQuery, "", "", err.Error())
continue
}
pubIds[pubId] = struct{}{}
}

if err = rows.Err(); err != nil {
return nil, err
}
return pubIds, nil
}
7 changes: 7 additions & 0 deletions modules/pubmatic/openwrap/metrics/config/multimetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,13 @@ func (me *MultiMetricsEngine) RecordUnwrapRespTime(accountId, wraperCnt string,
}
}

// RecordMBMFRequests record MBMF requests
func (me *MultiMetricsEngine) RecordMBMFRequests(pubId string, errorCode int) {
for _, thisME := range *me {
thisME.RecordMBMFRequests(pubId, errorCode)
}
}

// RecordAnalyticsTrackingThrottled record analytics throttling at publisher profile level
func (me *MultiMetricsEngine) RecordAnalyticsTrackingThrottled(pubid, profileid, analyticsType string) {
for _, thisME := range *me {
Expand Down
2 changes: 2 additions & 0 deletions modules/pubmatic/openwrap/metrics/config/multimetrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ func TestRecordFunctionForMultiMetricsEngine(t *testing.T) {
mockEngine.EXPECT().RecordBidRecoveryStatus(publisher, profile, true)
mockEngine.EXPECT().RecordBidRecoveryResponseTime(publisher, profile, time.Duration(200))
mockEngine.EXPECT().RecordGeoLookupFailure("geo")
mockEngine.EXPECT().RecordMBMFRequests("pubid", 1)

// create the multi-metric engine
multiMetricEngine := MultiMetricsEngine{}
Expand Down Expand Up @@ -296,4 +297,5 @@ func TestRecordFunctionForMultiMetricsEngine(t *testing.T) {
multiMetricEngine.RecordBidRecoveryStatus(publisher, profile, true)
multiMetricEngine.RecordBidRecoveryResponseTime(publisher, profile, time.Duration(200))
multiMetricEngine.RecordGeoLookupFailure("geo")
multiMetricEngine.RecordMBMFRequests("pubid", 1)
}
1 change: 1 addition & 0 deletions modules/pubmatic/openwrap/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ type MetricsEngine interface {
RecordFailedParsingItuneID(pubId, profId string)
RecordEndpointResponseSize(endpoint string, bodySize float64)
RecordGeoLookupFailure(endpoint string)
RecordMBMFRequests(pubId string, errorCode int)

//IBV metric
RecordIBVRequest(pubId, profId string)
Expand Down
12 changes: 12 additions & 0 deletions modules/pubmatic/openwrap/metrics/mock/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading