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
Event Tracking: Macro Replacement Framework. #2629
Conversation
* 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>
…ic-OpenWrap/prebid-server into I1725_vast_event_trackers
* OTT-422: Adding support for eventType=vast in analytic endpoint * Adding test cases
* OTT-485: Macro Replacement framework (#432)
* OTT-485: Removing Template based approach and config
* Removing macro processor config
* OTT-485: Changing macro prefix from PBS_ to PBS-
@bsardo Can you please review the PR? |
Added comments. |
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.
Thank you for all changes. Would you consider to modify comments a little? Please see suggestions below.
} | ||
} | ||
|
||
func constructTemplate(url string) urlMetaTemplate { |
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.
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.
// 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. |
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.
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.
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.
Done
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.
Thank you for all changes. Would you consider to modify comments a little? Please see suggestions above.
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.
@Pubmatic-Dhruv-Sonone Looking great other than very minor comments
if endingIndex == -1 { | ||
break | ||
} | ||
endingIndex = endingIndex + startIndex // offset adjustment (Delimiter inclusive) |
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.
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.
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.
Done
if value != "" { | ||
result.WriteString(value) | ||
} | ||
currentIndex = index + len(macro) + delimLen |
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.
Wouldn't it be easier to just do
currentIndex = endingIndex + delimLen
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.
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 |
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.
@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()) |
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.
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
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.
Done
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.
@Pubmatic-Dhruv-Sonone Looking great other than very minor comments
Looks like there are.a few merge conflicts to resolve. |
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.
@Pubmatic-Dhruv-Sonone LGTM other than the minor comment about parameter ordering in one of the assert.Equal
call
macros/provider_test.go
Outdated
for key := range tt.want { | ||
output[key] = b.GetMacro(key) | ||
} | ||
assert.Equal(t, output, tt.want, tt.name) |
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.
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)
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.
Done
Co-authored-by: Shriprasad <shriprasad.marathe@pubmatic.com>
BenchMark Results: