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().IsApplovinMultiFloorsEnabled(5890, "1234").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
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
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.

18 changes: 18 additions & 0 deletions modules/pubmatic/openwrap/metrics/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ type Metrics struct {

//geo lookup
geoLookUpFailure *prometheus.CounterVec

//MBMF
mbmfRequests *prometheus.CounterVec
}

const (
Expand All @@ -127,6 +130,7 @@ const (
adpodImpCountLabel = "adpod_imp_count"
bidderCodeLabel = "bidder_code"
adapterCodeLabel = "adapter_code"
errorCodeLabel = "error_code"
)

var standardTimeBuckets = []float64{0.05, 0.1, 0.3, 0.75, 1}
Expand Down Expand Up @@ -337,6 +341,12 @@ func newMetrics(cfg *config.PrometheusMetrics, promRegistry *prometheus.Registry
[]string{endpointLabel, platformLabel},
)

metrics.mbmfRequests = newCounter(cfg, promRegistry,
"mbmf_requests",
"Count of mbmf requests with error code",
[]string{pubIDLabel, errorLabel},
)

metrics.ctvHTTPMethodRequests = newCounter(cfg, promRegistry,
"ctv_http_method_requests",
"Count of ctv requests specific to http methods",
Expand Down Expand Up @@ -725,6 +735,14 @@ func (m *Metrics) RecordCTVReqCountWithAdPod(publisherID, profileID string) {
}).Inc()
}

// RecordMBMFRequests records count of request in which MBMF is present based on pubid and errorcode
func (m *Metrics) RecordMBMFRequests(pubId string, errorCode int) {
m.mbmfRequests.With(prometheus.Labels{
pubIDLabel: pubId,
errorLabel: strconv.Itoa(errorCode),
}).Inc()
}

func (m *Metrics) RecordRequestAdPodGeneratedImpressionsCount(impCount int, publisherID string) {}
func (m *Metrics) RecordAdPodImpressionYield(maxDuration int, minDuration int, publisherID string) {}
func (m *Metrics) RecordStatsKeyCTVPrebidFailedImpression(errorcode int, publisherID string, profile string) {
Expand Down
1 change: 1 addition & 0 deletions modules/pubmatic/openwrap/metrics/stats/tcp_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,4 @@ func (st *StatsTCP) RecordFailedParsingItuneID(pubId, profId string)
func (st *StatsTCP) RecordEndpointResponseSize(endpoint string, bodySize float64) {}
func (st *StatsTCP) RecordIBVRequest(pubId, profId string) {}
func (st *StatsTCP) RecordGeoLookupFailure(endpoint string) {}
func (st *StatsTCP) RecordMBMFRequests(pubId string, errorCode int) {}
36 changes: 30 additions & 6 deletions modules/pubmatic/openwrap/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ var (
protocols = []adcom1.MediaCreativeSubtype{adcom1.CreativeVAST30, adcom1.CreativeVAST30Wrapper, adcom1.CreativeVAST40, adcom1.CreativeVAST40Wrapper}
)

const (
MBMFSuccess = 0
MBMFCountryDisabled = 1
MBMFPubDisabled = 2
MBMFAdformatDisabled = 3
MBMFAdunitDisabled = 4
MBMFAdformatNotFound = 5
MBMFNoEntryFound = 6
)

func init() {
widthRegEx = regexp.MustCompile(models.MACRO_WIDTH)
heightRegEx = regexp.MustCompile(models.MACRO_HEIGHT)
Expand Down Expand Up @@ -612,14 +622,18 @@ func (m OpenWrap) getMultiFloors(rctx models.RequestCtx, reward *int8, imp openr
if rctx.Endpoint != models.EndpointAppLovinMax {
return nil
}

if !m.pubFeatures.IsMBMFCountry(rctx.DeviceCtx.DerivedCountryCode) {
return nil
IsPubIdMBMFPhase1Enabled := m.pubFeatures.IsApplovinMultiFloorsEnabled(rctx.PubID, rctx.ProfileIDStr)
if !IsPubIdMBMFPhase1Enabled {
if !m.pubFeatures.IsMBMFCountry(rctx.DeviceCtx.DerivedCountryCode) {
glog.Warning("MBMF Country Filtering Applied for pubid: %s, country: %s IID = %s", rctx.PubID, rctx.DeviceCtx.DerivedCountryCode, rctx.LoggerImpressionID)
m.metricEngine.RecordMBMFRequests(rctx.PubIDStr, MBMFCountryDisabled)
return nil
}
}

//if pub entry present with is_enabled=1 AND no pub in mbmf_enabled wrapper_feature-> apply mbmf
//if pub entry present as is_enabled=0 -> don't apply mbmf
if !m.pubFeatures.IsMBMFPublisherEnabled(rctx.PubID) {
m.metricEngine.RecordMBMFRequests(rctx.PubIDStr, MBMFPubDisabled)
return nil
}

Expand All @@ -628,6 +642,7 @@ func (m OpenWrap) getMultiFloors(rctx models.RequestCtx, reward *int8, imp openr
adunitFormat := getAdunitFormat(reward, imp)
//don't apply mbmf if pub is not enabled for adunitFormat
if adunitFormat != "" && !m.pubFeatures.IsMBMFEnabledForAdUnitFormat(rctx.PubID, adunitFormat) {
m.metricEngine.RecordMBMFRequests(rctx.PubIDStr, MBMFAdformatDisabled)
return nil
}

Expand All @@ -636,16 +651,25 @@ func (m OpenWrap) getMultiFloors(rctx models.RequestCtx, reward *int8, imp openr
if multifloors, ok := adunitLevelMultiFloors[imp.TagID]; ok && multifloors != nil {
//if profile adunitlevel floors present and is_active=0, don't apply mbmf
if !multifloors.IsActive {
m.metricEngine.RecordMBMFRequests(rctx.PubIDStr, MBMFAdunitDisabled)
return nil
}
m.metricEngine.RecordMBMFRequests(rctx.PubIDStr, MBMFSuccess)
return multifloors
}
//fallback to adunitformat multifloors if adunitlevel floors not present in DB
}

//ad unit level MBMF not found. Hence, looking up at adformat level
if adunitFormat != "" {
//return adunitformat multifloors for pubid, if not present then return default multifloors
return m.pubFeatures.GetMBMFFloorsForAdUnitFormat(rctx.PubID, adunitFormat)
multiFloors := m.pubFeatures.GetMBMFFloorsForAdUnitFormat(rctx.PubID, adunitFormat)
if multiFloors == nil {
m.metricEngine.RecordMBMFRequests(rctx.PubIDStr, MBMFAdformatNotFound)
return nil
}
m.metricEngine.RecordMBMFRequests(rctx.PubIDStr, MBMFSuccess)
return multiFloors
}
m.metricEngine.RecordMBMFRequests(rctx.PubIDStr, MBMFNoEntryFound)
return nil
}
Loading
Loading