Skip to content

refactor(iterable): update api limits and batching logic - #4232

Merged
koladilip merged 1 commit into
developfrom
fix/batching-for-iterable
Apr 4, 2025
Merged

koladilip merged 1 commit into
developfrom
fix/batching-for-iterable

Conversation

@koladilip

Copy link
Copy Markdown
Contributor

What are the changes introduced in this PR?

Update Iterable destination to use a single 4MB request size limit for both identify and track operations, and a 1,000 items per request limit for catalog operations.

  • Replace separate batch size limits with a single MAX_BODY_SIZE_IN_BYTES constant
  • Add CATALOG_MAX_ITEMS_PER_REQUEST constant for catalog operations
  • Add INITIAL_CHUNK_SIZE constant to replace hard-coded values
  • Simplify catalog batching logic only to respect item count limit
  • Add tests to verify batching behavior

What is the related Linear task?

Resolves INT-3475

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.

@koladilip
koladilip requested a review from a team as a code owner April 4, 2025 03:24
@coderabbitai

coderabbitai Bot commented Apr 4, 2025 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features
    • Enhanced event batching now dynamically groups events based on payload size for improved reliability.
  • Refactor
    • Consolidated configuration settings streamline the management of payload limits across operations.
  • Tests
    • Expanded test coverage ensures consistent event handling across varying payload scenarios.

Walkthrough

This pull request refactors configuration constants and updates event batching in the Iterable integration. The config.js file removes specific constants related to identify operations and introduces new consolidated constants for batch size limits. In the util.js file, imports are streamlined into a single configurations object, and the logic for batch processing is updated to utilize these new constants. A new function, prepareAndSplitTrackBatchesBasedOnPayloadSize, is added to manage event batching based on payload size, and the test suite is updated to validate this functionality.

Changes

File(s) Change Summary
src/v0/destinations/iterable/config.js Removed constants: IDENTIFY_MAX_BATCH_SIZE, IDENTIFY_MAX_BODY_SIZE_IN_BYTES, and TRACK_MAX_BATCH_SIZE; added consolidated constants: MAX_BODY_SIZE_IN_BYTES (4MB limit), INITIAL_CHUNK_SIZE, and CATALOG_MAX_ITEMS_PER_REQUEST.
src/v0/destinations/iterable/util.js
src/v0/destinations/iterable/util.test.js
Refactored configuration imports to use a single configurations object and updated batching functions (batchUpdateUserEvents and batchTrackEvents) to use new constants; introduced prepareAndSplitTrackBatchesBasedOnPayloadSize and updated tests accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Util
    Client->>Util: Invoke batchTrackEvents(trackEvents)
    Util->>Util: Call prepareAndSplitTrackBatchesBasedOnPayloadSize(trackEvents)
    Util-->>Util: Return split event batches
    Util->>Util: For each batch, execute processTrackBatch(batch)
    Util-->>Client: Return batched processing result
Loading

Suggestions for Improvements

  • Enhanced Edge Case Testing: Add tests covering edge conditions such as events exactly at the payload size limit or slightly exceeding it to ensure robust batch handling.
  • Backward Compatibility Verification: Confirm that integrations relying on removed constants are updated or provided with migration guidelines.
  • Documentation Update: Expand inline documentation and code comments to clarify the logic behind payload splitting and the rationale for consolidating batch limits.
  • Consistent Naming: Review the naming conventions across modules to maintain consistency, particularly in reference to batch sizes and payload limits.

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7f167e327f3e35645ef14759d8c1990ab47bc1cd and 9f458b3.

