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

Refactored HoldAuction Arguments #1570

Merged
merged 6 commits into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
11 changes: 8 additions & 3 deletions endpoints/openrtb2/amp_auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func NewAmpEndpoint(
validator openrtb_ext.BidderParamValidator,
requestsById stored_requests.Fetcher,
accounts stored_requests.AccountFetcher,
categories stored_requests.CategoryFetcher,
cfg *config.Configuration,
met pbsmetrics.MetricsEngine,
pbsAnalytics analytics.PBSAnalyticsModule,
Expand All @@ -74,7 +73,6 @@ func NewAmpEndpoint(
requestsById,
empty_fetcher.EmptyFetcher{},
accounts,
categories,
cfg,
met,
pbsAnalytics,
Expand Down Expand Up @@ -185,7 +183,14 @@ func (deps *endpointDeps) AmpAuction(w http.ResponseWriter, r *http.Request, _ h
return
}

response, err := deps.ex.HoldAuction(ctx, req, usersyncs, labels, account, &deps.categories, nil)
auctionRequest := exchange.AuctionRequest{
BidRequest: req,
Account: *account,
UserSyncs: usersyncs,
RequestType: labels.RType,
}

response, err := deps.ex.HoldAuction(ctx, auctionRequest, nil)
ao.AuctionResponse = response

if err != nil {
Expand Down
22 changes: 4 additions & 18 deletions endpoints/openrtb2/amp_auction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"testing"

"github.com/prebid/prebid-server/analytics"
"github.com/prebid/prebid-server/stored_requests"
"github.com/prebid/prebid-server/stored_requests/backends/empty_fetcher"

"github.com/mxmCherry/openrtb"
Expand Down Expand Up @@ -48,7 +47,6 @@ func TestGoodAmpRequests(t *testing.T) {
newParamsValidator(t),
&mockAmpStoredReqFetcher{goodRequests},
empty_fetcher.EmptyFetcher{},
empty_fetcher.EmptyFetcher{},
&config.Configuration{MaxRequestSize: maxSize},
theMetrics,
analyticsConf.NewPBSAnalytics(&config.Analytics{}),
Expand Down Expand Up @@ -102,7 +100,6 @@ func TestAMPPageInfo(t *testing.T) {
newParamsValidator(t),
&mockAmpStoredReqFetcher{stored},
empty_fetcher.EmptyFetcher{},
empty_fetcher.EmptyFetcher{},
&config.Configuration{MaxRequestSize: maxSize},
theMetrics,
analyticsConf.NewPBSAnalytics(&config.Analytics{}),
Expand Down Expand Up @@ -208,7 +205,6 @@ func TestGDPRConsent(t *testing.T) {
newParamsValidator(t),
&mockAmpStoredReqFetcher{stored},
empty_fetcher.EmptyFetcher{},
empty_fetcher.EmptyFetcher{},
&config.Configuration{MaxRequestSize: maxSize},
metrics,
analyticsConf.NewPBSAnalytics(&config.Analytics{}),
Expand Down Expand Up @@ -362,7 +358,6 @@ func TestCCPAConsent(t *testing.T) {
newParamsValidator(t),
&mockAmpStoredReqFetcher{stored},
empty_fetcher.EmptyFetcher{},
empty_fetcher.EmptyFetcher{},
&config.Configuration{MaxRequestSize: maxSize},
metrics,
analyticsConf.NewPBSAnalytics(&config.Analytics{}),
Expand Down Expand Up @@ -422,7 +417,6 @@ func TestNoConsent(t *testing.T) {
newParamsValidator(t),
&mockAmpStoredReqFetcher{stored},
empty_fetcher.EmptyFetcher{},
empty_fetcher.EmptyFetcher{},
&config.Configuration{MaxRequestSize: maxSize},
metrics,
analyticsConf.NewPBSAnalytics(&config.Analytics{}),
Expand Down Expand Up @@ -469,7 +463,6 @@ func TestInvalidConsent(t *testing.T) {
newParamsValidator(t),
&mockAmpStoredReqFetcher{stored},
empty_fetcher.EmptyFetcher{},
empty_fetcher.EmptyFetcher{},
&config.Configuration{MaxRequestSize: maxSize},
metrics,
analyticsConf.NewPBSAnalytics(&config.Analytics{}),
Expand Down Expand Up @@ -554,7 +547,6 @@ func TestNewAndLegacyConsentBothProvided(t *testing.T) {
newParamsValidator(t),
&mockAmpStoredReqFetcher{stored},
empty_fetcher.EmptyFetcher{},
empty_fetcher.EmptyFetcher{},
&config.Configuration{MaxRequestSize: maxSize},
metrics,
analyticsConf.NewPBSAnalytics(&config.Analytics{}),
Expand Down Expand Up @@ -607,7 +599,6 @@ func TestAMPSiteExt(t *testing.T) {
newParamsValidator(t),
&mockAmpStoredReqFetcher{stored},
empty_fetcher.EmptyFetcher{},
empty_fetcher.EmptyFetcher{},
&config.Configuration{MaxRequestSize: maxSize},
theMetrics,
analyticsConf.NewPBSAnalytics(&config.Analytics{}),
Expand Down Expand Up @@ -648,7 +639,6 @@ func TestAmpBadRequests(t *testing.T) {
newParamsValidator(t),
&mockAmpStoredReqFetcher{badRequests},
empty_fetcher.EmptyFetcher{},
empty_fetcher.EmptyFetcher{},
&config.Configuration{MaxRequestSize: maxSize},
theMetrics,
analyticsConf.NewPBSAnalytics(&config.Analytics{}),
Expand Down Expand Up @@ -680,7 +670,6 @@ func TestAmpDebug(t *testing.T) {
newParamsValidator(t),
&mockAmpStoredReqFetcher{requests},
empty_fetcher.EmptyFetcher{},
empty_fetcher.EmptyFetcher{},
&config.Configuration{MaxRequestSize: maxSize},
theMetrics,
analyticsConf.NewPBSAnalytics(&config.Analytics{}),
Expand Down Expand Up @@ -754,7 +743,6 @@ func TestQueryParamOverrides(t *testing.T) {
newParamsValidator(t),
&mockAmpStoredReqFetcher{requests},
empty_fetcher.EmptyFetcher{},
empty_fetcher.EmptyFetcher{},
&config.Configuration{MaxRequestSize: maxSize},
theMetrics,
analyticsConf.NewPBSAnalytics(&config.Analytics{}),
Expand Down Expand Up @@ -907,7 +895,6 @@ func (s formatOverrideSpec) execute(t *testing.T) {
newParamsValidator(t),
&mockAmpStoredReqFetcher{requests},
empty_fetcher.EmptyFetcher{},
empty_fetcher.EmptyFetcher{},
&config.Configuration{MaxRequestSize: maxSize},
theMetrics,
analyticsConf.NewPBSAnalytics(&config.Analytics{}),
Expand Down Expand Up @@ -965,8 +952,8 @@ var expectedErrorsFromHoldAuction map[openrtb_ext.BidderName][]openrtb_ext.ExtBi
},
}

func (m *mockAmpExchange) HoldAuction(ctx context.Context, bidRequest *openrtb.BidRequest, ids exchange.IdFetcher, labels pbsmetrics.Labels, account *config.Account, categoriesFetcher *stored_requests.CategoryFetcher, debugLog *exchange.DebugLog) (*openrtb.BidResponse, error) {
m.lastRequest = bidRequest
func (m *mockAmpExchange) HoldAuction(ctx context.Context, r exchange.AuctionRequest, debugLog *exchange.DebugLog) (*openrtb.BidResponse, error) {
m.lastRequest = r.BidRequest

response := &openrtb.BidResponse{
SeatBid: []openrtb.SeatBid{{
Expand All @@ -978,8 +965,8 @@ func (m *mockAmpExchange) HoldAuction(ctx context.Context, bidRequest *openrtb.B
Ext: json.RawMessage(`{ "errors": {"openx":[ { "code": 1, "message": "The request exceeded the timeout allocated" } ] } }`),
}

if bidRequest.Test == 1 {
resolvedRequest, err := json.Marshal(bidRequest)
if r.BidRequest.Test == 1 {
resolvedRequest, err := json.Marshal(r.BidRequest)
if err != nil {
resolvedRequest = json.RawMessage("{}")
}
Expand Down Expand Up @@ -1275,7 +1262,6 @@ func TestBuildAmpObject(t *testing.T) {
newParamsValidator(t),
mockAmpFetcher,
empty_fetcher.EmptyFetcher{},
empty_fetcher.EmptyFetcher{},
&config.Configuration{MaxRequestSize: maxSize},
pbsmetrics.NewMetrics(metrics.NewRegistry(), openrtb_ext.BidderList(), config.DisabledMetrics{}),
logger,
Expand Down
13 changes: 9 additions & 4 deletions endpoints/openrtb2/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var (
dntEnabled int8 = 1
)

func NewEndpoint(ex exchange.Exchange, validator openrtb_ext.BidderParamValidator, requestsById stored_requests.Fetcher, accounts stored_requests.AccountFetcher, categories stored_requests.CategoryFetcher, cfg *config.Configuration, met pbsmetrics.MetricsEngine, pbsAnalytics analytics.PBSAnalyticsModule, disabledBidders map[string]string, defReqJSON []byte, bidderMap map[string]openrtb_ext.BidderName) (httprouter.Handle, error) {
func NewEndpoint(ex exchange.Exchange, validator openrtb_ext.BidderParamValidator, requestsById stored_requests.Fetcher, accounts stored_requests.AccountFetcher, cfg *config.Configuration, met pbsmetrics.MetricsEngine, pbsAnalytics analytics.PBSAnalyticsModule, disabledBidders map[string]string, defReqJSON []byte, bidderMap map[string]openrtb_ext.BidderName) (httprouter.Handle, error) {

if ex == nil || validator == nil || requestsById == nil || accounts == nil || cfg == nil || met == nil {
return nil, errors.New("NewEndpoint requires non-nil arguments.")
Expand All @@ -66,7 +66,6 @@ func NewEndpoint(ex exchange.Exchange, validator openrtb_ext.BidderParamValidato
requestsById,
empty_fetcher.EmptyFetcher{},
accounts,
categories,
cfg,
met,
pbsAnalytics,
Expand All @@ -85,7 +84,6 @@ type endpointDeps struct {
storedReqFetcher stored_requests.Fetcher
videoFetcher stored_requests.Fetcher
accounts stored_requests.AccountFetcher
categories stored_requests.CategoryFetcher
cfg *config.Configuration
metricsEngine pbsmetrics.MetricsEngine
analytics analytics.PBSAnalyticsModule
Expand Down Expand Up @@ -164,7 +162,14 @@ func (deps *endpointDeps) Auction(w http.ResponseWriter, r *http.Request, _ http
return
}

response, err := deps.ex.HoldAuction(ctx, req, usersyncs, labels, account, &deps.categories, nil)
auctionRequest := exchange.AuctionRequest{
BidRequest: req,
Account: *account,
UserSyncs: usersyncs,
RequestType: labels.RType,
}

response, err := deps.ex.HoldAuction(ctx, auctionRequest, nil)
ao.Request = req
ao.Response = response
ao.Account = account
Expand Down
2 changes: 1 addition & 1 deletion endpoints/openrtb2/auction_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ func BenchmarkOpenrtbEndpoint(b *testing.B) {
infos,
gdpr.AlwaysAllow{},
currencies.NewRateConverter(&http.Client{}, "", time.Duration(0)),
empty_fetcher.EmptyFetcher{},
),
paramValidator,
empty_fetcher.EmptyFetcher{},
empty_fetcher.EmptyFetcher{},
empty_fetcher.EmptyFetcher{},
&config.Configuration{MaxRequestSize: maxSize},
theMetrics,
analyticsConf.NewPBSAnalytics(&config.Analytics{}),
Expand Down
Loading