Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Native-Specific Metrics to Prebid Server #930

Merged
merged 19 commits into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions endpoints/openrtb2/amp_auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ func (deps *endpointDeps) AmpAuction(w http.ResponseWriter, r *http.Request, _ h
labels := pbsmetrics.Labels{
Source: pbsmetrics.DemandUnknown,
RType: pbsmetrics.ReqTypeAMP,
IsImpBanner: false,
IsImpVideo: false,
IsImpAudio: false,
IsImpNative: false,
PubID: "",
Browser: pbsmetrics.BrowserOther,
CookieFlag: pbsmetrics.CookieFlagUnknown,
Expand Down
4 changes: 4 additions & 0 deletions endpoints/openrtb2/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ func (deps *endpointDeps) Auction(w http.ResponseWriter, r *http.Request, _ http
labels := pbsmetrics.Labels{
Source: pbsmetrics.DemandUnknown,
RType: pbsmetrics.ReqTypeORTB2Web,
IsImpBanner: false,
IsImpVideo: false,
IsImpAudio: false,
IsImpNative: false,
PubID: "",
Browser: pbsmetrics.BrowserOther,
CookieFlag: pbsmetrics.CookieFlagUnknown,
Expand Down
4 changes: 4 additions & 0 deletions endpoints/openrtb2/video_auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ func (deps *endpointDeps) VideoAuctionEndpoint(w http.ResponseWriter, r *http.Re
labels := pbsmetrics.Labels{
Source: pbsmetrics.DemandUnknown,
RType: pbsmetrics.ReqTypeVideo,
IsImpBanner: false,
IsImpVideo: false,
IsImpAudio: false,
IsImpNative: false,
PubID: "",
Browser: pbsmetrics.BrowserOther,
CookieFlag: pbsmetrics.CookieFlagUnknown,
Expand Down
62 changes: 62 additions & 0 deletions exchange/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,68 @@ func (e *exchange) HoldAuction(ctx context.Context, bidRequest *openrtb.BidReque
}
}

// Before the `cleanOpenRTBRequests(..)` function runs, let's set the labels.RType value here because this is a place common to all endpoints.
/* labels.RType must be extracted from bidRequest.Imp object
type Imp struct {
.
.
Banner *Banner `json:"banner,omitempty"`

// Attribute:
// video
// Type:
// object
// Description:
// A Video object (Section 3.2.7); required if this impression is
// offered as a video ad opportunity.
Video *Video `json:"video,omitempty"`

// Attribute:
// audio
// Type:
// object
// Description:
// An Audio object (Section 3.2.8); required if this impression is
// offered as an audio ad opportunity.
Audio *Audio `json:"audio,omitempty"`

// Attribute:
// native
// Type:
// object
// Description:
// A Native object (Section 3.2.9); required if this impression is
// offered as a native ad opportunity.
Native *Native `json:"native,omitempty"`
.
.
}
Since:
"Hans Hjort [2:58 PM]
More complicated than that, as the type can have multiple simultaneous values.
Might be best to have 4 flags, `isNative`, `isBanner`, `isVideo`, and `isAudio`."
Then:
We can just turn on flags here if the Imp has some other type in there
IsImpBanner: false,
IsImpVideo: false,
IsImpAudio: false,
IsImpNative: false,
*/
for _, impInRequest := range bidRequest.Imp {
guscarreon marked this conversation as resolved.
Show resolved Hide resolved
if impInRequest.Banner != nil {
labels.IsImpBanner = true
}
if impInRequest.Video != nil {
labels.IsImpVideo = true
}
if impInRequest.Audio != nil {
labels.IsImpAudio = true
}
if impInRequest.Native != nil {
labels.IsImpNative = true
}
}

// Slice of BidRequests, each a copy of the original cleaned to only contain bidder data for the named bidder
blabels := make(map[openrtb_ext.BidderName]*pbsmetrics.AdapterLabels)
cleanRequests, aliases, errs := cleanOpenRTBRequests(ctx, bidRequest, usersyncs, blabels, labels, e.gDPR, e.UsersyncIfAmbiguous)
Expand Down
19 changes: 19 additions & 0 deletions pbsmetrics/config/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func TestMultiMetricsEngine(t *testing.T) {
labels := pbsmetrics.Labels{
Source: pbsmetrics.DemandWeb,
RType: pbsmetrics.ReqTypeORTB2Web,
IsImpBanner: true,
IsImpVideo: false,
IsImpAudio: false,
IsImpNative: false,
PubID: "test1",
Browser: pbsmetrics.BrowserSafari,
CookieFlag: pbsmetrics.CookieFlagYes,
Expand All @@ -54,6 +58,10 @@ func TestMultiMetricsEngine(t *testing.T) {
apnLabels := pbsmetrics.AdapterLabels{
Source: pbsmetrics.DemandWeb,
RType: pbsmetrics.ReqTypeORTB2Web,
IsImpBanner: true,
IsImpVideo: false,
IsImpAudio: false,
IsImpNative: false,
Adapter: openrtb_ext.BidderAppnexus,
PubID: "test1",
Browser: pbsmetrics.BrowserSafari,
Expand All @@ -63,6 +71,10 @@ func TestMultiMetricsEngine(t *testing.T) {
pubLabels := pbsmetrics.AdapterLabels{
Source: pbsmetrics.DemandWeb,
RType: pbsmetrics.ReqTypeORTB2Web,
IsImpBanner: true,
IsImpVideo: false,
IsImpAudio: false,
IsImpNative: false,
Adapter: openrtb_ext.BidderPubmatic,
PubID: "test1",
Browser: pbsmetrics.BrowserSafari,
Expand All @@ -79,6 +91,7 @@ func TestMultiMetricsEngine(t *testing.T) {
metricsEngine.RecordAdapterBidReceived(pubLabels, openrtb_ext.BidTypeBanner, true)
metricsEngine.RecordAdapterTime(pubLabels, time.Millisecond*20)
}
//Make the metrics engine, instantiated here with goEngine, fill its RequestStatuses[RequestType][pbsmetrics.RequestStatusXX] with the new boolean values added to pbsmetrics.Labels
VerifyMetrics(t, "RequestStatuses.OpenRTB2.OK", goEngine.RequestStatuses[pbsmetrics.ReqTypeORTB2Web][pbsmetrics.RequestStatusOK].Count(), 5)
VerifyMetrics(t, "RequestStatuses.Legacy.OK", goEngine.RequestStatuses[pbsmetrics.ReqTypeLegacy][pbsmetrics.RequestStatusOK].Count(), 0)
VerifyMetrics(t, "RequestStatuses.AMP.OK", goEngine.RequestStatuses[pbsmetrics.ReqTypeAMP][pbsmetrics.RequestStatusOK].Count(), 0)
Expand All @@ -87,6 +100,12 @@ func TestMultiMetricsEngine(t *testing.T) {
VerifyMetrics(t, "RequestStatuses.Video.BadInput", goEngine.RequestStatuses[pbsmetrics.ReqTypeVideo][pbsmetrics.RequestStatusBadInput].Count(), 0)
VerifyMetrics(t, "RequestStatuses.OpenRTB2.Error", goEngine.RequestStatuses[pbsmetrics.ReqTypeORTB2Web][pbsmetrics.RequestStatusErr].Count(), 0)
VerifyMetrics(t, "RequestStatuses.OpenRTB2.BadInput", goEngine.RequestStatuses[pbsmetrics.ReqTypeORTB2Web][pbsmetrics.RequestStatusBadInput].Count(), 0)
//PBS-108 modify these accordingly so from the second comma on, they make sense. Modifications should probably come from the metrics.go file in here and should have a test case of their on
VerifyMetrics(t, "ImpTypeBanner", goEngine.ImpTypeBanner.Count(), 3)
VerifyMetrics(t, "ImpTypeVideo", goEngine.ImpTypeVideo.Count(), 0)
VerifyMetrics(t, "ImpTypeAudio", goEngine.ImpTypeAudio.Count(), 0)
VerifyMetrics(t, "ImpTypeNative", goEngine.ImpTypeNative.Count(), 0)

VerifyMetrics(t, "Request", goEngine.RequestStatuses[pbsmetrics.ReqTypeORTB2Web][pbsmetrics.RequestStatusOK].Count(), 5)
VerifyMetrics(t, "ImpMeter", goEngine.ImpMeter.Count(), 10)
VerifyMetrics(t, "NoCookieMeter", goEngine.NoCookieMeter.Count(), 0)
Expand Down
18 changes: 18 additions & 0 deletions pbsmetrics/go_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ type Metrics struct {
userSyncSet map[openrtb_ext.BidderName]metrics.Meter
userSyncGDPRPrevent map[openrtb_ext.BidderName]metrics.Meter

// Media types found in the "imp" JSON object
ImpTypeBanner metrics.Meter
ImpTypeVideo metrics.Meter
ImpTypeAudio metrics.Meter
ImpTypeNative metrics.Meter

AdapterMetrics map[openrtb_ext.BidderName]*AdapterMetrics
// Don't export accountMetrics because we need helper functions here to insure its properly populated dynamically
accountMetrics map[string]*accountMetrics
Expand Down Expand Up @@ -107,6 +113,11 @@ func NewBlankMetrics(registry metrics.Registry, exchanges []openrtb_ext.BidderNa
userSyncSet: make(map[openrtb_ext.BidderName]metrics.Meter),
userSyncGDPRPrevent: make(map[openrtb_ext.BidderName]metrics.Meter),

ImpTypeBanner: blankMeter,
ImpTypeVideo: blankMeter,
ImpTypeAudio: blankMeter,
ImpTypeNative: blankMeter,

AdapterMetrics: make(map[openrtb_ext.BidderName]*AdapterMetrics, len(exchanges)),
accountMetrics: make(map[string]*accountMetrics),

Expand Down Expand Up @@ -137,6 +148,13 @@ func NewMetrics(registry metrics.Registry, exchanges []openrtb_ext.BidderName) *
newMetrics.ConnectionAcceptErrorMeter = metrics.GetOrRegisterMeter("connection_accept_errors", registry)
newMetrics.ConnectionCloseErrorMeter = metrics.GetOrRegisterMeter("connection_close_errors", registry)
newMetrics.ImpMeter = metrics.GetOrRegisterMeter("imps_requested", registry)

// Find out how to GetOrRegisterMeter
newMetrics.ImpTypeBanner = metrics.GetOrRegisterMeter("imp_banner", registry)
newMetrics.ImpTypeVideo = metrics.GetOrRegisterMeter("imp_video", registry)
newMetrics.ImpTypeAudio = metrics.GetOrRegisterMeter("imp_audio", registry)
newMetrics.ImpTypeNative = metrics.GetOrRegisterMeter("imp_native", registry)

newMetrics.SafariRequestMeter = metrics.GetOrRegisterMeter("safari_requests", registry)
newMetrics.NoCookieMeter = metrics.GetOrRegisterMeter("no_cookie_requests", registry)
newMetrics.AppRequestMeter = metrics.GetOrRegisterMeter("app_requests", registry)
Expand Down
21 changes: 20 additions & 1 deletion pbsmetrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (
type Labels struct {
Source DemandSource
RType RequestType
IsImpBanner bool
IsImpVideo bool
IsImpAudio bool
IsImpNative bool
PubID string // exchange specific ID, so we cannot compile in values
Browser Browser
CookieFlag CookieFlag
Expand All @@ -19,7 +23,11 @@ type Labels struct {
// AdapterLabels defines the labels that can be attached to the adapter metrics.
type AdapterLabels struct {
Source DemandSource
RType RequestType
RType RequestType //change??
guscarreon marked this conversation as resolved.
Show resolved Hide resolved
IsImpBanner bool
IsImpVideo bool
IsImpAudio bool
IsImpNative bool
Adapter openrtb_ext.BidderName
PubID string // exchange specific ID, so we cannot compile in values
Browser Browser
Expand All @@ -33,6 +41,9 @@ type AdapterLabels struct {
// DemandSource : Demand source enumeration
type DemandSource string

// ImpMediaType : Media type described in the "imp" JSON object
type ImpMediaType string

// RequestType : Request type enumeration
type RequestType string

Expand Down Expand Up @@ -78,6 +89,14 @@ const (
ReqTypeVideo RequestType = "video"
)

// The media types described in the "imp json objects
const (
ImpTypeBanner ImpMediaType = "banner"
ImpTypeVideo ImpMediaType = "video"
ImpTypeAudio ImpMediaType = "audio"
ImpTypeNative ImpMediaType = "native"
)

func RequestTypes() []RequestType {
return []RequestType{
ReqTypeLegacy,
Expand Down