Skip to content

Commit

Permalink
resolved comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pm-priyanka-bagade committed Jun 11, 2024
1 parent 1354f17 commit 79dea92
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 54 deletions.
6 changes: 3 additions & 3 deletions analytics/pubmatic/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ func setWakandaObject(rCtx *models.RequestCtx, ao *analytics.AuctionObject, logg
setWakandaWinningBidFlag(rCtx.WakandaDebug, ao.Response)
parseURL, err := url.Parse(loggerURL)
if err != nil {
glog.Error("Failed to parse loggerURL while setting wakanda object err:%s", err.Error())
glog.Errorf("Failed to parse loggerURL while setting wakanda object err: %s", err.Error())
}
if parseURL != nil {
jsonParam := parseURL.Query().Get(parseUrlFormat)
rCtx.WakandaDebug.SetLogger(json.RawMessage(jsonParam))
}
bytes, err := json.Marshal(ao.Response)
if err != nil {
glog.Error("Failed to marshal ao.Response while setting wakanda object err:%s", err.Error())
glog.Errorf("Failed to marshal ao.Response while setting wakanda object err: %s", err.Error())
}
rCtx.WakandaDebug.SetHTTPResponseBodyWriter(string(bytes))
rCtx.WakandaDebug.SetOpenRTB(ao.RequestWrapper.BidRequest)
Expand All @@ -141,7 +141,7 @@ func setWakandaObject(rCtx *models.RequestCtx, ao *analytics.AuctionObject, logg
}

// setWakandaWinningBidFlag will set WinningBid flag to true if we are getting any positive bid in response
func setWakandaWinningBidFlag(wakandaDebug wakanda.DebugInterface, response *openrtb2.BidResponse) {
func setWakandaWinningBidFlag(wakandaDebug wakanda.WakandaDebug, response *openrtb2.BidResponse) {
if wakandaDebug != nil && response != nil {
if len(response.SeatBid) > 0 &&
len(response.SeatBid[0].Bid) > 0 &&
Expand Down
4 changes: 2 additions & 2 deletions analytics/pubmatic/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,13 +551,13 @@ func TestWloggerRecord_logProfileMetaData(t *testing.T) {

func TestSetWakandaWinningBidFlag(t *testing.T) {
type args struct {
wakandaDebug wakanda.DebugInterface
wakandaDebug wakanda.WakandaDebug
response *openrtb2.BidResponse
}
tests := []struct {
name string
args args
want wakanda.DebugInterface
want wakanda.WakandaDebug
}{
{
name: "all_empty_parameters",
Expand Down
15 changes: 7 additions & 8 deletions modules/pubmatic/openwrap/entrypointhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,14 @@ func (m OpenWrap) handleEntrypointHook(
result.Errors = append(result.Errors, errs[0].Error())
return result, errs[0]
}
if len(pubIdStr) > 0 {
rCtx.PubID, err = strconv.Atoi(pubIdStr)
if err != nil {
result.NbrCode = int(nbr.InvalidPublisherID)
result.Errors = append(result.Errors, "ErrInvalidPublisherID")
return result, fmt.Errorf("invalid publisher id : %v", err)
}
rCtx.PubIDStr = pubIdStr

rCtx.PubID, err = strconv.Atoi(pubIdStr)
if err != nil {
result.NbrCode = int(nbr.InvalidPublisherID)
result.Errors = append(result.Errors, "ErrInvalidPublisherID")
return result, fmt.Errorf("invalid publisher id : %v", err)
}
rCtx.PubIDStr = pubIdStr

rCtx.WakandaDebug.EnableIfRequired(pubIdStr, rCtx.ProfileIDStr)
if rCtx.WakandaDebug.IsEnable() {
Expand Down
2 changes: 1 addition & 1 deletion modules/pubmatic/openwrap/models/openwrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ type RequestCtx struct {
AppPlatform int
AppIntegrationPath *int
AppSubIntegrationPath *int
WakandaDebug wakanda.DebugInterface
WakandaDebug wakanda.WakandaDebug
}

type OwBid struct {
Expand Down
2 changes: 1 addition & 1 deletion modules/pubmatic/openwrap/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ func initOpenWrapServer(cfg *config.Config) *http.Server {

func startServer(server *http.Server) {
if err := server.ListenAndServe(); err != nil {
logger.Fatal("main.main:unable to start http server for /wakanda handler due to : %s", err.Error())
logger.Fatal("openwrap: unable to start http server for /wakanda handler due to err : %s", err.Error())
}
}
2 changes: 1 addition & 1 deletion modules/pubmatic/openwrap/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/assert"
)

func Test_initOpenWrapServer(t *testing.T) {
func TestInitOpenWrapServer(t *testing.T) {
type args struct {
cfg *config.Config
}
Expand Down
21 changes: 17 additions & 4 deletions modules/pubmatic/openwrap/wakanda/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,21 @@ package wakanda

var (

//ContentType HTTP Response Header Content Type
ContentType = `Content-Type`
//ContentTypeApplicationJSON HTTP Header Content-Type Value
ContentTypeApplicationJSON = `application/json`
//contentType HTTP Response Header Content Type
contentType = `Content-Type`
//contentTypeApplicationJSON HTTP Header Content-Type Value
contentTypeApplicationJSON = `application/json`
)

const (
//cMaxTraceCount maximum trace request can be logged
cMaxTraceCount = 20
//cAPIDebugLevel debug level parameter of wakanda handler
cAPIDebugLevel = "debugLevel"
//cAPIPublisherID publisher id paramater of wakanda handler
cAPIPublisherID = "pubId"
//cAPIProfileID profile id parameter of wakanda handler
cAPIProfileID = "profId"
//cRuleKeyPubProfile rule format ,same is used for folder name with "__DC"
cRuleKeyPubProfile = "PUB:%s__PROF:%s"
)
2 changes: 1 addition & 1 deletion modules/pubmatic/openwrap/wakanda/rulesMap.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (rm *rulesMap) Incr(key string) *wakandaRule {
}
//below line can be moved outside of function
aWakandaRule.TraceCount++
if aWakandaRule.TraceCount > CMaxTraceCount {
if aWakandaRule.TraceCount > cMaxTraceCount {
// this rule has got enough traces so we can delete this active rule
delete(rm.rules, key)
return nil
Expand Down
2 changes: 1 addition & 1 deletion modules/pubmatic/openwrap/wakanda/rulesMap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func TestRulesMapIncr(t *testing.T) {
fields: fields{
rules: map[string]*wakandaRule{
`key1`: {
TraceCount: CMaxTraceCount,
TraceCount: cMaxTraceCount,
},
},
},
Expand Down
25 changes: 6 additions & 19 deletions modules/pubmatic/openwrap/wakanda/wakanda.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,6 @@ import (
"strconv"
)

const (
//CMaxTraceCount maximum trace request can be logged
CMaxTraceCount = 20
//CAPIDebugLevel debug level parameter of wakanda handler
CAPIDebugLevel = "debugLevel"
//CAPIPublisherID publisher id paramater of wakanda handler
CAPIPublisherID = "pubId"
//CAPIProfileID profile id parameter of wakanda handler
CAPIProfileID = "profId"
//CRuleKeyPubProfile rule format ,same is used for folder name with "__DC"
CRuleKeyPubProfile = "PUB:%s__PROF:%s"
)

var wakandaRulesMap *rulesMap

// generateKeyFromWakandaRequest returns only one qualifying rule
Expand All @@ -27,11 +14,11 @@ func generateKeyFromWakandaRequest(pubIDStr string, profIDStr string) string {
// note: for new rule-key extra code will be needed to be added

if len(pubIDStr) > 3 && len(profIDStr) >= 1 {
return fmt.Sprintf(CRuleKeyPubProfile, pubIDStr, profIDStr)
return fmt.Sprintf(cRuleKeyPubProfile, pubIDStr, profIDStr)
}

if len(pubIDStr) > 3 {
return fmt.Sprintf(CRuleKeyPubProfile, pubIDStr, "0") // setting profile id as 0 for all profile ids
return fmt.Sprintf(cRuleKeyPubProfile, pubIDStr, "0") // setting profile id as 0 for all profile ids
}

return ""
Expand All @@ -48,8 +35,8 @@ func generateKeyFromWakandaRequest(pubIDStr string, profIDStr string) string {
func generateKeysFromHBRequest(pubIDStr string, profIDStr string) (generatedKeys []string) {
generatedKeys = append(
generatedKeys,
fmt.Sprintf(CRuleKeyPubProfile, pubIDStr, profIDStr),
fmt.Sprintf(CRuleKeyPubProfile, pubIDStr, "0"), // setting profile id as 0 for all profile ids
fmt.Sprintf(cRuleKeyPubProfile, pubIDStr, profIDStr),
fmt.Sprintf(cRuleKeyPubProfile, pubIDStr, "0"), // setting profile id as 0 for all profile ids
)
return
}
Expand All @@ -58,7 +45,7 @@ func generateKeysFromHBRequest(pubIDStr string, profIDStr string) (generatedKeys
func Handler(config Wakanda) http.HandlerFunc {
return func(httpRespWriter http.ResponseWriter, httpRequest *http.Request) {

debugLevel, _ := strconv.Atoi(httpRequest.FormValue(CAPIDebugLevel))
debugLevel, _ := strconv.Atoi(httpRequest.FormValue(cAPIDebugLevel))
if debugLevel == 0 {
debugLevel = 1 // default debugLevel
// 1: pbs debug 1
Expand All @@ -73,7 +60,7 @@ func Handler(config Wakanda) http.HandlerFunc {
successStatus := "true"
statusMsg := ""

key := generateKeyFromWakandaRequest(httpRequest.FormValue(CAPIPublisherID), httpRequest.FormValue(CAPIProfileID))
key := generateKeyFromWakandaRequest(httpRequest.FormValue(cAPIPublisherID), httpRequest.FormValue(cAPIProfileID))
if len(key) > 0 {

if wakandaRulesMap.AddIfNotPresent(key, debugLevel, config.DCName) {
Expand Down
2 changes: 1 addition & 1 deletion modules/pubmatic/openwrap/wakanda/wakandaDebug.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Debug struct {
Config Wakanda
}

type DebugInterface interface {
type WakandaDebug interface {
IsEnable() bool
SetHTTPRequestData(HTTPRequest *http.Request, HTTPRequestBody json.RawMessage)
SetHTTPResponseWriter(HTTPResponse http.ResponseWriter)
Expand Down
6 changes: 3 additions & 3 deletions modules/pubmatic/openwrap/wakanda/wakandaDebugData.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (r *request) set(request *http.Request, postData json.RawMessage) {
r.Path = request.URL.Path
}
if len(postData) > 0 {
if r.Headers.Get(ContentType) == ContentTypeApplicationJSON {
if r.Headers.Get(contentType) == contentTypeApplicationJSON {
r.PostJSON = postData
} else {
r.PostBody = string(postData)
Expand All @@ -63,7 +63,7 @@ func (r *response) setResponseRecorder(resp *httptest.ResponseRecorder) {
if resp != nil {
r.StatusCode = resp.Code
r.Headers = resp.HeaderMap
if r.Headers.Get(ContentType) == ContentTypeApplicationJSON {
if r.Headers.Get(contentType) == contentTypeApplicationJSON {
r.Body = resp.Body.Bytes()[:]
} else {
r.Response = resp.Body.String()
Expand All @@ -75,7 +75,7 @@ func (r *response) setResponseWriter(resp http.ResponseWriter, body string) {
if resp != nil {
r.Headers = resp.Header()
}
if r.Headers.Get(ContentType) == ContentTypeApplicationJSON {
if r.Headers.Get(contentType) == contentTypeApplicationJSON {
r.Body = json.RawMessage(body)
} else {
r.Response = body
Expand Down
14 changes: 6 additions & 8 deletions modules/pubmatic/openwrap/wakanda/wakandaDebugData_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestRequestSet(t *testing.T) {
args: args{
request: func() *http.Request {
req := httptest.NewRequest("GET", "http://test.com/path?query=test_query", nil)
req.Header.Set(ContentType, ContentTypeApplicationJSON)
req.Header.Set(contentType, contentTypeApplicationJSON)
return req
}(),
postData: json.RawMessage(`{"test_post_data":1}`),
Expand All @@ -77,7 +77,7 @@ func TestRequestSet(t *testing.T) {
Path: "/path",
QueryString: "query=test_query",
Headers: http.Header{
ContentType: []string{ContentTypeApplicationJSON},
contentType: []string{contentTypeApplicationJSON},
},
PostJSON: json.RawMessage(`{"test_post_data":1}`),
},
Expand Down Expand Up @@ -134,15 +134,15 @@ func TestResponseSetResponseRecorder(t *testing.T) {
Body: bytes.NewBuffer([]byte(`{"test_body":1}`)),
Code: 200,
HeaderMap: http.Header{
ContentType: []string{ContentTypeApplicationJSON},
contentType: []string{contentTypeApplicationJSON},
"x-header-1": []string{"val1"},
},
},
},
want: response{
StatusCode: 200,
Headers: http.Header{
ContentType: []string{ContentTypeApplicationJSON},
contentType: []string{contentTypeApplicationJSON},
"x-header-1": []string{"val1"},
},
Body: json.RawMessage(`{"test_body":1}`),
Expand Down Expand Up @@ -214,15 +214,15 @@ func TestResponseSetResponseWriter(t *testing.T) {
args: args{
resp: &httptest.ResponseRecorder{
HeaderMap: http.Header{
ContentType: []string{ContentTypeApplicationJSON},
contentType: []string{contentTypeApplicationJSON},
"x-header-1": []string{"val1"},
},
},
body: `{"test_body":1}`,
},
want: response{
Headers: http.Header{
ContentType: []string{ContentTypeApplicationJSON},
contentType: []string{contentTypeApplicationJSON},
"x-header-1": []string{"val1"},
},
Body: json.RawMessage(`{"test_body":1}`),
Expand Down Expand Up @@ -323,8 +323,6 @@ func TestNewLogRecord(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
got := NewLogRecord(tt.args.wD)
assert.Equal(t, tt.want, got)
_, err := json.Marshal(got)
assert.Nil(t, err)
})
}
}
1 change: 0 additions & 1 deletion modules/pubmatic/openwrap/wakanda/wakanda_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func wakndaGetTester(t *testing.T, handler http.HandlerFunc, call string, output
t.Errorf("For input Query: %s, handler returned wrong status code: \nGOT %v \nWANT %v",
call, status, http.StatusOK)
}
// expected := `{success: "false", statusMsg: "No key was generated for the request."}`
if rr.Body.String() != output {
t.Errorf("For input Query: %s, handler returned unexpected body:\nGOT %v \nWANT %v",
call, rr.Body.String(), output)
Expand Down

0 comments on commit 79dea92

Please sign in to comment.