Skip to content

Commit

Permalink
Debug disable feature implementation: (#1677)
Browse files Browse the repository at this point in the history
Co-authored-by: Veronika Solovei <[email protected]>
  • Loading branch information
VeronikaSolovei9 and Veronika Solovei authored Jan 28, 2021
1 parent c276b58 commit 01645db
Show file tree
Hide file tree
Showing 17 changed files with 393 additions and 161 deletions.
5 changes: 5 additions & 0 deletions adapters/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ type BidderInfo struct {
Capabilities *CapabilitiesInfo `yaml:"capabilities" json:"capabilities"`
AliasOf string `json:"aliasOf,omitempty"`
ModifyingVastXmlAllowed bool `yaml:"modifyingVastXmlAllowed" json:"-" xml:"-"`
Debug *DebugInfo `yaml:"debug,omitempty" json:"-" xml:"-"`
}

type DebugInfo struct {
Allow bool `yaml:"allow" json:"allow"`
}

type MaintainerInfo struct {
Expand Down
1 change: 1 addition & 0 deletions config/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Account struct {
EventsEnabled bool `mapstructure:"events_enabled" json:"events_enabled"`
CCPA AccountCCPA `mapstructure:"ccpa" json:"ccpa"`
GDPR AccountGDPR `mapstructure:"gdpr" json:"gdpr"`
DebugAllow bool `mapstructure:"debug_allow" json:"debug_allow"`
}

// AccountCCPA represents account-specific CCPA configuration
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,7 @@ func SetupViper(v *viper.Viper, filename string) {
v.SetDefault("blacklisted_accts", []string{""})
v.SetDefault("account_required", false)
v.SetDefault("account_defaults.disabled", false)
v.SetDefault("account_defaults.debug_allow", true)
v.SetDefault("certificates_file", "")
v.SetDefault("auto_gen_source_tid", true)

Expand Down
7 changes: 6 additions & 1 deletion exchange/adapter_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ func buildExchangeBidders(cfg *config.Configuration, infos adapters.BidderInfos,

exchangeBidders := make(map[openrtb_ext.BidderName]adaptedBidder, len(bidders))
for bidderName, bidder := range bidders {
exchangeBidders[bidderName] = adaptBidder(bidder, client, cfg, me, bidderName)
info, infoFound := infos[string(bidderName)]
if !infoFound {
errs = append(errs, fmt.Errorf("%v: bidder info not found", bidder))
continue
}
exchangeBidders[bidderName] = adaptBidder(bidder, client, cfg, me, bidderName, info.Debug)
}

return exchangeBidders, nil
Expand Down
8 changes: 4 additions & 4 deletions exchange/adapter_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestBuildAdaptersSuccess(t *testing.T) {

appnexusBidder, _ := appnexus.Builder(openrtb_ext.BidderAppnexus, config.Adapter{})
appnexusBidderWithInfo := adapters.EnforceBidderInfo(appnexusBidder, infoActive)
appnexusBidderAdapted := adaptBidder(appnexusBidderWithInfo, client, &config.Configuration{}, metricEngine, openrtb_ext.BidderAppnexus)
appnexusBidderAdapted := adaptBidder(appnexusBidderWithInfo, client, &config.Configuration{}, metricEngine, openrtb_ext.BidderAppnexus, nil)
appnexusBidderValidated := addValidatedBidderMiddleware(appnexusBidderAdapted)

idLegacyAdapted := &adaptedAdapter{lifestreet.NewLifestreetLegacyAdapter(adapters.DefaultHTTPAdapterConfig, "anyEndpoint")}
Expand Down Expand Up @@ -77,11 +77,11 @@ func TestBuildExchangeBidders(t *testing.T) {

appnexusBidder, _ := appnexus.Builder(openrtb_ext.BidderAppnexus, config.Adapter{})
appnexusBidderWithInfo := adapters.EnforceBidderInfo(appnexusBidder, infoActive)
appnexusBidderAdapted := adaptBidder(appnexusBidderWithInfo, client, &config.Configuration{}, metricEngine, openrtb_ext.BidderAppnexus)
appnexusBidderAdapted := adaptBidder(appnexusBidderWithInfo, client, &config.Configuration{}, metricEngine, openrtb_ext.BidderAppnexus, nil)

rubiconBidder, _ := rubicon.Builder(openrtb_ext.BidderRubicon, config.Adapter{})
rubiconBidderWithInfo := adapters.EnforceBidderInfo(rubiconBidder, infoActive)
rubiconBidderAdapted := adaptBidder(rubiconBidderWithInfo, client, &config.Configuration{}, metricEngine, openrtb_ext.BidderRubicon)
rubiconBidderAdapted := adaptBidder(rubiconBidderWithInfo, client, &config.Configuration{}, metricEngine, openrtb_ext.BidderRubicon, nil)

testCases := []struct {
description string
Expand Down Expand Up @@ -397,7 +397,7 @@ func TestGetDisabledBiddersErrorMessages(t *testing.T) {

type fakeAdaptedBidder struct{}

func (fakeAdaptedBidder) requestBid(ctx context.Context, request *openrtb.BidRequest, name openrtb_ext.BidderName, bidAdjustment float64, conversions currency.Conversions, reqInfo *adapters.ExtraRequestInfo) (*pbsOrtbSeatBid, []error) {
func (fakeAdaptedBidder) requestBid(ctx context.Context, request *openrtb.BidRequest, name openrtb_ext.BidderName, bidAdjustment float64, conversions currency.Conversions, reqInfo *adapters.ExtraRequestInfo, accountDebugAllowed bool) (*pbsOrtbSeatBid, []error) {
return nil, nil
}

Expand Down
25 changes: 20 additions & 5 deletions exchange/bidder.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type adaptedBidder interface {
//
// Any errors will be user-facing in the API.
// Error messages should help publishers understand what might account for "bad" bids.
requestBid(ctx context.Context, request *openrtb.BidRequest, name openrtb_ext.BidderName, bidAdjustment float64, conversions currency.Conversions, reqInfo *adapters.ExtraRequestInfo) (*pbsOrtbSeatBid, []error)
requestBid(ctx context.Context, request *openrtb.BidRequest, name openrtb_ext.BidderName, bidAdjustment float64, conversions currency.Conversions, reqInfo *adapters.ExtraRequestInfo, accountDebugAllowed bool) (*pbsOrtbSeatBid, []error)
}

// pbsOrtbBid is a Bid returned by an adaptedBidder.
Expand Down Expand Up @@ -93,7 +93,7 @@ type pbsOrtbSeatBid struct {
//
// The name refers to the "Adapter" architecture pattern, and should not be confused with a Prebid "Adapter"
// (which is being phased out and replaced by Bidder for OpenRTB auctions)
func adaptBidder(bidder adapters.Bidder, client *http.Client, cfg *config.Configuration, me metrics.MetricsEngine, name openrtb_ext.BidderName) adaptedBidder {
func adaptBidder(bidder adapters.Bidder, client *http.Client, cfg *config.Configuration, me metrics.MetricsEngine, name openrtb_ext.BidderName, debugInfo *adapters.DebugInfo) adaptedBidder {
return &bidderAdapter{
Bidder: bidder,
BidderName: name,
Expand All @@ -102,10 +102,18 @@ func adaptBidder(bidder adapters.Bidder, client *http.Client, cfg *config.Config
config: bidderAdapterConfig{
Debug: cfg.Debug,
DisableConnMetrics: cfg.Metrics.Disabled.AdapterConnectionMetrics,
DebugInfo: adapters.DebugInfo{Allow: parseDebugInfo(debugInfo)},
},
}
}

func parseDebugInfo(info *adapters.DebugInfo) bool {
if info == nil {
return true
}
return info.Allow
}

type bidderAdapter struct {
Bidder adapters.Bidder
BidderName openrtb_ext.BidderName
Expand All @@ -117,9 +125,10 @@ type bidderAdapter struct {
type bidderAdapterConfig struct {
Debug config.Debug
DisableConnMetrics bool
DebugInfo adapters.DebugInfo
}

func (bidder *bidderAdapter) requestBid(ctx context.Context, request *openrtb.BidRequest, name openrtb_ext.BidderName, bidAdjustment float64, conversions currency.Conversions, reqInfo *adapters.ExtraRequestInfo) (*pbsOrtbSeatBid, []error) {
func (bidder *bidderAdapter) requestBid(ctx context.Context, request *openrtb.BidRequest, name openrtb_ext.BidderName, bidAdjustment float64, conversions currency.Conversions, reqInfo *adapters.ExtraRequestInfo, accountDebugAllowed bool) (*pbsOrtbSeatBid, []error) {
reqData, errs := bidder.Bidder.MakeRequests(request, reqInfo)

if len(reqData) == 0 {
Expand Down Expand Up @@ -155,8 +164,14 @@ func (bidder *bidderAdapter) requestBid(ctx context.Context, request *openrtb.Bi
for i := 0; i < len(reqData); i++ {
httpInfo := <-responseChannel
// If this is a test bid, capture debugging info from the requests.
if debugInfo := ctx.Value(DebugContextKey); debugInfo != nil && debugInfo.(bool) {
seatBid.httpCalls = append(seatBid.httpCalls, makeExt(httpInfo))
// Write debug data to ext in case if:
// - debugContextKey (url param) in true
// - account debug is allowed
// - bidder debug is allowed
if accountDebugAllowed && bidder.config.DebugInfo.Allow {
if debugInfo := ctx.Value(DebugContextKey); debugInfo != nil && debugInfo.(bool) {
seatBid.httpCalls = append(seatBid.httpCalls, makeExt(httpInfo))
}
}

if httpInfo.err == nil {
Expand Down
Loading

0 comments on commit 01645db

Please sign in to comment.