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

feat: enrich with geo location data during destination transformation #2803

Closed
wants to merge 29 commits into from

Conversation

sanpj2292
Copy link
Contributor

@sanpj2292 sanpj2292 commented Nov 7, 2023

Description of the change

We are enriching the event payload with geo-location data just before destination transformation

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Related issues

Resolves INT-1000
Resolved INT-1001

Checklists

Development

  • Lint rules pass locally
  • The code changed/added as part of this pull request has been covered with tests
  • All tests related to the changed code pass in development

Code review

  • This pull request has a descriptive title and information useful to a reviewer. There may be a screenshot or screencast attached
  • "Ready for review" label attached to the PR and reviewers mentioned in a comment
  • Changes have been reviewed by at least one other engineer
  • Issue from task tracker has a link to this pull request

Copy link

codecov bot commented Nov 7, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (a6f7d13) 87.11% compared to head (a2f0747) 87.13%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2803      +/-   ##
===========================================
+ Coverage    87.11%   87.13%   +0.02%     
===========================================
  Files          768      770       +2     
  Lines        28653    28714      +61     
  Branches      6726     6740      +14     
===========================================
+ Hits         24960    25021      +61     
  Misses        3350     3350              
  Partials       343      343              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sai Sankeerth added 5 commits November 7, 2023 18:40
- add router transformation test-case
- change test-case for helper for first-key found logic

Signed-off-by: Sai Sankeerth <[email protected]>
@sanpj2292 sanpj2292 marked this pull request as ready for review November 8, 2023 05:45
@sanpj2292 sanpj2292 requested review from a team and sivashanmukh as code owners November 8, 2023 05:45
Sai Sankeerth added 2 commits November 8, 2023 19:22
…ints & asynchronise geolocation enricher

Signed-off-by: Sai Sankeerth <[email protected]>
src/helpers/geoLocation.ts Show resolved Hide resolved
src/middlewares/enricher.ts Show resolved Hide resolved
src/helpers/geoLocation.ts Outdated Show resolved Hide resolved
src/helpers/geoLocation.ts Outdated Show resolved Hide resolved
src/helpers/geoLocation.ts Outdated Show resolved Hide resolved
src/v0/util/index.js Outdated Show resolved Hide resolved
src/v0/util/index.js Outdated Show resolved Hide resolved
src/v0/util/index.js Outdated Show resolved Hide resolved
src/v0/util/index.js Outdated Show resolved Hide resolved
src/helpers/geoLocation.ts Outdated Show resolved Hide resolved
Sai Sankeerth added 3 commits November 9, 2023 17:34
- simplify logic for finding addressKey
- update name of first matching key-value pair finder function
- simplify logic for finding first key-value pair
- add validation on message to be an object to perform search operation

Signed-off-by: Sai Sankeerth <[email protected]>
…tead of identifying the valid values manually, added test-cases

Signed-off-by: Sai Sankeerth <[email protected]>
@sanpj2292 sanpj2292 self-assigned this Nov 9, 2023
Sai Sankeerth added 2 commits November 9, 2023 20:07
Signed-off-by: Sai Sankeerth <[email protected]>
properties: object;
traits: object;
[key: string]: FixMe;
}>;

type RouterTransformationRequestData = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is low level struct used in both process & routerTransform flow, so shouldn't the name be neutral ?

Suggested change
type RouterTransformationRequestData = {
type EventRequestData = {

Copy link
Contributor Author

@sanpj2292 sanpj2292 Nov 9, 2023

Choose a reason for hiding this comment

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

Basically it was named as RouterTransformationRequestData previously but since the elements in the type were common, I used it as a low-level struct.

Tried to change name, there are many files which are using this type. I feel this is a little bigger change & out of scope of this task. May be we can handle this in a backlog item and make a change independent of this task. But yeah, let me know if we are ok with making this change as part of this PR.

| 'alias'
| 'audiencelist';

type RudderMessageSchema = Partial<{
Copy link
Collaborator

Choose a reason for hiding this comment

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

there's RudderMessage too -

type RudderMessage = {

Do we need both of them ?

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 used RudderMessage itself but there were too many changes that were needed in order for the tests to pass & compile. So, kind of yes, we need both of them.
[Backlog] We have to plan to get rid of both of these types & stick with only one type.

receivedAt: '2020-04-17T20:12:44.758+05:30',
request_ip: '[::1]:53513',
sentAt: '2020-04-17T14:42:44.722Z',
traits: {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the test case meant to have address but not context.geo ?
Next test case is exactly same

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 the case to have address but not context.geo

message: {
anonymousId: 'ac7722c2-ccb6-4ae2-baf6-1effe861f4cd',
channel: 'web',
context: {
Copy link
Collaborator

Choose a reason for hiding this comment

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

As we are not asserting other attributes & that's not the scope in unit test here, can keep the context object simple by restricting to only context.geo or empty context

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. Incorporated the suggestions

key: 'rivals.spain',
},
},
];
Copy link
Collaborator

@krishna2020 krishna2020 Nov 9, 2023

Choose a reason for hiding this comment

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

should we also have a test case where both 'spain.rivals', 'rivals.spain' would be present in the object ?
If the customer instruments address at both the places ? ["traits.address", "context.traits.address"]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. Will include one such case

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

@sanpj2292 sanpj2292 requested a review from krishna2020 November 9, 2023 17:40
src/v0/util/index.js Outdated Show resolved Hide resolved
src/helpers/geoLocation.ts Outdated Show resolved Hide resolved
return { key: addressKey, value };
}

public static getMessageWithGeoLocationData(
Copy link
Contributor

Choose a reason for hiding this comment

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

what do you think about name enrichMessageAddressWithGeoData ?

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

src/middlewares/enricher.ts Outdated Show resolved Hide resolved
private static enrichWithGeoInfo(
data: RouterTransformationRequestData[],
): RouterTransformationRequestData[] {
return data.map((inpEv) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

acronyms like inpEv might not be readable, let's name them as input or event or inputEvent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Incorporated

Sai Sankeerth added 2 commits November 10, 2023 14:50
- update enricher class name, method, var name & update related test-cases
- return value as undefined when anything apart from Array or object is sent for searching
- make use of msg rather than message

Signed-off-by: Sai Sankeerth <[email protected]>
Copy link
Contributor

@abhimanyubabbar abhimanyubabbar left a comment

Choose a reason for hiding this comment

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

Except for one last comment made, the changes to me look good.

Copy link
Contributor

@abhimanyubabbar abhimanyubabbar left a comment

Choose a reason for hiding this comment

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

LGTM

src/v0/util/index.js Outdated Show resolved Hide resolved
src/helpers/geoLocation.ts Show resolved Hide resolved
src/helpers/geoLocation.ts Outdated Show resolved Hide resolved
src/helpers/geoLocation.ts Show resolved Hide resolved
src/middlewares/enricher.ts Outdated Show resolved Hide resolved
Sai Sankeerth added 2 commits November 14, 2023 15:19
- move DTRequest to types/index.ts
- remove unnecessary optional chaining

Signed-off-by: Sai Sankeerth <[email protected]>
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@sanpj2292
Copy link
Contributor Author

Closing this PR as these changes are not necessary

@sanpj2292 sanpj2292 closed this Dec 1, 2023
@devops-github-rudderstack devops-github-rudderstack deleted the feat.enrich-geo-location branch February 15, 2024 01:22
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.

4 participants