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

New Adapter: Insticator #3806

Merged
merged 19 commits into from
Dec 12, 2024
Merged

Conversation

shubhamc-ins
Copy link
Contributor

@shubhamc-ins shubhamc-ins commented Jul 10, 2024

shubhamc-ins and others added 5 commits July 10, 2024 23:59
* init insticator adaptor

* update modules

* add mediaType for bids

* update insticator adaptor with tests

* update insticator for test cases

* fix test cases

* update InstAdapter

* update insticator adaptor

* fix test cases for adUnitId

* update insticator adapter type

* Updates
- add currency converter support
- Add video validation support

* remove default plcmt and placement

* add more test cases

* update for publisher ID

* fix tests
* add multi-imps testJson

* fix pubId parsing for request
Copy link

Code coverage summary

Note:

  • Prebid team doesn't anticipate tests covering code paths that might result in marshal and unmarshal errors
  • Coverage summary encompasses all commits leading up to the latest one, 92e859a

insticator

Refer here for heat map coverage report

github.com/prebid/prebid-server/v2/adapters/insticator/insticator.go:99:	Error				0.0%
github.com/prebid/prebid-server/v2/adapters/insticator/insticator.go:104:	isInteger			0.0%
github.com/prebid/prebid-server/v2/adapters/insticator/insticator.go:118:	isArrayOfNums			0.0%
github.com/prebid/prebid-server/v2/adapters/insticator/insticator.go:170:	toInt				0.0%
github.com/prebid/prebid-server/v2/adapters/insticator/insticator.go:185:	Builder				100.0%
github.com/prebid/prebid-server/v2/adapters/insticator/insticator.go:193:	getMediaTypeForBid		100.0%
github.com/prebid/prebid-server/v2/adapters/insticator/insticator.go:204:	getBidType			0.0%
github.com/prebid/prebid-server/v2/adapters/insticator/insticator.go:212:	MakeRequests			80.0%
github.com/prebid/prebid-server/v2/adapters/insticator/insticator.go:268:	makeRequest			50.0%
github.com/prebid/prebid-server/v2/adapters/insticator/insticator.go:304:	MakeBids			80.0%
github.com/prebid/prebid-server/v2/adapters/insticator/insticator.go:344:	makeImps			85.7%
github.com/prebid/prebid-server/v2/adapters/insticator/insticator.go:393:	validateVideoParams		85.7%
github.com/prebid/prebid-server/v2/adapters/insticator/insticator.go:413:	makeReqExt			80.0%
github.com/prebid/prebid-server/v2/adapters/insticator/insticator.go:435:	resolveBidFloor			50.0%
github.com/prebid/prebid-server/v2/adapters/insticator/insticator.go:445:	roundTo4Decimals		0.0%
github.com/prebid/prebid-server/v2/adapters/insticator/insticator.go:449:	validateOptionalVideoParams	68.8%
github.com/prebid/prebid-server/v2/adapters/insticator/insticator.go:484:	toCamelCase			0.0%
github.com/prebid/prebid-server/v2/adapters/insticator/insticator.go:492:	isZeroOrNil			0.0%
github.com/prebid/prebid-server/v2/adapters/insticator/insticator.go:506:	populatePublisherId		27.3%
total:										(statements)			57.6%

@bsardo bsardo changed the title New Adaptor: Insticator New Adapter: Insticator Jul 26, 2024
Copy link

Code coverage summary

Note:

  • Prebid team doesn't anticipate tests covering code paths that might result in marshal and unmarshal errors
  • Coverage summary encompasses all commits leading up to the latest one, ff2df10

insticator

Refer here for heat map coverage report

github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:56:	Builder			100.0%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:64:	getMediaTypeForBid	100.0%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:75:	MakeRequests		73.3%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:132:	makeRequest		50.0%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:168:	MakeBids		88.2%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:200:	makeImps		80.0%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:244:	makeReqExt		80.0%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:266:	resolveBidFloor		50.0%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:275:	validateVideoParams	100.0%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:289:	populatePublisherId	85.0%
total:										(statements)		76.9%

