-
Notifications
You must be signed in to change notification settings - Fork 760
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
Debug override header #1853
Debug override header #1853
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,11 +128,13 @@ func (deps *endpointDeps) VideoAuctionEndpoint(w http.ResponseWriter, r *http.Re | |
cacheTTL = int64(deps.cfg.CacheURL.DefaultTTLs.Video) | ||
} | ||
debugLog := exchange.DebugLog{ | ||
Enabled: strings.EqualFold(debugQuery, "true"), | ||
CacheType: prebid_cache_client.TypeXML, | ||
TTL: cacheTTL, | ||
Regexp: deps.debugLogRegexp, | ||
Enabled: strings.EqualFold(debugQuery, "true"), | ||
CacheType: prebid_cache_client.TypeXML, | ||
TTL: cacheTTL, | ||
Regexp: deps.debugLogRegexp, | ||
DebugOverride: exchange.IsDebugOverrideEnabled(r.Header.Get(exchange.DebugOverrideHeader), deps.cfg.Debug.OverrideToken), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To ensure I'm following correctly, we need to perform this check in the video endpoint because the video endpoint does it's own debug logging. The auction and amp endpoints don't require this since the logic in auction.go applies to all 3 openrtb2 endpoints, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. Now debug log is enabled for video endpoint only. For amp and auction we don't init debugLog and by default it's disabled. func (e *exchange) HoldAuction:
|
||
} | ||
debugLog.DebugEnabledOrOverridden = debugLog.Enabled || debugLog.DebugOverride | ||
|
||
defer func() { | ||
if len(debugLog.CacheKey) > 0 && vo.VideoResponse == nil { | ||
|
@@ -157,7 +159,7 @@ func (deps *endpointDeps) VideoAuctionEndpoint(w http.ResponseWriter, r *http.Re | |
} | ||
|
||
resolvedRequest := requestJson | ||
if debugLog.Enabled { | ||
if debugLog.DebugEnabledOrOverridden { | ||
debugLog.Data.Request = string(requestJson) | ||
if headerBytes, err := json.Marshal(r.Header); err == nil { | ||
debugLog.Data.Headers = string(headerBytes) | ||
|
@@ -209,7 +211,7 @@ func (deps *endpointDeps) VideoAuctionEndpoint(w http.ResponseWriter, r *http.Re | |
//create full open rtb req from full video request | ||
mergeData(videoBidReq, bidReq) | ||
// If debug query param is set, force the response to enable test flag | ||
if debugLog.Enabled { | ||
if debugLog.DebugEnabledOrOverridden { | ||
bidReq.Test = 1 | ||
} | ||
|
||
|
@@ -306,7 +308,7 @@ func (deps *endpointDeps) VideoAuctionEndpoint(w http.ResponseWriter, r *http.Re | |
bidResp.Ext = response.Ext | ||
} | ||
|
||
if len(bidResp.AdPods) == 0 && debugLog.Enabled { | ||
if len(bidResp.AdPods) == 0 && debugLog.DebugEnabledOrOverridden { | ||
err := debugLog.PutDebugLogError(deps.cache, deps.cfg.CacheURL.ExpectedTimeMillis, vo.Errors) | ||
if err != nil { | ||
vo.Errors = append(vo.Errors, err) | ||
|
@@ -344,7 +346,7 @@ func cleanupVideoBidRequest(videoReq *openrtb_ext.BidRequestVideo, podErrors []P | |
} | ||
|
||
func handleError(labels *metrics.Labels, w http.ResponseWriter, errL []error, vo *analytics.VideoObject, debugLog *exchange.DebugLog) { | ||
if debugLog != nil && debugLog.Enabled { | ||
if debugLog != nil && debugLog.DebugEnabledOrOverridden { | ||
if rawUUID, err := uuid.NewV4(); err == nil { | ||
debugLog.CacheKey = rawUUID.String() | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,14 +17,21 @@ import ( | |
"github.com/prebid/prebid-server/prebid_cache_client" | ||
) | ||
|
||
const ( | ||
DebugOverrideHeader string = "x-pbs-debug-override" | ||
) | ||
|
||
type DebugLog struct { | ||
Enabled bool | ||
CacheType prebid_cache_client.PayloadType | ||
Data DebugData | ||
TTL int64 | ||
CacheKey string | ||
CacheString string | ||
Regexp *regexp.Regexp | ||
Enabled bool | ||
CacheType prebid_cache_client.PayloadType | ||
Data DebugData | ||
TTL int64 | ||
CacheKey string | ||
CacheString string | ||
Regexp *regexp.Regexp | ||
DebugOverride bool | ||
//little optimization, it stores value of debugLog.Enabled || debugLog.DebugOverride | ||
DebugEnabledOrOverridden bool | ||
} | ||
|
||
type DebugData struct { | ||
|
@@ -47,6 +54,10 @@ func (d *DebugLog) BuildCacheString() { | |
d.CacheString = fmt.Sprintf("%s<Log>%s%s%s</Log>", xml.Header, d.Data.Request, d.Data.Headers, d.Data.Response) | ||
} | ||
|
||
func IsDebugOverrideEnabled(debugHeader, configOverrideToken string) bool { | ||
return configOverrideToken != "" && debugHeader == configOverrideToken | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be simplified to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, done. |
||
|
||
func (d *DebugLog) PutDebugLogError(cache prebid_cache_client.Client, timeout int, errors []error) error { | ||
if len(d.Data.Response) == 0 && len(errors) == 0 { | ||
d.Data.Response = "No response or errors created" | ||
|
@@ -238,7 +249,7 @@ func (a *auction) doCache(ctx context.Context, cache prebid_cache_client.Client, | |
} | ||
} | ||
|
||
if len(toCache) > 0 && debugLog != nil && debugLog.Enabled { | ||
if len(toCache) > 0 && debugLog != nil && debugLog.DebugEnabledOrOverridden { | ||
debugLog.CacheKey = hbCacheID | ||
debugLog.BuildCacheString() | ||
if jsonBytes, err := json.Marshal(debugLog.CacheString); err == nil { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,6 +118,56 @@ func TestCacheJSON(t *testing.T) { | |
} | ||
} | ||
|
||
func TestIsDebugOverrideEnabled(t *testing.T) { | ||
type inTest struct { | ||
debugHeader string | ||
configToken string | ||
} | ||
type aTest struct { | ||
desc string | ||
in inTest | ||
result bool | ||
} | ||
testCases := []aTest{ | ||
{ | ||
desc: "test debug header is empty, config token is empty", | ||
in: inTest{debugHeader: "", configToken: ""}, | ||
result: false, | ||
}, | ||
{ | ||
desc: "test debug header is present, config token is empty", | ||
in: inTest{debugHeader: "TestToken", configToken: ""}, | ||
result: false, | ||
}, | ||
{ | ||
desc: "test debug header is empty, config token is present", | ||
in: inTest{debugHeader: "", configToken: "TestToken"}, | ||
result: false, | ||
}, | ||
{ | ||
desc: "test debug header is present, config token is present, not equal", | ||
in: inTest{debugHeader: "TestToken123", configToken: "TestToken"}, | ||
result: false, | ||
}, | ||
{ | ||
desc: "test debug header is present, config token is present, equal", | ||
in: inTest{debugHeader: "TestToken", configToken: "TestToken"}, | ||
result: true, | ||
}, | ||
{ | ||
desc: "test debug header is present, config token is present, not case equal", | ||
in: inTest{debugHeader: "TestTokeN", configToken: "TestToken"}, | ||
result: false, | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding one more test to make it explicit that the comparison is case sensitive. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
} | ||
|
||
for _, test := range testCases { | ||
result := IsDebugOverrideEnabled(test.in.debugHeader, test.in.configToken) | ||
assert.Equal(t, test.result, result, test.desc) | ||
} | ||
|
||
} | ||
|
||
// LoadCacheSpec reads and parses a file as a test case. If something goes wrong, it returns an error. | ||
func loadCacheSpec(filename string) (*cacheSpec, error) { | ||
specData, err := ioutil.ReadFile(filename) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 *openrtb2.BidRequest, name openrtb_ext.BidderName, bidAdjustment float64, conversions currency.Conversions, reqInfo *adapters.ExtraRequestInfo, accountDebugAllowed bool) (*pbsOrtbSeatBid, []error) | ||
requestBid(ctx context.Context, request *openrtb2.BidRequest, name openrtb_ext.BidderName, bidAdjustment float64, conversions currency.Conversions, reqInfo *adapters.ExtraRequestInfo, accountDebugAllowed, headerDebugAllowed bool) (*pbsOrtbSeatBid, []error) | ||
} | ||
|
||
// pbsOrtbBid is a Bid returned by an adaptedBidder. | ||
|
@@ -126,7 +126,7 @@ type bidderAdapterConfig struct { | |
DebugInfo config.DebugInfo | ||
} | ||
|
||
func (bidder *bidderAdapter) requestBid(ctx context.Context, request *openrtb2.BidRequest, name openrtb_ext.BidderName, bidAdjustment float64, conversions currency.Conversions, reqInfo *adapters.ExtraRequestInfo, accountDebugAllowed bool) (*pbsOrtbSeatBid, []error) { | ||
func (bidder *bidderAdapter) requestBid(ctx context.Context, request *openrtb2.BidRequest, name openrtb_ext.BidderName, bidAdjustment float64, conversions currency.Conversions, reqInfo *adapters.ExtraRequestInfo, accountDebugAllowed, headerDebugAllowed bool) (*pbsOrtbSeatBid, []error) { | ||
reqData, errs := bidder.Bidder.MakeRequests(request, reqInfo) | ||
|
||
if len(reqData) == 0 { | ||
|
@@ -176,19 +176,25 @@ func (bidder *bidderAdapter) requestBid(ctx context.Context, request *openrtb2.B | |
httpInfo := <-responseChannel | ||
// If this is a test bid, capture debugging info from the requests. | ||
// Write debug data to ext in case if: | ||
// - headerDebugAllowed (debug override header specified correct) - it overrides all other debug restrictions | ||
// - debugContextKey (url param) in true | ||
// - account debug is allowed | ||
// - bidder debug is allowed | ||
if debugInfo := ctx.Value(DebugContextKey); debugInfo != nil && debugInfo.(bool) { | ||
if accountDebugAllowed { | ||
if bidder.config.DebugInfo.Allow { | ||
seatBid.httpCalls = append(seatBid.httpCalls, makeExt(httpInfo)) | ||
} else { | ||
debugDisabledWarning := errortypes.Warning{ | ||
WarningCode: errortypes.BidderLevelDebugDisabledWarningCode, | ||
Message: "debug turned off for bidder", | ||
if headerDebugAllowed { | ||
seatBid.httpCalls = append(seatBid.httpCalls, makeExt(httpInfo)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please consider asserting that this information exists when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mansi, this is sort of done in test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @VeronikaSolovei9 Thanks for that explanation. However, even though both |
||
} else { | ||
debugInfo := ctx.Value(DebugContextKey) | ||
if debugInfo != nil && debugInfo.(bool) { | ||
if accountDebugAllowed { | ||
if bidder.config.DebugInfo.Allow { | ||
seatBid.httpCalls = append(seatBid.httpCalls, makeExt(httpInfo)) | ||
} else { | ||
debugDisabledWarning := errortypes.Warning{ | ||
WarningCode: errortypes.BidderLevelDebugDisabledWarningCode, | ||
Message: "debug turned off for bidder", | ||
} | ||
errs = append(errs, &debugDisabledWarning) | ||
} | ||
errs = append(errs, &debugDisabledWarning) | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add this field to the
TestFullConfig
test.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added