📒 Files selected for processing (3)
  • src/v0/destinations/iterable/config.js (2 hunks)
  • src/v0/destinations/iterable/util.js (8 hunks)
  • src/v0/destinations/iterable/util.test.js (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/v0/destinations/iterable/config.js
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.js`: Focus on ESLint errors (max 3) and warnings (max 5).

**/*.js: Focus on ESLint errors (max 3) and warnings (max 5).

  • src/v0/destinations/iterable/util.test.js
  • src/v0/destinations/iterable/util.js
🧬 Code Definitions (1)
src/v0/destinations/iterable/util.test.js (3)
src/v0/destinations/iterable/util.js (6)
  • require (5-5)
  • require (6-13)
  • require (16-16)
  • require (17-17)
  • chunk (523-523)
  • prepareAndSplitTrackBatchesBasedOnPayloadSize (563-596)
src/v0/destinations/iterable/config.js (1)
  • require (1-1)
src/v0/destinations/iterable/transform.js (6)
  • require (3-3)
  • require (5-19)
  • require (29-29)
  • require (30-30)
  • require (31-31)
  • require (32-32)
⏰ 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 AMD64
  • GitHub Check: Code Coverage
  • GitHub Check: ingestion-service-test
  • GitHub Check: UT Tests
  • GitHub Check: test_and_publish
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
🔇 Additional comments (15)
src/v0/destinations/iterable/util.test.js (5)

14-14: Good addition of new export function in imports.

This matches the new function prepareAndSplitTrackBatchesBasedOnPayloadSize added to the util.js file, ensuring proper test coverage for the new functionality.


18-31: Well-structured mock configuration for testing.

Good approach to mock the configuration constants with smaller values to make testing more manageable. This allows for easier validation of batching logic without requiring large payloads.


1066-1070: Good edge case handling for empty input.

The explicit handling of the empty input case ensures that the function correctly handles this edge case, which is an important test scenario for batching functions.


1072-1090: Comprehensive test verification.

The test assertions are thorough, checking multiple aspects of the response:

  1. Verifying the length of the result
  2. Confirming all expected users are present
  3. Validating metadata is preserved
  4. Ensuring non-batched requests are properly included

This provides good coverage of the batching functionality.


1117-1178: Well-structured tests for the new batching function.

The tests effectively cover the key scenarios for the new prepareAndSplitTrackBatchesBasedOnPayloadSize function:

  1. Handling payload sizes that exceed the limit (testing the batching logic)
  2. Processing payloads under the size limit (testing the single batch case)

This provides good coverage of the function's behavior under different conditions.

src/v0/destinations/iterable/util.js (10)

15-15: Improved module imports with consolidated configuration.

Consolidating configuration imports into a single object is a good practice that makes the code cleaner and more maintainable. This change simplifies how configuration values are accessed throughout the file.

Also applies to: 21-21


375-375: Updated to use consolidated size limit constant.

Good update to use the new configurations.MAX_BODY_SIZE_IN_BYTES constant, which aligns with the PR objective of implementing a unified request size limit.


474-474: Using configuration constant instead of hardcoded value.

Good replacement of hardcoded batch size with the new configurations.INITIAL_CHUNK_SIZE constant, eliminating magic numbers in the code.


484-488: Improved documentation for catalog batching.

Clear documentation update explaining the 1,000 items limit for catalog operations, which helps future developers understand the API constraints.


492-500: Simplified catalog batching implementation.

The catalog batching logic has been simplified to focus only on the item count limit, making the code more straightforward and easier to understand.

Also applies to: 518-521


545-550: Using configuration constant for catalog batch size.

Good implementation of the catalog batching using the new configurations.CATALOG_MAX_ITEMS_PER_REQUEST constant, which ensures consistency with the documented API limits.


559-596: Well-implemented new batching function.

The new prepareAndSplitTrackBatchesBasedOnPayloadSize function follows a similar pattern to the existing user batching function, providing consistent behavior and making the code more modular.

Key aspects handled well:

  1. Size tracking and batch creation when limits are reached
  2. Proper reset of variables after creating a batch
  3. Handling the final batch even if size limit isn't reached

604-628: Improved track batch processing with new batching function.

Good refactoring of the processTrackBatch function to use the new prepareAndSplitTrackBatchesBasedOnPayloadSize function. This makes the code more modular and maintainable.


639-644: Updated track events chunking logic.

Good update to use the configurations.INITIAL_CHUNK_SIZE constant and properly handle the array of responses from processTrackBatch. The comment explaining that you'll rely on size-based batching is helpful for understanding the approach.


814-814: Appropriate addition to module exports.

Good addition of the new function to the module exports, making it available for testing and other modules that might need to use it.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@codecov

codecov Bot commented Apr 4, 2025 •

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.05%. Comparing base (322ddbc) to head (9f458b3).
Report is 3 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #4232   +/-   ##
========================================
  Coverage    91.05%   91.05%           
========================================
  Files          627      627           
  Lines        33049    33068   +19     
  Branches      7818     7817    -1     
========================================
+ Hits         30092    30111   +19     
- Misses        2710     2740   +30     
+ Partials       247      217   -30     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@koladilip
koladilip force-pushed the fix/batching-for-iterable branch from 68a25b7 to 5dbc6a8 Compare April 4, 2025 03:32

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/v0/destinations/iterable/util.js (1)

1-1: Added ESLint directive.

The eslint-disable unicorn/consistent-destructuring directive may be necessary but consider using a more targeted approach to only disable the rule for specific lines or blocks if possible.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 68a25b709d429b0429d4b4fddcfdc63ebfd057ce and 5dbc6a89c6ae1afe8cced3236ce4f7adf343e0bd.

📒 Files selected for processing (3)
  • src/v0/destinations/iterable/config.js (2 hunks)
  • src/v0/destinations/iterable/util.js (8 hunks)
  • src/v0/destinations/iterable/util.test.js (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.js`: Focus on ESLint errors (max 3) and warnings (max 5).

**/*.js: Focus on ESLint errors (max 3) and warnings (max 5).

  • src/v0/destinations/iterable/util.test.js
  • src/v0/destinations/iterable/config.js
  • src/v0/destinations/iterable/util.js
🧬 Code Definitions (2)
src/v0/destinations/iterable/util.test.js (3)
src/v0/destinations/iterable/util.js (6)
  • require (5-5)
  • require (6-13)
  • require (16-16)
  • require (17-17)
  • chunk (523-523)
  • prepareAndSplitTrackBatchesBasedOnPayloadSize (563-596)
src/v0/destinations/iterable/config.js (1)
  • require (1-1)
src/v0/destinations/iterable/transform.js (6)
  • require (3-3)
  • require (5-19)
  • require (29-29)
  • require (30-30)
  • require (31-31)
  • require (32-32)
src/v0/destinations/iterable/util.js (3)
src/v0/destinations/iterable/util.test.js (2)
  • require (1-16)
  • require (34-34)
src/v0/destinations/iterable/config.js (2)
  • require (1-1)
  • constructEndpoint (74-77)
src/v0/destinations/iterable/transform.js (6)
  • require (3-3)
  • require (5-19)
  • require (29-29)
  • require (30-30)
  • require (31-31)
  • require (32-32)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Code Coverage
  • 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: test_and_publish
  • GitHub Check: ingestion-service-test
  • GitHub Check: UT Tests
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
🔇 Additional comments (22)
src/v0/destinations/iterable/util.test.js (6)

14-14: Import added for new track batch function.

The import statement has been updated to include the new prepareAndSplitTrackBatchesBasedOnPayloadSize function, which is a key part of the refactored batching logic.


17-31: Good configuration mocking approach.

Nice implementation of the config module mock with smaller values for testing purposes. This makes it easier to test the batching logic without creating large payloads and follows best practices for unit testing by isolating the test from the actual configuration values.


33-34: Clean import of the mocked config.

Good practice to import the mocked module explicitly to ensure the tests are using the modified configuration values.


36-37: Clear comment about lodash mocking.

Good clarification that lodash doesn't need to be mocked for this test suite.


1066-1091: Improved test case for update user batches.

The test has been enhanced to handle empty input cases and verify the presence of expected properties across all batches. This increases test robustness and ensures the batching function behaves correctly under various conditions.


1117-1178: Well-structured tests for the new track batching function.

The new test cases thoroughly verify the behavior of prepareAndSplitTrackBatchesBasedOnPayloadSize under different scenarios:

  1. When payload size exceeds the limit, ensuring multiple batches are created
  2. When payload size is under the limit, ensuring a single batch is created

This follows good testing practices by covering both edge cases and normal operation.

src/v0/destinations/iterable/config.js (3)

81-82: Clear documentation for the API limit.

Good documentation comment explaining that Iterable has a unified 4MB request size limit for all operations. This helps future developers understand the rationale behind the constant.


84-86: Improved constant organization.

Good refactoring of the batch size limits into clearly named constants that reflect their purpose:

  • INITIAL_CHUNK_SIZE for the initial batching of all operations
  • CATALOG_MAX_ITEMS_PER_REQUEST for the catalog operation limit

This makes the code more maintainable and self-documenting.


110-112: Updated module exports.

The module exports have been updated to include the new constants. This ensures they are accessible to other modules that need to reference them.

src/v0/destinations/iterable/util.js (13)

14-15: Simplified configuration import.

Good refactoring to import all configuration from a single object, making the code cleaner and more maintainable.


21-21: Destructured configuration imports.

Clean destructuring of the configuration imports to access the specific components needed.


375-375: Updated size limit check.

The function now references the unified MAX_BODY_SIZE_IN_BYTES constant from the configurations object, aligning with the PR's goal of consolidating batch size limits.


474-474: Updated initial chunk size.

The function now uses the new INITIAL_CHUNK_SIZE constant instead of a hard-coded value, improving maintainability.


484-489: Improved documentation for catalog operations.

Clear comments explaining the Iterable API's limit of 1,000 items per request for catalog operations. This helps future developers understand the constraints.


492-500: Refactored catalog batch processing.

The catalog batch processing has been simplified to focus on the item count limit, making the code more maintainable. The new approach properly maps catalog items to their respective catalog IDs.


518-521: Improved JSON structure for catalog operations.

The JSON structure now clearly separates documents and the replaceUploadedFieldsOnly flag, which improves readability and aligns with the Iterable API requirements.


523-527: Better variable extraction.

The function now cleanly extracts destination, message, and endpoint information for the API call.


539-550: Updated documentation and chunking for catalog events.

The function now clearly explains that catalog events are chunked based on the Iterable API's limit of 1,000 items per request. The code uses the new CATALOG_MAX_ITEMS_PER_REQUEST constant for clarity.


558-596: Well-implemented track batching function.

The new prepareAndSplitTrackBatchesBasedOnPayloadSize function is a good addition that follows the same pattern as the user update batching function. It correctly:

  1. Tracks cumulative payload size
  2. Creates new batches when size exceeds the limit
  3. Handles the final batch correctly

This promotes code reuse and consistency in the batching logic.


604-628: Refactored track batch processing.

The processTrackBatch function has been refactored to use the new batching function, making the code more modular and easier to maintain. The changes correctly handle the array of batch responses.


638-644: Updated track events batching.

The function now uses the new INITIAL_CHUNK_SIZE constant and correctly handles the array of batch responses from processTrackBatch.


814-814: Export of new track batching function.

The new prepareAndSplitTrackBatchesBasedOnPayloadSize function is properly exported for use in other modules and tests.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@koladilip
koladilip force-pushed the fix/batching-for-iterable branch from 5dbc6a8 to 7f167e3 Compare April 4, 2025 05:04
@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

Update Iterable destination to use a single 4MB request size
limit for both identify and track operations, and a 1,000
items per request limit for catalog operations.

- Replace separate batch size limits with a single
  MAX_BODY_SIZE_IN_BYTES constant
- Add CATALOG_MAX_ITEMS_PER_REQUEST constant for catalog operations
- Add INITIAL_CHUNK_SIZE constant to replace hard-coded values
- Simplify catalog batching logic to only respect item count limit
- Add tests to verify batching behavior
@koladilip
koladilip force-pushed the fix/batching-for-iterable branch from 7f167e3 to 9f458b3 Compare April 4, 2025 06:02
@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@sonarqubecloud

sonarqubecloud Bot commented Apr 4, 2025

Copy link
Copy Markdown

@koladilip
koladilip merged commit bc70358 into develop Apr 4, 2025
@koladilip
koladilip deleted the fix/batching-for-iterable branch April 4, 2025 06:13
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.

6 participants