From a33f1a0429c5e6f47777905aa85c89ab3e1d1c2f Mon Sep 17 00:00:00 2001 From: Saurabh Narkhede <108730956+pm-saurabh-narkhede@users.noreply.github.com> Date: Tue, 26 Mar 2024 15:26:56 +0530 Subject: [PATCH 1/3] UOE-10050: fetch vendorId for VastBidder from db (#708) --- modules/pubmatic/openwrap/database/mysql/partner_config.go | 4 +--- .../pubmatic/openwrap/database/mysql/partner_config_test.go | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/modules/pubmatic/openwrap/database/mysql/partner_config.go b/modules/pubmatic/openwrap/database/mysql/partner_config.go index 558e0326e53..8a423f0a407 100644 --- a/modules/pubmatic/openwrap/database/mysql/partner_config.go +++ b/modules/pubmatic/openwrap/database/mysql/partner_config.go @@ -65,9 +65,7 @@ func (db *mySqlDB) getActivePartnerConfigurations(versionID int) (map[int]map[st partnerConfigMap[partnerID][models.PREBID_PARTNER_NAME] = prebidPartnerName partnerConfigMap[partnerID][models.BidderCode] = bidderCode partnerConfigMap[partnerID][models.IsAlias] = strconv.Itoa(isAlias) - if prebidPartnerName != models.BidderVASTBidder { - partnerConfigMap[partnerID][models.VENDORID] = strconv.Itoa(vendorID) - } + partnerConfigMap[partnerID][models.VENDORID] = strconv.Itoa(vendorID) } } diff --git a/modules/pubmatic/openwrap/database/mysql/partner_config_test.go b/modules/pubmatic/openwrap/database/mysql/partner_config_test.go index 4b12b311c3f..ea9f5e57159 100644 --- a/modules/pubmatic/openwrap/database/mysql/partner_config_test.go +++ b/modules/pubmatic/openwrap/database/mysql/partner_config_test.go @@ -227,7 +227,7 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) { "serverSideEnabled": "1", "isAlias": "0", "partnerId": "234", - "vendorId": "999", + "vendorId": "546", }, 101: { "bidderCode": "pubmatic", @@ -266,8 +266,8 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) { AddRow("101", "pubmatic", "pubmatic", 0, 3, 0, 76, "kgp", "_AU_@_W_x_H_"). AddRow("101", "pubmatic", "pubmatic", 0, 3, 0, 76, "timeout", "200"). AddRow("101", "pubmatic", "pubmatic", 0, 3, 0, 76, "serverSideEnabled", "1"). - AddRow("234", "vastbidder", "test-vastbidder", 0, 3, 0, -1, "serverSideEnabled", "1"). - AddRow("234", "vastbidder", "test-vastbidder", 0, 3, 0, -1, "vendorId", "999") + AddRow("234", "vastbidder", "test-vastbidder", 0, 3, 0, 546, "vendorId", "999"). + AddRow("234", "vastbidder", "test-vastbidder", 0, 3, 0, 546, "serverSideEnabled", "1") mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_config_map (.+)")).WillReturnRows(rowsPartnerConfig) return db }, From c884968746648d016f999655baceaf1e0aeb409e Mon Sep 17 00:00:00 2001 From: Jaydeep Mohite <30924180+pm-jaydeep-mohite@users.noreply.github.com> Date: Tue, 26 Mar 2024 15:56:00 +0530 Subject: [PATCH 2/3] OTT-1706: Changed datatype of FloorsSchemaVersion from string to int (#736) * OTT-1706: Changed datatype of FloorsSchemaVersion from string to int --- floors/floors_test.go | 8 ++++---- floors/validate.go | 2 +- floors/validate_test.go | 17 +++++++++++++++-- openrtb_ext/floors.go | 2 +- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/floors/floors_test.go b/floors/floors_test.go index 87ba9f2c6f5..e122ffd0ee3 100644 --- a/floors/floors_test.go +++ b/floors/floors_test.go @@ -82,7 +82,7 @@ func TestEnrichWithPriceFloors(t *testing.T) { expFloorVal float64 expFloorCur string expPriceFlrLoc string - expSchemaVersion string + expSchemaVersion int }{ { name: "Floors disabled in account config", @@ -169,7 +169,7 @@ func TestEnrichWithPriceFloors(t *testing.T) { Publisher: &openrtb2.Publisher{Domain: "www.website.com"}, }, Imp: []openrtb2.Imp{{ID: "1234", Banner: &openrtb2.Banner{Format: []openrtb2.Format{{W: 300, H: 250}}}}}, - Ext: json.RawMessage(`{"prebid":{"floors":{"floormin":11,"floormincur":"USD","data":{"currency":"USD","floorsschemaversion":"2","modelgroups":[{"modelweight":50,"modelversion":"version2","schema":{"fields":["mediaType","size","domain"],"delimiter":"|"},"values":{"*|*|*":11.01,"*|*|www.website1.com":17.01},"default":21},{"modelweight":50,"modelversion":"version11","skiprate":110,"schema":{"fields":["mediaType","size","domain"],"delimiter":"|"},"values":{"*|300x250|*":11.01,"*|300x250|www.website1.com":100.01},"default":21}]},"enforcement":{"enforcepbs":true,"floordeals":true},"enabled":true}}}`), + Ext: json.RawMessage(`{"prebid":{"floors":{"floormin":11,"floormincur":"USD","data":{"currency":"USD","floorsschemaversion":2,"modelgroups":[{"modelweight":50,"modelversion":"version2","schema":{"fields":["mediaType","size","domain"],"delimiter":"|"},"values":{"*|*|*":11.01,"*|*|www.website1.com":17.01},"default":21},{"modelweight":50,"modelversion":"version11","skiprate":110,"schema":{"fields":["mediaType","size","domain"],"delimiter":"|"},"values":{"*|300x250|*":11.01,"*|300x250|www.website1.com":100.01},"default":21}]},"enforcement":{"enforcepbs":true,"floordeals":true},"enabled":true}}}`), }, }, account: testAccountConfig, @@ -177,7 +177,7 @@ func TestEnrichWithPriceFloors(t *testing.T) { expFloorVal: 11.01, expFloorCur: "USD", expPriceFlrLoc: openrtb_ext.RequestLocation, - expSchemaVersion: "2", + expSchemaVersion: 2, }, { name: "Rule selection with Site object, banner|300x600|www.website.com", @@ -376,7 +376,7 @@ func TestEnrichWithPriceFloors(t *testing.T) { assert.Equal(t, *requestExt.GetPrebid().Floors.Skipped, tc.Skipped, tc.name) } else { assert.Equal(t, requestExt.GetPrebid().Floors.PriceFloorLocation, tc.expPriceFlrLoc, tc.name) - if tc.expSchemaVersion != "" { + if tc.expSchemaVersion != 0 { assert.Equal(t, requestExt.GetPrebid().Floors.Data.FloorsSchemaVersion, tc.expSchemaVersion, tc.name) } } diff --git a/floors/validate.go b/floors/validate.go index 5624735c852..6052ed9cfb2 100644 --- a/floors/validate.go +++ b/floors/validate.go @@ -55,7 +55,7 @@ func validateFloorRulesAndLowerValidRuleKey(schema openrtb_ext.PriceFloorSchema, // validateFloorParams validates SchemaVersion, SkipRate and FloorMin func validateFloorParams(extFloorRules *openrtb_ext.PriceFloorRules) error { - if extFloorRules.Data != nil && len(extFloorRules.Data.FloorsSchemaVersion) > 0 && extFloorRules.Data.FloorsSchemaVersion != "2" { + if extFloorRules.Data != nil && extFloorRules.Data.FloorsSchemaVersion > 0 && extFloorRules.Data.FloorsSchemaVersion != 2 { return fmt.Errorf("Invalid FloorsSchemaVersion = '%v', supported version 2", extFloorRules.Data.FloorsSchemaVersion) } diff --git a/floors/validate_test.go b/floors/validate_test.go index 96dad819e06..45ae335d5b9 100644 --- a/floors/validate_test.go +++ b/floors/validate_test.go @@ -56,9 +56,9 @@ func TestValidateFloorParams(t *testing.T) { Err: errors.New("Invalid FloorMin = '-10', value should be >= 0"), }, { - name: "Invalid FloorSchemaVersion ", + name: "Invalid FloorSchemaVersion", floorExt: &openrtb_ext.PriceFloorRules{Data: &openrtb_ext.PriceFloorData{ - FloorsSchemaVersion: "1", + FloorsSchemaVersion: 1, ModelGroups: []openrtb_ext.PriceFloorModelGroup{{ ModelVersion: "Version 1", @@ -70,6 +70,19 @@ func TestValidateFloorParams(t *testing.T) { }}}, Err: errors.New("Invalid FloorsSchemaVersion = '1', supported version 2"), }, + { + name: "Valid FloorSchemaVersion", + floorExt: &openrtb_ext.PriceFloorRules{Data: &openrtb_ext.PriceFloorData{ + FloorsSchemaVersion: 2, + ModelGroups: []openrtb_ext.PriceFloorModelGroup{{ + ModelVersion: "Version 1", + Schema: openrtb_ext.PriceFloorSchema{Fields: []string{"mediaType", "size", "domain"}, Delimiter: "|"}, + Values: map[string]float64{ + "banner|300x250|www.website.com": 1.01, + "banner|300x600|*": 4.01, + }, Default: 0.01}, + }}}, + }, } for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { diff --git a/openrtb_ext/floors.go b/openrtb_ext/floors.go index 33bb75b2550..aeec3647736 100644 --- a/openrtb_ext/floors.go +++ b/openrtb_ext/floors.go @@ -78,7 +78,7 @@ type PriceFloorEndpoint struct { type PriceFloorData struct { Currency string `json:"currency,omitempty"` SkipRate int `json:"skiprate,omitempty"` - FloorsSchemaVersion string `json:"floorsschemaversion,omitempty"` + FloorsSchemaVersion int `json:"floorsschemaversion,omitempty"` ModelTimestamp int `json:"modeltimestamp,omitempty"` ModelGroups []PriceFloorModelGroup `json:"modelgroups,omitempty"` FloorProvider string `json:"floorprovider,omitempty"` From e457fe20a2985f03c5c23fdc244815460a1c1784 Mon Sep 17 00:00:00 2001 From: pm-avinash-kapre <112699665+AvinashKapre@users.noreply.github.com> Date: Wed, 27 Mar 2024 11:43:41 +0530 Subject: [PATCH 3/3] UOE-10233: Stats for the AMP Multiformat request and response (#734) --- .../openwrap/metrics/config/metrics.go | 14 +++++ .../openwrap/metrics/config/metrics_test.go | 4 ++ modules/pubmatic/openwrap/metrics/metrics.go | 2 + .../pubmatic/openwrap/metrics/mock/mock.go | 24 ++++++++ .../openwrap/metrics/prometheus/prometheus.go | 2 + .../metrics/prometheus/prometheus_sshb.go | 26 ++++++++ .../prometheus/prometheus_sshb_test.go | 60 +++++++++++++++++++ .../openwrap/metrics/stats/tcp_stats.go | 2 + 8 files changed, 134 insertions(+) diff --git a/modules/pubmatic/openwrap/metrics/config/metrics.go b/modules/pubmatic/openwrap/metrics/config/metrics.go index cf67a7e652a..8e03aa688aa 100644 --- a/modules/pubmatic/openwrap/metrics/config/metrics.go +++ b/modules/pubmatic/openwrap/metrics/config/metrics.go @@ -445,3 +445,17 @@ func (me *MultiMetricsEngine) RecordOWServerPanic(endpoint, methodName, nodeName thisME.RecordOWServerPanic(endpoint, methodName, nodeName, podName) } } + +// RecordAmpVideoRequests across all engines +func (me *MultiMetricsEngine) RecordAmpVideoRequests(pubid, profileid string) { + for _, thisME := range *me { + thisME.RecordAmpVideoRequests(pubid, profileid) + } +} + +// RecordAmpVideoResponses across all engines +func (me *MultiMetricsEngine) RecordAmpVideoResponses(pubid, profileid string) { + for _, thisME := range *me { + thisME.RecordAmpVideoResponses(pubid, profileid) + } +} diff --git a/modules/pubmatic/openwrap/metrics/config/metrics_test.go b/modules/pubmatic/openwrap/metrics/config/metrics_test.go index 66c99b93bde..85e2b218db3 100644 --- a/modules/pubmatic/openwrap/metrics/config/metrics_test.go +++ b/modules/pubmatic/openwrap/metrics/config/metrics_test.go @@ -217,6 +217,8 @@ func TestRecordFunctionForMultiMetricsEngine(t *testing.T) { mockEngine.EXPECT().RecordSendLoggerDataTime("requestType", "profileid", time.Second) mockEngine.EXPECT().RecordRequestTime("requestType", time.Second) mockEngine.EXPECT().RecordOWServerPanic("endpoint", "methodName", "nodeName", "podName") + mockEngine.EXPECT().RecordAmpVideoRequests("pubid", "profileid") + mockEngine.EXPECT().RecordAmpVideoResponses("pubid", "profileid") // create the multi-metric engine multiMetricEngine := MultiMetricsEngine{} @@ -279,4 +281,6 @@ func TestRecordFunctionForMultiMetricsEngine(t *testing.T) { multiMetricEngine.RecordSendLoggerDataTime("requestType", "profileid", time.Second) multiMetricEngine.RecordRequestTime("requestType", time.Second) multiMetricEngine.RecordOWServerPanic("endpoint", "methodName", "nodeName", "podName") + multiMetricEngine.RecordAmpVideoRequests("pubid", "profileid") + multiMetricEngine.RecordAmpVideoResponses("pubid", "profileid") } diff --git a/modules/pubmatic/openwrap/metrics/metrics.go b/modules/pubmatic/openwrap/metrics/metrics.go index 3d00bf73219..8fb591aa643 100644 --- a/modules/pubmatic/openwrap/metrics/metrics.go +++ b/modules/pubmatic/openwrap/metrics/metrics.go @@ -72,4 +72,6 @@ type MetricsEngine interface { RecordSendLoggerDataTime(requestType, profileid string, sendTime time.Duration) RecordRequestTime(requestType string, requestTime time.Duration) RecordOWServerPanic(endpoint, methodName, nodeName, podName string) + RecordAmpVideoRequests(pubid, profileid string) + RecordAmpVideoResponses(pubid, profileid string) } diff --git a/modules/pubmatic/openwrap/metrics/mock/mock.go b/modules/pubmatic/openwrap/metrics/mock/mock.go index 03dc3b0ae19..f16a0674c71 100644 --- a/modules/pubmatic/openwrap/metrics/mock/mock.go +++ b/modules/pubmatic/openwrap/metrics/mock/mock.go @@ -89,6 +89,30 @@ func (m *MockMetricsEngine) RecordBidResponseByDealCountInPBS(arg0, arg1, arg2, m.ctrl.Call(m, "RecordBidResponseByDealCountInPBS", arg0, arg1, arg2, arg3) } +// RecordAmpVideoRequests mocks base method +func (m *MockMetricsEngine) RecordAmpVideoRequests(arg0, arg1 string) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RecordAmpVideoRequests", arg0, arg1) +} + +// RecordAmpVideoRequests indicates an expected call of RecordAmpVideoRequests +func (mr *MockMetricsEngineMockRecorder) RecordAmpVideoRequests(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RecordAmpVideoRequests", reflect.TypeOf((*MockMetricsEngine)(nil).RecordAmpVideoRequests), arg0, arg1) +} + +// RecordAmpVideoResponses mocks base method +func (m *MockMetricsEngine) RecordAmpVideoResponses(arg0, arg1 string) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RecordAmpVideoResponses", arg0, arg1) +} + +// RecordAmpVideoResponses indicates an expected call of RecordAmpVideoResponses +func (mr *MockMetricsEngineMockRecorder) RecordAmpVideoResponses(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RecordAmpVideoResponses", reflect.TypeOf((*MockMetricsEngine)(nil).RecordAmpVideoResponses), arg0, arg1) +} + // RecordBidResponseByDealCountInPBS indicates an expected call of RecordBidResponseByDealCountInPBS. func (mr *MockMetricsEngineMockRecorder) RecordBidResponseByDealCountInPBS(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() diff --git a/modules/pubmatic/openwrap/metrics/prometheus/prometheus.go b/modules/pubmatic/openwrap/metrics/prometheus/prometheus.go index 372df5cfad0..a24bc25ec16 100644 --- a/modules/pubmatic/openwrap/metrics/prometheus/prometheus.go +++ b/modules/pubmatic/openwrap/metrics/prometheus/prometheus.go @@ -67,6 +67,8 @@ type Metrics struct { panicCounts *prometheus.CounterVec sendLoggerData *prometheus.HistogramVec owRequestTime *prometheus.HistogramVec + ampVideoRequests *prometheus.CounterVec + ampVideoResponses *prometheus.CounterVec } const ( diff --git a/modules/pubmatic/openwrap/metrics/prometheus/prometheus_sshb.go b/modules/pubmatic/openwrap/metrics/prometheus/prometheus_sshb.go index bad86d6ce13..75a38220496 100644 --- a/modules/pubmatic/openwrap/metrics/prometheus/prometheus_sshb.go +++ b/modules/pubmatic/openwrap/metrics/prometheus/prometheus_sshb.go @@ -107,6 +107,16 @@ func newSSHBMetrics(metrics *Metrics, cfg *config.PrometheusMetrics, promRegistr "Counts the header-bidding server panic.", []string{nodeNameLabel, podNameLabel, methodNameLabel, endpointLabel}) + metrics.ampVideoRequests = newCounter(cfg, promRegistry, + "sshb_amp_video_requests", + "Counts the AMP video requests labeled by pub id and profile id.", + []string{pubIDLabel, profileIDLabel}) + + metrics.ampVideoResponses = newCounter(cfg, promRegistry, + "sshb_amp_video_responses", + "Counts the AMP video responses labeled by pub id and profile id.", + []string{pubIDLabel, profileIDLabel}) + preloadLabelValues(metrics) } @@ -194,6 +204,22 @@ func (m *Metrics) RecordOWServerPanic(endpoint, methodName, nodeName, podName st }).Inc() } +// RecordAmpVideoResponses counts the AMP Video requests +func (m *Metrics) RecordAmpVideoRequests(pubid, profileid string) { + m.ampVideoRequests.With(prometheus.Labels{ + pubIDLabel: pubid, + profileIDLabel: profileid, + }).Inc() +} + +// RecordAmpVideoResponses counts the AMP Video responses +func (m *Metrics) RecordAmpVideoResponses(pubid, profileid string) { + m.ampVideoResponses.With(prometheus.Labels{ + pubIDLabel: pubid, + profileIDLabel: profileid, + }).Inc() +} + func preloadLabelValues(m *Metrics) { var ( requestStatusValues = requestStatusesAsString() diff --git a/modules/pubmatic/openwrap/metrics/prometheus/prometheus_sshb_test.go b/modules/pubmatic/openwrap/metrics/prometheus/prometheus_sshb_test.go index fc3423529ff..bf3dcbfaafd 100644 --- a/modules/pubmatic/openwrap/metrics/prometheus/prometheus_sshb_test.go +++ b/modules/pubmatic/openwrap/metrics/prometheus/prometheus_sshb_test.go @@ -387,3 +387,63 @@ func TestRegisterLabelPermutations(t *testing.T) { assert.ElementsMatch(t, test.expectedLabels, resultLabels) } } + +func TestMetrics_RecordAmpVideoRequets(t *testing.T) { + m := createMetricsForTesting() + + type args struct { + pubid string + profileid string + } + tests := []struct { + name string + args args + }{ + { + name: "Record Amp Video Requests", + args: args{ + pubid: "1010", + profileid: "11", + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + m.RecordAmpVideoRequests(tt.args.pubid, tt.args.profileid) + assertCounterVecValue(t, "", "sshb_amp_video_requests", m.ampVideoRequests, float64(1), prometheus.Labels{ + pubIDLabel: tt.args.pubid, + profileIDLabel: tt.args.profileid, + }) + }) + } +} + +func TestMetrics_RecordAmpVideoResponses(t *testing.T) { + m := createMetricsForTesting() + + type args struct { + pubid string + profileid string + } + tests := []struct { + name string + args args + }{ + { + name: "Record Amp Video Requests", + args: args{ + pubid: "1010", + profileid: "11", + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + m.RecordAmpVideoResponses(tt.args.pubid, tt.args.profileid) + assertCounterVecValue(t, "", "sshb_amp_video_responses", m.ampVideoResponses, float64(1), prometheus.Labels{ + pubIDLabel: tt.args.pubid, + profileIDLabel: tt.args.profileid, + }) + }) + } +} diff --git a/modules/pubmatic/openwrap/metrics/stats/tcp_stats.go b/modules/pubmatic/openwrap/metrics/stats/tcp_stats.go index 86a1936e6f5..7fc14bd3716 100644 --- a/modules/pubmatic/openwrap/metrics/stats/tcp_stats.go +++ b/modules/pubmatic/openwrap/metrics/stats/tcp_stats.go @@ -339,3 +339,5 @@ func (st *StatsTCP) RecordCtvUaAccuracy(pubId, status string) func (st *StatsTCP) RecordSendLoggerDataTime(requestType, profileid string, sendTime time.Duration) {} func (st *StatsTCP) RecordRequestTime(requestType string, requestTime time.Duration) {} func (st *StatsTCP) RecordOWServerPanic(endpoint, methodName, nodeName, podName string) {} +func (st *StatsTCP) RecordAmpVideoRequests(pubid, profileid string) {} +func (st *StatsTCP) RecordAmpVideoResponses(pubid, profileid string) {}