@shubhamc-ins
Copy link
Contributor Author

shubhamc-ins commented Nov 26, 2024

Hi @SyntaxNode , did you get time to check the updates? #3806 (comment)

Thanks!

@bsardo
Copy link
Collaborator

bsardo commented Dec 4, 2024

@bretg I have the updated the iframe syncing, it is calling the PBS host /setuid endpoint, and it is not syncing more than 10 DSPs now. Please check.

Here's a screenshot for your reference. image

Cookie syncing LGTM. Verified the PBS setuid endpoint is being called, the cookie is being updated with the insticator user ID and no more than 10 DSPs are being called.

Copy link
Collaborator

@bsardo bsardo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionally things look good but there is a lot of missing test coverage. Please see my comments.

Comment on lines +7 to +9
func RoundTo4Decimals(amount float64) float64 {
return math.Round(amount*10000) / 10000
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create mathutil_test.go with a unit test for this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added unit test for it.


func TestJsonSamples(t *testing.T) {
bidder, buildErr := Builder(openrtb_ext.BidderInsticator, config.Adapter{
Endpoint: "https://ex.ingage.tech/v1/prebidserver"},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We recommend using a fake URL for tests for maintenance reasons.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

func TestJsonSamples(t *testing.T) {
bidder, buildErr := Builder(openrtb_ext.BidderInsticator, config.Adapter{
Endpoint: "https://ex.ingage.tech/v1/prebidserver"},
config.Server{ExternalUrl: "https://ex.ingage.tech/v1/prebidserver", GvlID: 1, DataCenter: "2"})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We recommend using a fake URL for tests for maintenance reasons.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines 145 to 156
if len(request.Device.UA) > 0 {
headers.Add("User-Agent", request.Device.UA)
}

if len(request.Device.IPv6) > 0 {
headers.Add("X-Forwarded-For", request.Device.IPv6)
}

if len(request.Device.IP) > 0 {
headers.Add("X-Forwarded-For", request.Device.IP)
headers.Add("IP", request.Device.IP)
}
Copy link
Collaborator

@bsardo bsardo Dec 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're missing some test coverage here. I suggest the following:

  1. Either update an existing exemplary test or add a new supplemental JSON test where .device.ua, .device.ipv6 and .device.ip are set
  2. Add a supplemental JSON test where .device is not nil but .device.ua, device.ipv6 and .device.ip are of zero length.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added a new adapters/insticator/insticatortest/supplemental/device-validation.json and added device object in one or two old files too.


// Unmarshal the imp extension to get the publisher ID
if err := jsonutil.Unmarshal(imp.Ext, &ext); err != nil {
return &errortypes.BadInput{Message: "Error unmarshalling imp extension"}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a supplemental JSON test case where attempting to unmarshal imp.ext fails. You should be able to force this by simply setting imp.ext.insticator in your JSON test to an invalid type which would be something other than an object (e.g. a string).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this should never be non-empty. The ext definition you are using here is looking for the field name 'insticator' rather than bidder which is always translated to bidder by PBS core.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unmarshal step has been removed.

Comment on lines +268 to +269
floor, err := reqInfo.ConvertCurrency(bidFloor, bidFloorCur, "USD")
return mathutil.RoundTo4Decimals(floor), err
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're missing test coverage here. Please add the following supplemental JSON test cases:

  1. currency conversion is successful resulting in a bid floor that is greater than 0
  2. currency conversion fails

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


if len(request.Ext) > 0 {
if err := jsonutil.Unmarshal(request.Ext, &reqExt); err != nil {
return nil, err
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a supplemental JSON test case where attempting to unmarshal request.ext fails. You should be able to force this by simply setting request.ext.insticator in your JSON test to an invalid type which would be something other than an object (e.g. a string).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added adapters/insticator/insticatortest/supplemental/request-ext-unmarhal-fail.json


func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) {
if adapters.IsResponseStatusCodeNoContent(responseData) {
return nil, nil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a supplemental JSON test where your mock response returns a 204 status code.

Copy link
Contributor Author

@shubhamc-ins shubhamc-ins Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


var response openrtb2.BidResponse
if err := jsonutil.Unmarshal(responseData.Body, &response); err != nil {
return nil, []error{err}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a supplemental JSON test where your mock response returns a bid response that cannot be successuflly unmarshalled. This can be accomplished by making one of the fields the wrong type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this test testing? The filename says multi-imp but I only see one imp and I don't see anything failing validation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated this test case, added both video and banner imps.

Copy link

github-actions bot commented Dec 6, 2024

Code coverage summary

Note:

  • Prebid team doesn't anticipate tests covering code paths that might result in marshal and unmarshal errors
  • Coverage summary encompasses all commits leading up to the latest one, fdcdc59

insticator

Refer here for heat map coverage report

github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:56:	Builder			100.0%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:64:	getMediaTypeForBid	100.0%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:75:	MakeRequests		90.0%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:131:	makeRequest		93.8%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:167:	MakeBids		100.0%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:199:	makeImps		86.7%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:243:	makeReqExt		100.0%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:265:	resolveBidFloor		100.0%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:274:	validateVideoParams	100.0%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:285:	populatePublisherId	95.0%
total:										(statements)		94.2%

@shubhamc-ins
Copy link
Contributor Author

@bsardo Thanks a lot for your time. I have updated the PR with all the test cases. Please take a look :)

@shubhamc-ins shubhamc-ins requested a review from bsardo December 7, 2024 07:09

// Populate site.publisher.id from imp extension
if requestCopy.Site != nil || requestCopy.App != nil {
if err := populatePublisherId(&impCopy, &requestCopy); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will unmarshal the imp.ext of the current imp and update the site/app object's publisher ID to match. It will repeat this process for every imp in the request. It would be much more efficient to remove this step from the loop, and just execute this for the last imp in the list, as it will have the same result and only consume 1/len(Imp) as many cycles.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I know. I was doing the same previously but someone previously asked to update it.

#3806 (comment)

@hhhjort

return bidResponse, nil
}

func makeImps(imp openrtb2.Imp) (openrtb2.Imp, string, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may make sense to return the publisher ID here, since you unmarshal the imp.ext here. This would save you from unmarshalling it again in populatePublisherID(). Or possibly move the unmarshal into the Imp loop and pass the unmarshalled structure into this function.

Copy link
Contributor Author

@shubhamc-ins shubhamc-ins Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see @hhhjort

what do you think of this ?

for i := 0; i < len(request.Imp); i++ {
                // I will return publisherId from the makeImps, and use it in next step
		impCopy, impKey, publisherId, err := makeImps(request.Imp[i])
		if err != nil {
			errs = append(errs, err)
			continue
		}

		// Populate publisher.id from imp extension only once for the first imp
		if (requestCopy.Site != nil || requestCopy.App != nil) && i == 0  {
                        // use publisherId here
			if err := populatePublisherId(publisherId, &requestCopy); err != nil {
				errs = append(errs, err)
				continue
			}
		}

... rest code

and I will remove the Unmarshal from populatePublisherId

func populatePublisherId(imp *openrtb2.Imp, request *openrtb2.BidRequest) error {
	// this will be removed
       //  var ext ext

	// Unmarshal the imp extension to get the publisher ID
	// if err := jsonutil.Unmarshal(imp.Ext, &ext); err != nil {
	// 	return &errortypes.BadInput{Message: "Error unmarshalling imp extension"}
	// }

	// Populate site.publisher.id if request.Site is not nil
	if request.Site != nil {

.... Rest code

@bsardo bsardo assigned hhhjort and unassigned SyntaxNode Dec 9, 2024
Copy link

github-actions bot commented Dec 9, 2024

Code coverage summary

Note:

  • Prebid team doesn't anticipate tests covering code paths that might result in marshal and unmarshal errors
  • Coverage summary encompasses all commits leading up to the latest one, d8f3ca3

insticator

Refer here for heat map coverage report

github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:56:	Builder			100.0%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:64:	getMediaTypeForBid	100.0%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:75:	MakeRequests		90.6%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:133:	makeRequest		93.8%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:169:	MakeBids		100.0%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:201:	makeImps		86.7%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:245:	makeReqExt		100.0%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:267:	resolveBidFloor		100.0%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:276:	validateVideoParams	100.0%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:287:	populatePublisherId	100.0%
total:										(statements)		95.0%

@shubhamc-ins
Copy link
Contributor Author

shubhamc-ins commented Dec 9, 2024

@hhhjort updated the PR with your suggestions. Please take a look. Thanks :)

@shubhamc-ins shubhamc-ins requested a review from hhhjort December 9, 2024 20:54
Copy link
Collaborator

@bsardo bsardo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're very close. I have just a few more comments.

}
},

"httpCalls": [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can verify the headers, specifically the device related ones, are set correctly given that you have a device object here by including the following:

"httpCalls": [
    {
      "expectedRequest": {
        "headers": {
          "Content-Type": [
            "application/json;charset=utf-8"
          ],
          "Accept": [
            "application/json"
          ],
          etc...
``

(video.H == nil || *video.H == 0) ||
video.MIMEs == nil {

if (video.W == nil || *video.W == 0) || (video.H == nil || *video.H == 0) || video.MIMEs == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: you should be able to delete the parentheses

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: file name typo -unmarhal-fail.json --> -unmarshal-fail.json

"device": {
"ipv6": "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
"ip": "1.22.22.1",
"ua": "Mozilla/5.0 (Linux; Android 8.0.0; SM-G960F Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.84 Mobile Safari/537.36"
}
},

"httpCalls": [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please verify the headers are set correctly in this test since some of them are derived from the device object. You can do so like this:

"httpCalls": [
    {
      "expectedRequest": {
        "headers": {
          "Content-Type": [
            "application/json;charset=utf-8"
          ],
          "Accept": [
            "application/json"
          ],
          etc...
``

if requestCopy.Site != nil || requestCopy.App != nil {
if err := populatePublisherId(&impCopy, &requestCopy); err != nil {
// Populate publisher.id from imp extension
if !isPublisherIdPopulated && (requestCopy.Site != nil || requestCopy.App != nil) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simplify this to just if !isPublisherIdPopulated { since you've only declared support for site and app (not dooh) in your YAML file which means your adapter will only be called if site or app is present.

}

// populatePublisherId function populates site.publisher.id or app.publisher.id
func populatePublisherId(publisherId string, request *openrtb2.BidRequest) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function does not return an error anymore so please remove that return parameter.

@shubhamc-ins
Copy link
Contributor Author

@bsardo Thanks for checking, I have updated the PR.

Copy link

Code coverage summary

Note:

  • Prebid team doesn't anticipate tests covering code paths that might result in marshal and unmarshal errors
  • Coverage summary encompasses all commits leading up to the latest one, f0d12f0

insticator

Refer here for heat map coverage report

github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:56:	Builder			100.0%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:64:	getMediaTypeForBid	100.0%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:75:	MakeRequests		96.7%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:130:	makeRequest		93.8%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:166:	MakeBids		100.0%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:198:	makeImps		86.7%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:242:	makeReqExt		100.0%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:264:	resolveBidFloor		100.0%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:273:	validateVideoParams	100.0%
github.com/prebid/prebid-server/v3/adapters/insticator/insticator.go:284:	populatePublisherId	100.0%
total:										(statements)		96.6%

@shubhamc-ins shubhamc-ins requested a review from bsardo December 12, 2024 18:57
Copy link
Collaborator

@hhhjort hhhjort left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bsardo bsardo merged commit 69dd6e9 into prebid:master Dec 12, 2024
5 checks passed
@przemkaczmarek przemkaczmarek self-assigned this Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants