Skip to content

Commit

Permalink
Merge branch 'ci' of github.com:PubMatic-OpenWrap/prebid-server into …
Browse files Browse the repository at this point in the history
…OTT-1687
  • Loading branch information
ashishshinde-pubm committed Mar 28, 2024
2 parents e08c86f + e457fe2 commit 3582ee7
Show file tree
Hide file tree
Showing 14 changed files with 159 additions and 14 deletions.
8 changes: 4 additions & 4 deletions floors/floors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -169,15 +169,15 @@ 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,
err: "Invalid Floor Model = 'version11' due to SkipRate = '110' is out of range (1-100)",
expFloorVal: 11.01,
expFloorCur: "USD",
expPriceFlrLoc: openrtb_ext.RequestLocation,
expSchemaVersion: "2",
expSchemaVersion: 2,
},
{
name: "Rule selection with Site object, banner|300x600|www.website.com",
Expand Down Expand Up @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion floors/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
17 changes: 15 additions & 2 deletions floors/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",

Expand All @@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions modules/pubmatic/openwrap/database/mysql/partner_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func Test_mySqlDB_GetActivePartnerConfigurations(t *testing.T) {
"serverSideEnabled": "1",
"isAlias": "0",
"partnerId": "234",
"vendorId": "999",
"vendorId": "546",
},
101: {
"bidderCode": "pubmatic",
Expand Down Expand Up @@ -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
},
Expand Down
14 changes: 14 additions & 0 deletions modules/pubmatic/openwrap/metrics/config/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
4 changes: 4 additions & 0 deletions modules/pubmatic/openwrap/metrics/config/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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")
}
2 changes: 2 additions & 0 deletions modules/pubmatic/openwrap/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
24 changes: 24 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.

2 changes: 2 additions & 0 deletions modules/pubmatic/openwrap/metrics/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ type Metrics struct {
panicCounts *prometheus.CounterVec
sendLoggerData *prometheus.HistogramVec
owRequestTime *prometheus.HistogramVec
ampVideoRequests *prometheus.CounterVec
ampVideoResponses *prometheus.CounterVec
}

const (
Expand Down
26 changes: 26 additions & 0 deletions modules/pubmatic/openwrap/metrics/prometheus/prometheus_sshb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
})
}
}
2 changes: 2 additions & 0 deletions modules/pubmatic/openwrap/metrics/stats/tcp_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
2 changes: 1 addition & 1 deletion openrtb_ext/floors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit 3582ee7

Please sign in to comment.