Repository navigation
fix(dynamicConfigParser): fix cloning issue in getdynamicconfig method - #4278
Conversation
Summary by CodeRabbit
Summary by CodeRabbit
WalkthroughA new test suite for the Changes
Sequence Diagram(s)sequenceDiagram
participant TestSuite
participant DynamicConfigParser
participant configureVal
TestSuite->>DynamicConfigParser: process(event)
DynamicConfigParser->>DynamicConfigParser: clone event to resultantEvent
DynamicConfigParser->>DynamicConfigParser: getDynamicConfig(resultantEvent)
DynamicConfigParser->>configureVal: configureVal(Config, resultantEvent)
configureVal-->>DynamicConfigParser: resolved Config
DynamicConfigParser-->>TestSuite: processed event with resolved Config
Suggestions for Improvement:
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
0ac3092 to
c9f4fd0
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/util/dynamicConfigParser.ts (1)
65-66: Consider using class name instead ofthisin static methods.Using
thisin static methods can be confusing as noted by the static analysis tool. While it works correctly, it would be more conventional to use the class name directly.- resultantEvent.destination.Config = this.configureVal(Config, resultantEvent); + resultantEvent.destination.Config = DynamicConfigParser.configureVal(Config, resultantEvent);🧰 Tools
🪛 Biome (1.9.4)
[error] 66-66: Using this in a static context can be confusing.
this refers to the class.
Unsafe fix: Use the class name instead.(lint/complexity/noThisInStatic)
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 19d9371 and c9f4fd0d823ebb49296b0fc5fea701fbffc6300c.
📒 Files selected for processing (2)
src/util/dynamicConfigParser.test.ts(1 hunks)src/util/dynamicConfigParser.ts(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/util/dynamicConfigParser.test.ts (2)
src/types/destinationTransformation.ts (1)
ProcessorTransformationRequest(18-26)src/util/dynamicConfigParser.ts (1)
DynamicConfigParser(9-79)
🪛 Biome (1.9.4)
src/util/dynamicConfigParser.ts
[error] 66-66: Using this in a static context can be confusing.
this refers to the class.
Unsafe fix: Use the class name instead.
(lint/complexity/noThisInStatic)
⏰ Context from checks skipped due to timeout of 90000ms (8)
- GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
- GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: test_and_publish
- GitHub Check: Code Coverage
- GitHub Check: UT Tests
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Analyze (go)
🔇 Additional comments (6)
src/util/dynamicConfigParser.ts (1)
65-66: Good fix addressing the event cloning issue.You've fixed the bug by correctly extracting the
Configfrom the clonedresultantEvent.destinationrather than the original event. This ensures that any modifications during configuration processing won't affect the original event data, preventing unintended side effects when multiple events share the same destination object reference.🧰 Tools
🪛 Biome (1.9.4)
[error] 66-66: Using this in a static context can be confusing.
this refers to the class.
Unsafe fix: Use the class name instead.(lint/complexity/noThisInStatic)
src/util/dynamicConfigParser.test.ts (5)
5-44: Well-structured test helper function.The
createTestEventhelper function is well implemented, providing a clean way to create test events with customizable configurations, traits, and message types. This improves test readability and maintainability.
49-106: Excellent use of table-driven tests.The table-driven approach for test cases improves code maintainability and makes it easy to add more test scenarios in the future. Your test cases effectively cover basic functionality, nested configurations, default values, and path aliases.
126-150: Good test for handling multiple events.This test effectively verifies that the parser correctly processes multiple events independently, ensuring each event gets its own properly configured destination object.
153-193: Comprehensive message type coverage.The tests appropriately verify that the dynamic configuration parser works correctly across different message types ('identify', 'track', 'page'), which is important for ensuring the fix works in all contexts.
195-284: Excellent test for shared destination objects.This test directly addresses the core issue described in the PR objectives. It verifies that when multiple events share the same destination object reference, the parser returns new destination objects per event without modifying the original shared destination.
c9f4fd0 to
6f44294
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (4)
src/util/dynamicConfigParser.ts (4)
65-66: Good fix for the cloning issue.Your changes correctly ensure that we work with a cloned configuration object from the resultant event rather than the original event. This prevents unintended side effects on the original event data, which was the root cause of the bug mentioned in PR objectives.
Just a minor style improvement suggestion:
- resultantEvent.destination.Config = this.configureVal(Config, resultantEvent); + resultantEvent.destination.Config = DynamicConfigParser.configureVal(Config, resultantEvent);Using the class name instead of
thisin a static method is more explicit and avoids potential confusion.🧰 Tools
🪛 Biome (1.9.4)
[error] 66-66: Using this in a static context can be confusing.
this refers to the class.
Unsafe fix: Use the class name instead.(lint/complexity/noThisInStatic)
61-68: Consider adding error handling for edge cases.The method assumes that
resultantEvent.destinationand itsConfigproperty always exist. Consider adding checks to handle cases where these properties might be undefined.private static getDynamicConfig( event: ProcessorTransformationRequest | RouterTransformationRequestData, ) { const resultantEvent = cloneDeep(event); + if (!resultantEvent.destination) { + return resultantEvent; // Return early if destination is undefined + } const { Config } = resultantEvent.destination; + if (!Config) { + return resultantEvent; // Return early if Config is undefined + } resultantEvent.destination.Config = this.configureVal(Config, resultantEvent); return resultantEvent; }🧰 Tools
🪛 Biome (1.9.4)
[error] 66-66: Using this in a static context can be confusing.
this refers to the class.
Unsafe fix: Use the class name instead.(lint/complexity/noThisInStatic)
1-8: Consider standardizing import style.The codebase mixes ES module imports and CommonJS requires. For consistency and better maintainability, consider standardizing to ES module imports throughout.
import cloneDeep from 'lodash/cloneDeep'; import { ProcessorTransformationRequest, RouterTransformationRequestData } from '../types/index'; import { FixMe } from './types'; - const get = require('get-value'); - const unset = require('unset-value'); + import get from 'get-value'; + import unset from 'unset-value';
10-39: Consider adding method documentation.Adding JSDoc comments to methods would improve code readability and maintainability, especially for complex methods like
getDynamicConfigValue./** * Extracts dynamic config values from template strings. * Processes strings in the format "{{ path || defaultvalue }}" * * @param event - The event object containing the data * @param value - The template string to process * @returns The extracted value or default value */ private static getDynamicConfigValue( event: ProcessorTransformationRequest | RouterTransformationRequestData, value: FixMe, ) { // existing implementation }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between c9f4fd0d823ebb49296b0fc5fea701fbffc6300c and 6f442949ac09dd82e4d2fa15099074854b662b19.
📒 Files selected for processing (2)
src/util/dynamicConfigParser.test.ts(1 hunks)src/util/dynamicConfigParser.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/util/dynamicConfigParser.test.ts
🧰 Additional context used
🪛 Biome (1.9.4)
src/util/dynamicConfigParser.ts
[error] 66-66: Using this in a static context can be confusing.
this refers to the class.
Unsafe fix: Use the class name instead.
(lint/complexity/noThisInStatic)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Analyze (go)
|
Allure Test reports for this run are available at:
|
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a cloning issue in the getdynamicconfig method to ensure that the original event is not modified. It also adds comprehensive and table-driven tests to verify the fix and improve maintainability.
- Fix cloning issue by switching from using the original event to the cloned event when processing destination configuration.
- Add extensive table-driven tests to cover various event scenarios and message types.
- Ensure shared destination objects are not modified unintentionally.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/util/dynamicConfigParser.ts | Corrects the cloning behavior by consistently using the cloned event when processing config. |
| src/util/dynamicConfigParser.test.ts | Adds comprehensive tests including table-driven tests to ensure original events remain unchanged. |
Resolves INT-3571 - Fix bug where original event was being modified instead of cloned event - Add comprehensive tests to verify the fix works correctly - Implement table-driven tests for better maintainability
6f44294 to
8860a9d
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/util/dynamicConfigParser.ts (1)
65-66: Consider using explicit class name instead of 'this' in static methodWhile the code works correctly, using
thisin a static context can be confusing. For better clarity and consistency, consider using the class name explicitly.- resultantEvent.destination.Config = this.configureVal(Config, resultantEvent); + resultantEvent.destination.Config = DynamicConfigParser.configureVal(Config, resultantEvent);🧰 Tools
🪛 Biome (1.9.4)
[error] 66-66: Using this in a static context can be confusing.
this refers to the class.
Unsafe fix: Use the class name instead.(lint/complexity/noThisInStatic)
src/util/dynamicConfigParser.test.ts (1)
109-124: Consider adding a test for non-string configurationsWhile the current tests are comprehensive, I noticed that there's no explicit test for configurations containing non-string values (numbers, booleans, null, etc.) that shouldn't be processed for dynamic values.
Consider adding a test case like:
{ name: 'should not process non-string configuration values', config: { stringKey: '{{ message.traits.appId || "default-api-key" }}', numberKey: 42, booleanKey: true, nullKey: null }, traits: { appId: 'test-app-id' }, expectedConfig: { stringKey: 'test-app-id', numberKey: 42, booleanKey: true, nullKey: null } }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 6f442949ac09dd82e4d2fa15099074854b662b19 and 8860a9d.
📒 Files selected for processing (2)
src/util/dynamicConfigParser.test.ts(1 hunks)src/util/dynamicConfigParser.ts(1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/util/dynamicConfigParser.ts
[error] 66-66: Using this in a static context can be confusing.
this refers to the class.
Unsafe fix: Use the class name instead.
(lint/complexity/noThisInStatic)
⏰ Context from checks skipped due to timeout of 90000ms (9)
- GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
- GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
- GitHub Check: Code Coverage
- GitHub Check: UT Tests
- GitHub Check: test_and_publish
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Analyze (go)
🔇 Additional comments (6)
src/util/dynamicConfigParser.ts (1)
65-66: Improved code to prevent mutation of original eventThe changes correctly extract the
Configobject from the cloned event's destination rather than the original event, and then pass the cloned event to theconfigureValmethod. This ensures that all modifications happen on the cloned data, preventing unintended side effects on the original event.🧰 Tools
🪛 Biome (1.9.4)
[error] 66-66: Using this in a static context can be confusing.
this refers to the class.
Unsafe fix: Use the class name instead.(lint/complexity/noThisInStatic)
src/util/dynamicConfigParser.test.ts (5)
6-44: Well-structured test helper functionThe
createTestEventhelper function provides a clean way to generate test events with customizable configurations, traits, and message types. The default parameters make it easy to use in various test scenarios while maintaining consistent event structure.
46-124: Excellent table-driven test approachThe use of table-driven tests is a great choice for testing multiple scenarios with different inputs and expected outputs. The tests clearly validate the basic functionality of the
processmethod, ensuring it handles various configuration patterns correctly without modifying the original events.
126-150: Good test for multiple events processingThis test effectively verifies that the
processmethod correctly handles multiple events, ensuring each event is processed independently and that the original events remain unmodified.
153-193: Comprehensive testing across message typesGreat job testing across different message types ('identify', 'track', 'page'). This ensures the dynamic configuration parsing works correctly regardless of the message type.
195-284: Critical test for shared destination objectsThis test is essential as it verifies the fix for the issue described in the PR. It confirms that when multiple events share the same destination object reference, the parser returns new destination objects per event without modifying the original shared destination.
The test setup properly creates two events sharing the same destination object reference, processes them, and then verifies that:
- The result contains distinct destination objects
- The original shared destination is not modified
- Each processed event has the correct configuration values
|
Allure Test reports for this run are available at:
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #4278 +/- ##
===========================================
+ Coverage 91.21% 91.26% +0.05%
===========================================
Files 632 634 +2
Lines 33053 33243 +190
Branches 7827 7867 +40
===========================================
+ Hits 30150 30340 +190
- Misses 2658 2688 +30
+ Partials 245 215 -30 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
* chore(docs): update README on how to configure secrets in tests (#4242) * chore: remove conplexity issue and redundant comments (#4250) * chore: remove conplexity issue and redundant comments * chore: address comment * chore(deps): bump rudderlabs/build-scan-push-action from 1.5.2 to 1.5.3 (#4236) chore(deps): bump build scan push action to 1.5.3 Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(pyroscope): use forked pyroscope middleware with latest updates * chore(pyroscope): use forked pyroscope middleware with latest updates * chore(pyroscope): use rudderstack scoped pyroscope nodejs * chore(pyroscope): scope and version change * chore: run ingestion svc test after artefacts build (#4196) * chore: run ingestion svc test after artefacts build * fix: test * fix: test * fix: test * chore: test * chore: test * chore: use go version file * chore: use transformer image * chore: misc * chore: review comment * chore: misc * chore: pass secrets * chore: fix workflow * chore: add docker login * chore: pull image * chore: misc * chore: misc * chore: misc * chore: cleanup * chore: remmove env * chore: remove branch * chore: bump actions/setup-node from 4.0.4 to 4.4.0 (#4262) chore(deps): bump actions/setup-node from 4.0.4 to 4.4.0 Bumps [actions/setup-node](https://github.com/actions/setup-node) from 4.0.4 to 4.4.0. - [Release notes](https://github.com/actions/setup-node/releases) - [Commits](actions/setup-node@v4.0.4...v4.4.0) --- updated-dependencies: - dependency-name: actions/setup-node dependency-version: 4.4.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump codecov/codecov-action from 5.4.0 to 5.4.2 (#4264) Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 5.4.0 to 5.4.2. - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](codecov/codecov-action@v5.4.0...v5.4.2) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-version: 5.4.2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore: convert necessary fields to string for pinterest (#4272) * feat: onboarding new destination loops (#3976) (#4235) * feat: identify and track for loops (#3976) * feat: identify and track for loops * feat: test for mailing lists * Update src/cdk/v2/destinations/loops/procWorkflow.yaml Co-authored-by: Yashasvi Bajpai <[email protected]> * fix: added response step; updated tests * fix: better way to get email and userId * feat: some changes * feat: use type --------- Co-authored-by: Yashasvi Bajpai <[email protected]> * fix: minor issues * chore: added test * feat: identify and track for loops (#3976) * feat: identify and track for loops * feat: test for mailing lists * Update src/cdk/v2/destinations/loops/procWorkflow.yaml Co-authored-by: Yashasvi Bajpai <[email protected]> * fix: added response step; updated tests * fix: better way to get email and userId * feat: some changes * feat: use type --------- Co-authored-by: Yashasvi Bajpai <[email protected]> * fix: minor issues * chore: added test * chore: update test to new structure * chore: minor change * chore: minor change --------- Co-authored-by: Dan <[email protected]> Co-authored-by: Yashasvi Bajpai <[email protected]> * feat: onboarding snapchat v3 (#4052) * feat: snapchat v3 * chore: added mappings for v3 * chore: small fix * chore: updated files * feat: onboarding snapchat capi v3 * feat: refactoring and some changes * chore: minor changes * chore: added tests and minor refactoring * fix: minor change * chore: minor changes --------- Co-authored-by: Manish Kumar <[email protected]> Co-authored-by: Manish Kumar <[email protected]> * fix(dynamicConfigParser): fix cloning issue in getdynamicconfig method (#4278) fix(dynamic config): fix cloning issue in getdynamicconfig method Resolves INT-3571 - Fix bug where original event was being modified instead of cloned event - Add comprehensive tests to verify the fix works correctly - Implement table-driven tests for better maintainability * feat(mixpanel): add support for partial batch failure handling (#4260) * feat(mixpanel): add support for partial batch failure handling * chore: misc * fix: handler * fix: handler * fix: review comments * fix: review comments * chore: review comments * chore: review comments * chore: review comments * chore: review comments * chore: review comments * chore: remove unused code * chore: table test case * chore: table test case * fix: test * chore: improve test * chore: upgrade salesforce api version from v50.0 to v63.0 (#4116) Co-authored-by: Manish Kumar <[email protected]> Co-authored-by: Manish Kumar <[email protected]> * chore: return error when gzip compression fails (#4283) chore: return error when gzip compression fails for mp * chore: revert "chore: upgrade salesforce api version from v50.0 to v63.0" (#4285) Revert "chore: upgrade salesforce api version from v50.0 to v63.0 (#4116)" This reverts commit c600f53. * chore: improving code coverage of snapchat conversion (#4284) * chore: improving code coverage of snapchat conversion * chore: minor change * fix: timestamp duration in v2 api * chore(release): 1.98.0 --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Dilip Kola <[email protected]> Co-authored-by: Yashasvi Bajpai <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Vinay Teki <[email protected]> Co-authored-by: Mahesh Kutty <[email protected]> Co-authored-by: Manish Kumar <[email protected]> Co-authored-by: Dan <[email protected]> Co-authored-by: Aanshi Lahoti <[email protected]> Co-authored-by: Manish Kumar <[email protected]> Co-authored-by: GitHub Actions <[email protected]>



What are the changes introduced in this PR?
Write a brief explainer on your code changes.
What is the related Linear task?
Resolves INT-3571
Please explain the objectives of your changes below
Put down any required details on the broader aspect of your changes. If there are any dependent changes, mandatorily mention them here
Any changes to existing capabilities/behaviour, mention the reason & what are the changes ?
N/A
Any new dependencies introduced with this change?
N/A
Any new generic utility introduced or modified. Please explain the changes.
N/A
Any technical or performance related pointers to consider with the change?
N/A
@coderabbitai review
Developer checklist
My code follows the style guidelines of this project
No breaking changes are being introduced.
All related docs linked with the PR?
All changes manually tested?
Any documentation changes needed with this change?
Is the PR limited to 10 file changes?
Is the PR limited to one linear task?
Are relevant unit and component test-cases added in new readability format?
Reviewer checklist
Is the type of change in the PR title appropriate as per the changes?
Verified that there are no credentials or confidential data exposed with the changes.