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

Added TransmitPreciseGeo activity handling in modules #3348

Merged
merged 9 commits into from
Jan 16, 2024

Conversation

VeronikaSolovei9
Copy link
Contributor

No description provided.

Copy link
Contributor

@AlexBVolcy AlexBVolcy left a comment

Choose a reason for hiding this comment

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

This looks good! Just left one very minor nitpick.

@@ -49,13 +55,45 @@ func TestHandleModuleActivitiesBidderRequestPayload(t *testing.T) {
}},
},
},

Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: can you remove this blank line?

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 refactored func handleModuleActivities the way you proposed to refactor similar function in analytics activities to reduce nesting.

@@ -68,6 +68,7 @@ func NewHookExecutor(builder hooks.ExecutionPlanBuilder, endpoint string, me met
stageOutcomes: []StageOutcome{},
moduleContexts: &moduleContexts{ctxs: make(map[string]hookstage.ModuleContext)},
metricEngine: me,
account: &config.Account{Privacy: config.AccountPrivacy{}},
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the motivation for creating an empty account here instead of just keeping it as nil until an account is set on the hookExecutor using SetAccount? It seems like an attempt to avoid nil checks when executing each stage but I'm not sure that's a good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed. I changed handleModuleActivities function signature to accept account *config.Account instead of AccountPrivacy.

@@ -760,7 +760,7 @@ func TestExecuteProcessedAuctionStage(t *testing.T) {
{
description: "Stage execution can be rejected - and later hooks rejected",
givenPlanBuilder: TestRejectPlanBuilder{},
givenAccount: nil,
givenAccount: account,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to pass account here, because we want to test that BidRequest will not change even if we restrict activities: getModuleActivities("foo", false, false) and payload for the hook will be modified.

Copy link
Contributor

Choose a reason for hiding this comment

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

If we add the account nil check in handleModuleActivities we shouldn't need to define an account here right? The way this test case is currently constructed, it seems like the only reason an account is being passed here now is to ensure PBS doesn't crash.

AlexBVolcy
AlexBVolcy previously approved these changes Jan 4, 2024
@@ -10,6 +10,12 @@ import (
"testing"
)

const (
testIpv6 = "1111:2222:3333:4444:5555:6666:7777:8888"
testIPv6Scubbed = "1111:2222::"
Copy link
Contributor

Choose a reason for hiding this comment

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

Super nitpick: typo Scrubbed

@@ -137,13 +206,27 @@ func TestHandleModuleActivitiesNoBidderRequestPayload(t *testing.T) {
privacyConfig: getTransmitUFPDActivityConfig("foo", true),
expectedPayloadData: hookstage.RawAuctionRequestPayload{},
},
{
description: "payload should change when transmitPreciseGeo is blocked by activity",
Copy link
Contributor

Choose a reason for hiding this comment

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

Some of the test cases in this test have descriptions that indicate the payload should change but it doesn't.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, description fixed. Payload should NOT change in any of these cases, because hookstage.RawAuctionRequestPayload doesn't implement hookstage.RequestUpdater

if !transmitUserFPDActivityAllowed {
privacy.ScrubUserFPD(bidderReqCopy)
}
if !transmitPreciseGeoActivityAllowed {
Copy link
Contributor

Choose a reason for hiding this comment

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

In practice there should always be an account if we've gotten this far but perhaps we should add a check here to make sure the account is not nil just to be safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct, in practice we will always have an account because we call hookExecutor.SetAccount(account) in auction and amp_auction.
In order to add nil check for account, what do we expect to do if for some reason account is nil?

  1. skip activity execution: privacy.ScrubGeoAndDeviceIP(bidderReqCopy, ipConf)
  2. set default masking values(which also should be already set) and execute activity with default values:
    account.Privacy.IPv6Config.AnonKeepBits = iputil.IPv6DefaultMaskingBitSize and
    account.Privacy.IPv4Config.AnonKeepBits = iputil.IPv4DefaultMaskingBitSize

Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest option 2 so that we still scrub given the sensitive nature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@@ -699,7 +699,7 @@ func TestExecuteRawAuctionStage(t *testing.T) {

func TestExecuteProcessedAuctionStage(t *testing.T) {
foobarModuleCtx := &moduleContexts{ctxs: map[string]hookstage.ModuleContext{"foobar": nil}}
account := &config.Account{}
account := &config.Account{Privacy: config.AccountPrivacy{}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: you shouldn't need to specify Privacy because you're defining a zero value account which will create a nested zero value Privacy object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, privacy is not a pointer. Removed.

@@ -760,7 +760,7 @@ func TestExecuteProcessedAuctionStage(t *testing.T) {
{
description: "Stage execution can be rejected - and later hooks rejected",
givenPlanBuilder: TestRejectPlanBuilder{},
givenAccount: nil,
givenAccount: account,
Copy link
Contributor

Choose a reason for hiding this comment

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

If we add the account nil check in handleModuleActivities we shouldn't need to define an account here right? The way this test case is currently constructed, it seems like the only reason an account is being passed here now is to ensure PBS doesn't crash.

@VeronikaSolovei9
Copy link
Contributor Author

VeronikaSolovei9 commented Jan 9, 2024

If we add the account nil check in handleModuleActivities we shouldn't need to define an account here right? The way this test case is currently constructed, it seems like the only reason an account is being passed here now is to ensure PBS doesn't crash.

Yes, it's needed for this test only. Do you think we may need to pass account with non-default values in future?
Currently in all test cases input account is just a not nil account:&config.Account{}.
We need to decide if we want to add a nil check for it in handleModuleActivities, I commented about possible cases in another comment above.

@@ -699,7 +699,6 @@ func TestExecuteRawAuctionStage(t *testing.T) {

func TestExecuteProcessedAuctionStage(t *testing.T) {
foobarModuleCtx := &moduleContexts{ctxs: map[string]hookstage.ModuleContext{"foobar": nil}}
account := &config.Account{}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we want to remove this from every test in this file?

Copy link
Contributor

Choose a reason for hiding this comment

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

I went through and tried removing all of these lines, and the tests still passed, so I think it can be removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with Alex; we can remove them.

@VeronikaSolovei9 VeronikaSolovei9 merged commit 27b2ff6 into master Jan 16, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants