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

Event Tracking: Macro Replacement Framework. #2629

Merged
merged 66 commits into from May 30, 2023

Conversation

Pubmatic-Dhruv-Sonone
Copy link
Contributor

@Pubmatic-Dhruv-Sonone Pubmatic-Dhruv-Sonone commented Mar 8, 2023

BenchMark Results:

// 1) ^BenchmarkStringIndexCachedBasedReplacer$ github.com/prebid/prebid-server/macros
// goos: darwin
// goarch: amd64
// pkg: github.com/prebid/prebid-server/macros
// cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
// BenchmarkStringIndexCachedBasedReplacer-12    	   65348	     17148 ns/op	   12617 B/op	      56 allocs/op
// PASS
// ok  	github.com/prebid/prebid-server/macros	2.446s
// 2) ^BenchmarkGolangReplacer$ github.com/prebid/prebid-server/macros
// goos: darwin
// goarch: amd64
// pkg: github.com/prebid/prebid-server/macros
// cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
// BenchmarkGolangReplacer-12    	   10926	     99165 ns/op	   81887 B/op	     603 allocs/op
// PASS
// ok  	github.com/prebid/prebid-server/macros	2.144s

* OTT-421: Unit tests and basic framework for events consumption and validation
* OTT-421: Changed eventvalidation interface according to configuration.validate() requirements
* OTT-421: Made validate method from eventvalidation.go private

Co-authored-by: Shriprasad <shriprasad.marathe@pubmatic.com>
* OTT-421: Added note to not enabled this feature. Because, it is still in progress

Co-authored-by: Shriprasad <shriprasad.marathe@pubmatic.com>
…entscoments (#255)

* OTT-421: Addressed code review comments

Co-authored-by: Shriprasad <shriprasad.marathe@pubmatic.com>
…res) (#256)

* OTT-421: Fixed test failures

Co-authored-by: Shriprasad <shriprasad.marathe@pubmatic.com>
* OTT-421: Added warning when events.enabled is true

Co-authored-by: Shriprasad <shriprasad.marathe@pubmatic.com>
…ents - 2) (#258)

* OTT-421: Unit tests and basic framework for events consumption and validation

* OTT-421: Reverted unwanted change.

* OTT-421: Changed eventvalidation interface according to configuration.validate() requirements

* OTT-421: Reverted unwanted change

* OTT-421: Made validate method from eventvalidation.go private

* OTT-421: Added note to not enabled this feature. Because, it is still in progress

* OTT-421: Temporary print statement

* OTT-421: Addressed code review comments

* OTT-421: Fixed test failures

* OTT-421: Added warning when events.enabled is true

* OTT-421: Addressed code review comments

* OTT-421: Disabled event validations

* OTT-421: Reverted stored_requests/data/by_id/accounts/test.json

* OTT-421: Removed unwanted comment

Co-authored-by: Shriprasad <shriprasad.marathe@pubmatic.com>
* OTT-421: Disabled event validations
Co-authored-by: Shriprasad <shriprasad.marathe@pubmatic.com>
* OTT-422: Adding support for eventType=vast in analytic endpoint

* Adding test cases
* OTT-485: Macro Replacement framework (#432)
@SyntaxNode SyntaxNode changed the title I1725: Macro Replacement Framework. Event Tracking: Macro Replacement Framework. Mar 8, 2023
@bsardo bsardo self-assigned this Mar 8, 2023
* OTT-485: Removing Template based approach and config
* Removing macro processor config
* OTT-485: Changing macro prefix from PBS_ to PBS-
@Pubmatic-Dhruv-Sonone
Copy link
Contributor Author

@bsardo Can you please review the PR?

@bsardo bsardo assigned SyntaxNode and mansinahar and unassigned bsardo Apr 3, 2023
@Pubmatic-Dhruv-Sonone
Copy link
Contributor Author

@Pubmatic-Dhruv-Sonone discussed possible changes in string-based.go. We decided to leave everything as is there. Despite our current PBS is configured to load host and account data at the server start up, we need to support flexibility and give other hosts an ability to "lazy-load" account data. Regarding string replacement mechanism we agreed to move with more productive approach.

May you please add comments to describe the replacement algorithm, so it will be easier to understand in future reviewing and maintenance?

Thank you for your explanations and efforts!

Added comments.

Copy link
Contributor

@VeronikaSolovei9 VeronikaSolovei9 left a comment

Choose a reason for hiding this comment

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

Thank you for all changes. Would you consider to modify comments a little? Please see suggestions below.

}
}

