Skip to content

Commit f3f58e3

Browse files
committed
resolves merge conflict
2 parents 0283b8c + 0a34a01 commit f3f58e3

File tree

16 files changed

+759
-112
lines changed

16 files changed

+759
-112
lines changed

config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ func SetupViper(v *viper.Viper, filename string) {
954954
v.SetDefault("adapters.eplanning.endpoint", "http://rtb.e-planning.net/pbs/1")
955955
v.SetDefault("adapters.gamma.endpoint", "https://hb.gammaplatform.com/adx/request/")
956956
v.SetDefault("adapters.gamoshi.endpoint", "https://rtb.gamoshi.io")
957-
v.SetDefault("adapters.grid.endpoint", "http://grid.bidswitch.net/sp_bid?sp=prebid")
957+
v.SetDefault("adapters.grid.endpoint", "https://grid.bidswitch.net/sp_bid?sp=prebid")
958958
v.SetDefault("adapters.gumgum.endpoint", "https://g2.gumgum.com/providers/prbds2s/bid")
959959
v.SetDefault("adapters.improvedigital.endpoint", "http://ad.360yield.com/pbs")
960960
v.SetDefault("adapters.inmobi.endpoint", "https://api.w.inmobi.com/showad/openrtb/bidder/prebid")

config/stored_requests.go

Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,31 @@ const (
2222
)
2323

2424
// Section returns the config section this type is defined in
25-
func (sr *StoredRequests) Section() string {
25+
func (dataType DataType) Section() string {
2626
return map[DataType]string{
2727
RequestDataType: "stored_requests",
2828
CategoryDataType: "categories",
2929
VideoDataType: "stored_video_req",
3030
AMPRequestDataType: "stored_amp_req",
3131
AccountDataType: "accounts",
32-
}[sr.dataType]
32+
}[dataType]
33+
}
34+
35+
// Section returns the config section
36+
func (sr *StoredRequests) Section() string {
37+
return sr.dataType.Section()
3338
}
3439

40+
// DataType returns the DataType associated with this config
3541
func (sr *StoredRequests) DataType() DataType {
3642
return sr.dataType
3743
}
3844

45+
// SetDataType sets the DataType on this config. Needed for tests.
46+
func (sr *StoredRequests) SetDataType(dataType DataType) {
47+
sr.dataType = dataType
48+
}
49+
3950
// StoredRequests struct defines options for stored requests for each data type
4051
// including some amp stored_requests options
4152
type StoredRequests struct {
@@ -132,7 +143,7 @@ func (cfg *StoredRequests) validate(errs configErrors) configErrors {
132143
if cfg.DataType() == AccountDataType && cfg.Postgres.ConnectionInfo.Database != "" {
133144
errs = append(errs, fmt.Errorf("%s.postgres: retrieving accounts via postgres not available, use accounts.files", cfg.Section()))
134145
} else {
135-
errs = cfg.Postgres.validate(cfg.Section(), errs)
146+
errs = cfg.Postgres.validate(cfg.DataType(), errs)
136147
}
137148

138149
// Categories do not use cache so none of the following checks apply
@@ -156,7 +167,7 @@ func (cfg *StoredRequests) validate(errs configErrors) configErrors {
156167
errs = append(errs, fmt.Errorf("%s: postgres.initialize_caches.query must be empty if in_memory_cache=none", cfg.Section()))
157168
}
158169
}
159-
errs = cfg.InMemoryCache.validate(cfg.Section(), errs)
170+
errs = cfg.InMemoryCache.validate(cfg.DataType(), errs)
160171
return errs
161172
}
162173

@@ -169,12 +180,12 @@ type PostgresConfig struct {
169180
PollUpdates PostgresUpdatePolling `mapstructure:"poll_for_updates"`
170181
}
171182

172-
func (cfg *PostgresConfig) validate(section string, errs configErrors) configErrors {
183+
func (cfg *PostgresConfig) validate(dataType DataType, errs configErrors) configErrors {
173184
if cfg.ConnectionInfo.Database == "" {
174185
return errs
175186
}
176187

177-
return cfg.PollUpdates.validate(section, errs)
188+
return cfg.PollUpdates.validate(dataType, errs)
178189
}
179190

180191
// PostgresConnection has options which put types to the Postgres Connection string. See:
@@ -269,7 +280,8 @@ type PostgresCacheInitializer struct {
269280
AmpQuery string `mapstructure:"amp_query"`
270281
}
271282

272-
func (cfg *PostgresCacheInitializer) validate(section string, errs configErrors) configErrors {
283+
func (cfg *PostgresCacheInitializer) validate(dataType DataType, errs configErrors) configErrors {
284+
section := dataType.Section()
273285
if cfg.Query == "" {
274286
return errs
275287
}
@@ -305,7 +317,8 @@ type PostgresUpdatePolling struct {
305317
AmpQuery string `mapstructure:"amp_query"`
306318
}
307319

308-
func (cfg *PostgresUpdatePolling) validate(section string, errs configErrors) configErrors {
320+
func (cfg *PostgresUpdatePolling) validate(dataType DataType, errs configErrors) configErrors {
321+
section := dataType.Section()
309322
if cfg.Query == "" {
310323
return errs
311324
}
@@ -384,32 +397,57 @@ type InMemoryCache struct {
384397
// TTL is the maximum number of seconds that an unused value will stay in the cache.
385398
// TTL <= 0 can be used for "no ttl". Elements will still be evicted based on the Size.
386399
TTL int `mapstructure:"ttl_seconds"`
400+
// Size is the max total cache size allowed for single caches
401+
Size int `mapstructure:"size_bytes"`
387402
// RequestCacheSize is the max number of bytes allowed in the cache for Stored Requests. Values <= 0 will have no limit
388403
RequestCacheSize int `mapstructure:"request_cache_size_bytes"`
389404
// ImpCacheSize is the max number of bytes allowed in the cache for Stored Imps. Values <= 0 will have no limit
390405
ImpCacheSize int `mapstructure:"imp_cache_size_bytes"`
391406
}
392407

393-
func (cfg *InMemoryCache) validate(section string, errs configErrors) configErrors {
408+
func (cfg *InMemoryCache) validate(dataType DataType, errs configErrors) configErrors {
409+
section := dataType.Section()
394410
switch cfg.Type {
395411
case "none":
396412
// No errors for no config options
397413
case "unbounded":
398414
if cfg.TTL != 0 {
399-
errs = append(errs, fmt.Errorf("%s: in_memory_cache must be 0 for unbounded caches. Got %d", section, cfg.TTL))
415+
errs = append(errs, fmt.Errorf("%s: in_memory_cache.ttl_seconds is not supported for unbounded caches. Got %d", section, cfg.TTL))
400416
}
401-
if cfg.RequestCacheSize != 0 {
402-
errs = append(errs, fmt.Errorf("%s: in_memory_cache.request_cache_size_bytes must be 0 for unbounded caches. Got %d", section, cfg.RequestCacheSize))
403-
}
404-
if cfg.ImpCacheSize != 0 {
405-
errs = append(errs, fmt.Errorf("%s: in_memory_cache.imp_cache_size_bytes must be 0 for unbounded caches. Got %d", section, cfg.ImpCacheSize))
417+
if dataType == AccountDataType {
418+
// single cache
419+
if cfg.Size != 0 {
420+
errs = append(errs, fmt.Errorf("%s: in_memory_cache.size_bytes is not supported for unbounded caches. Got %d", section, cfg.Size))
421+
}
422+
} else {
423+
// dual (request and imp) caches
424+
if cfg.RequestCacheSize != 0 {
425+
errs = append(errs, fmt.Errorf("%s: in_memory_cache.request_cache_size_bytes is not supported for unbounded caches. Got %d", section, cfg.RequestCacheSize))
426+
}
427+
if cfg.ImpCacheSize != 0 {
428+
errs = append(errs, fmt.Errorf("%s: in_memory_cache.imp_cache_size_bytes is not supported for unbounded caches. Got %d", section, cfg.ImpCacheSize))
429+
}
406430
}
407431
case "lru":
408-
if cfg.RequestCacheSize <= 0 {
409-
errs = append(errs, fmt.Errorf("%s: in_memory_cache.request_cache_size_bytes must be >= 0 when in_memory_cache.type=lru. Got %d", section, cfg.RequestCacheSize))
410-
}
411-
if cfg.ImpCacheSize <= 0 {
412-
errs = append(errs, fmt.Errorf("%s: in_memory_cache.imp_cache_size_bytes must be >= 0 when in_memory_cache.type=lru. Got %d", section, cfg.ImpCacheSize))
432+
if dataType == AccountDataType {
433+
// single cache
434+
if cfg.Size <= 0 {
435+
errs = append(errs, fmt.Errorf("%s: in_memory_cache.size_bytes must be >= 0 when in_memory_cache.type=lru. Got %d", section, cfg.Size))
436+
}
437+
if cfg.RequestCacheSize > 0 || cfg.ImpCacheSize > 0 {
438+
glog.Warningf("%s: in_memory_cache.request_cache_size_bytes and imp_cache_size_bytes do not apply to this section and will be ignored", section)
439+
}
440+
} else {
441+
// dual (request and imp) caches
442+
if cfg.RequestCacheSize <= 0 {
443+
errs = append(errs, fmt.Errorf("%s: in_memory_cache.request_cache_size_bytes must be >= 0 when in_memory_cache.type=lru. Got %d", section, cfg.RequestCacheSize))
444+
}
445+
if cfg.ImpCacheSize <= 0 {
446+
errs = append(errs, fmt.Errorf("%s: in_memory_cache.imp_cache_size_bytes must be >= 0 when in_memory_cache.type=lru. Got %d", section, cfg.ImpCacheSize))
447+
}
448+
if cfg.Size > 0 {
449+
glog.Warningf("%s: in_memory_cache.size_bytes does not apply in this section and will be ignored", section)
450+
}
413451
}
414452
default:
415453
errs = append(errs, fmt.Errorf("%s: in_memory_cache.type %s is invalid", section, cfg.Type))

config/stored_requests_test.go

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,43 +75,83 @@ func TestPostgressConnString(t *testing.T) {
7575
assertHasValue(t, params, "sslmode", "disable")
7676
}
7777

78-
func TestInMemoryCacheValidation(t *testing.T) {
78+
func TestInMemoryCacheValidationStoredRequests(t *testing.T) {
7979
assertNoErrs(t, (&InMemoryCache{
8080
Type: "unbounded",
81-
}).validate("Test", nil))
81+
}).validate(RequestDataType, nil))
8282
assertNoErrs(t, (&InMemoryCache{
8383
Type: "none",
84-
}).validate("Test", nil))
84+
}).validate(RequestDataType, nil))
8585
assertNoErrs(t, (&InMemoryCache{
8686
Type: "lru",
8787
RequestCacheSize: 1000,
8888
ImpCacheSize: 1000,
89-
}).validate("Test", nil))
89+
}).validate(RequestDataType, nil))
9090
assertErrsExist(t, (&InMemoryCache{
9191
Type: "unrecognized",
92-
}).validate("Test", nil))
92+
}).validate(RequestDataType, nil))
9393
assertErrsExist(t, (&InMemoryCache{
9494
Type: "unbounded",
9595
ImpCacheSize: 1000,
96-
}).validate("Test", nil))
96+
}).validate(RequestDataType, nil))
9797
assertErrsExist(t, (&InMemoryCache{
9898
Type: "unbounded",
9999
RequestCacheSize: 1000,
100-
}).validate("Test", nil))
100+
}).validate(RequestDataType, nil))
101101
assertErrsExist(t, (&InMemoryCache{
102102
Type: "unbounded",
103103
TTL: 500,
104-
}).validate("Test", nil))
104+
}).validate(RequestDataType, nil))
105105
assertErrsExist(t, (&InMemoryCache{
106106
Type: "lru",
107107
RequestCacheSize: 0,
108108
ImpCacheSize: 1000,
109-
}).validate("Test", nil))
109+
}).validate(RequestDataType, nil))
110110
assertErrsExist(t, (&InMemoryCache{
111111
Type: "lru",
112112
RequestCacheSize: 1000,
113113
ImpCacheSize: 0,
114-
}).validate("Test", nil))
114+
}).validate(RequestDataType, nil))
115+
assertErrsExist(t, (&InMemoryCache{
116+
Type: "lru",
117+
Size: 1000,
118+
}).validate(RequestDataType, nil))
119+
}
120+
121+
func TestInMemoryCacheValidationSingleCache(t *testing.T) {
122+
assertNoErrs(t, (&InMemoryCache{
123+
Type: "unbounded",
124+
}).validate(AccountDataType, nil))
125+
assertNoErrs(t, (&InMemoryCache{
126+
Type: "none",
127+
}).validate(AccountDataType, nil))
128+
assertNoErrs(t, (&InMemoryCache{
129+
Type: "lru",
130+
Size: 1000,
131+
}).validate(AccountDataType, nil))
132+
assertErrsExist(t, (&InMemoryCache{
133+
Type: "unrecognized",
134+
}).validate(AccountDataType, nil))
135+
assertErrsExist(t, (&InMemoryCache{
136+
Type: "unbounded",
137+
Size: 1000,
138+
}).validate(AccountDataType, nil))
139+
assertErrsExist(t, (&InMemoryCache{
140+
Type: "unbounded",
141+
TTL: 500,
142+
}).validate(AccountDataType, nil))
143+
assertErrsExist(t, (&InMemoryCache{
144+
Type: "lru",
145+
Size: 0,
146+
}).validate(AccountDataType, nil))
147+
assertErrsExist(t, (&InMemoryCache{
148+
Type: "lru",
149+
RequestCacheSize: 1000,
150+
}).validate(AccountDataType, nil))
151+
assertErrsExist(t, (&InMemoryCache{
152+
Type: "lru",
153+
ImpCacheSize: 1000,
154+
}).validate(AccountDataType, nil))
115155
}
116156