func constructTemplate(url string) urlMetaTemplate {
Copy link
Contributor

Choose a reason for hiding this comment

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

How about this comment:

// constructTemplate func finds index bounds of all macros in an input string where macro format is ##data##.
// constructTemplate func returns two arrays with start indexes and end indexes for all macros found in the input string.
// Start index of the macro points to the index of the delimiter(##) start.
// End index of the macro points to the end index of the delimiter.
// For the valid input string number of start and end indexes should be equal, and they should not intersect.
// This approach shows better performance results compare to standard GoLang string replacer. 

Comment on lines 63 to 67
// Replace will replace the macros in the given event url.
// Check if urlMetaTemplate exist in cache for given url if not construct the template (start and end index info of each macro) and store in cache.
// Iterate over the startingIndices in the template and for each starting index and corresponding ending index, extract macro from the url.
// Get the value of the macro from the macroProvider.
// Prepend the url string present before the macro to the macro value and append the remaining url.
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you consider to modify it to:

// Replace function replaces macros in a given string with the data from macroProvider and returns modified input string.
// If a given string was previously processed this function fetches its metadata from the cache. 
// If input string is not found in cache then template metadata will be created. 
// Iterates over start and end indexes of the template arrays and extracts macro name from the input string.
// Gets the value of the extracted macro from the macroProvider. Replaces macro with corresponding value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@VeronikaSolovei9 VeronikaSolovei9 left a comment

Choose a reason for hiding this comment

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

Thank you for all changes. Would you consider to modify comments a little? Please see suggestions above.

Copy link
Contributor

@mansinahar mansinahar left a comment

Choose a reason for hiding this comment

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

@Pubmatic-Dhruv-Sonone Looking great other than very minor comments

if endingIndex == -1 {
break
}
endingIndex = endingIndex + startIndex // offset adjustment (Delimiter inclusive)
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be

endingIndex = startIndex + endingIndex - 1

the endingIndex returned by the strings.Index function on L48 would be the index of first ending delimiter char not the ending index of the macro key.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

if value != "" {
result.WriteString(value)
}
currentIndex = index + len(macro) + delimLen
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be easier to just do

currentIndex = endingIndex + delimLen

Copy link
Contributor Author

Choose a reason for hiding this comment

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

currentIndex = endingIndex + delimLen won't work after making changes as per above comment.

currentIndex = endingIndex + 1 + delimLen will work., but the current implement looks more easier to understand to me.

Should I keep it as it is or change to currentIndex = endingIndex + 1 + delimLen?


func TestGetMacro(t *testing.T) {
type args struct {
key string
Copy link
Contributor

Choose a reason for hiding this comment

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

@Pubmatic-Dhruv-Sonone As mentioned in my previous comment,

In this case we just wanna test the logic in GetMacro function and that just retrieves and returns the macro in the map.

So you don't need to add a test case for each macro key in here. 1-2 keys are enough. The logic we need to check is that if macro is present in provider, it will return it. If not, it won't. GetMacro knows nothing about the specific keys so test cases for each macro key don't add much value here.

router/router.go Outdated
@@ -214,7 +215,8 @@ func New(cfg *config.Configuration, rateConvertor *currency.RateConverter) (r *R
}

planBuilder := hooks.NewExecutionPlanBuilder(cfg.Hooks, repo)
theExchange := exchange.NewExchange(adapters, cacheClient, cfg, syncersByBidder, r.MetricsEngine, cfg.BidderInfos, gdprPermsBuilder, tcf2CfgBuilder, rateConvertor, categoriesFetcher, adsCertSigner)
theExchange := exchange.NewExchange(adapters, cacheClient, cfg, syncersByBidder, r.MetricsEngine, cfg.BidderInfos, gdprPermsBuilder, tcf2CfgBuilder, rateConvertor, categoriesFetcher, adsCertSigner, macros.NewStringIndexBasedReplacer())
Copy link
Contributor

Choose a reason for hiding this comment

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

I recommend instantiating macroReplacer before this line and then use that variable as parameter to NewExchange so that it is explicit and clear to the reader what macroReplcer is being used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@mansinahar mansinahar left a comment

Choose a reason for hiding this comment

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

@Pubmatic-Dhruv-Sonone Looking great other than very minor comments

@hhhjort
Copy link
Collaborator

hhhjort commented May 18, 2023

Looks like there are.a few merge conflicts to resolve.

Copy link
Contributor

@mansinahar mansinahar left a comment

Choose a reason for hiding this comment

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

@Pubmatic-Dhruv-Sonone LGTM other than the minor comment about parameter ordering in one of the assert.Equal call

for key := range tt.want {
output[key] = b.GetMacro(key)
}
assert.Equal(t, output, tt.want, tt.name)
Copy link
Contributor

Choose a reason for hiding this comment

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

The order here for assert.Equal arguments needs to be expected then actual. So, can you please change it to:

assert.Equal(t, tt.want, output, tt.name)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@bsardo bsardo merged commit 9b0fb7f into prebid:master May 30, 2023
3 checks passed
blueseasx pushed a commit to blueseasx/prebid-server that referenced this pull request Jun 2, 2023
Co-authored-by: Shriprasad <shriprasad.marathe@pubmatic.com>
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.

None yet

8 participants