117157
func assertErrsExist(t *testing.T, err configErrors) {
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
"description": "Video endpoint valid request with AppendBidderNames.",
3+
"requestPayload": {
4+
"appendbiddernames": true,
5+
"storedrequestid": "80ce30c53c16e6ede735f123ef6e32361bfc7b22",
6+
"podconfig": {
7+
"durationrangesec": [
8+
30
9+
],
10+
"requireexactduration": true,
11+
"pods": [{
12+
"podid": 1,
13+
"adpoddurationsec": 180,
14+
"configid": "fba10607-0c12-43d1-ad07-b8a513bc75d6"
15+
},
16+
{
17+
"podid": 2,
18+
"adpoddurationsec": 150,
19+
"configid": "8b452b41-2681-4a20-9086-6f16ffad7773"
20+
}
21+
]
22+
},
23+
"site": {
24+
"page": "prebid.com"
25+
},
26+
"regs": {
27+
"ext": {
28+
"gdpr": 0
29+
}
30+
},
31+
"user": {
32+
"yob": 1991,
33+
"gender": "F",
34+
"keywords": "Hotels, Travelling",
35+
"ext": {
36+
"prebid": {
37+
"buyeruids": {
38+
"appnexus": "unique_id_an",
39+
"rubicon": "unique_id_rubi"
40+
}
41+
}
42+
}
43+
},
44+
"device": {
45+
"ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.13 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2",
46+
"ip": "123.145.167.10",
47+
"devicetype": 1,
48+
"ifa": "AA000DFE74168477C70D291f574D344790E0BB11",
49+
"lmt": 44,
50+
"os": "mac os",
51+
"w": 640,
52+
"h": 480,
53+
"didsha1": "didsha1",
54+
"didmd5": "didmd5",
55+
"dpidsha1": "dpidsha1",
56+
"dpidmd5": "dpidmd5",
57+
"macsha1": "macsha1",
58+
"macmd5": "macmd5"
59+
},
60+
"includebrandcategory": {
61+
"primaryadserver": 1,
62+
"publisher": ""
63+
},
64+
"video": {
65+
"w": 640,
66+
"h": 480,
67+
"mimes": [
68+
"video/mp4"
69+
],
70+
"protocols": [
71+
2, 3, 5, 6
72+
]
73+
},
74+
"content": {
75+
"episode": 6,
76+
"title": "episodeName",
77+
"series": "TvName",
78+
"season": "season3",
79+
"len": 900,
80+
"livestream": 0
81+
},
82+
"cacheconfig": {
83+
"ttl": 42
84+
}
85+
}
86+
}

endpoints/openrtb2/video_auction.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@ func createBidExtension(videoRequest *openrtb_ext.BidRequestVideo) ([]byte, erro
624624
IncludeBrandCategory: inclBrandCat,
625625
DurationRangeSec: durationRangeSec,
626626
IncludeBidderKeys: true,
627+
AppendBidderNames: videoRequest.AppendBidderNames,
627628
}
628629

629630
vastXml := openrtb_ext.ExtRequestPrebidCacheVAST{}

0 commit comments

Comments
 (0)