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

fix: handle edge cases in retry queue #2074

Merged
merged 4 commits into from
Mar 3, 2025

Conversation

saikumarrs
Copy link
Member

@saikumarrs saikumarrs commented Mar 2, 2025

PR Description

I've fixed the following issues in the retry queue module:

  • When max items is 1, handle exactly 1 item. Earlier, it was accumulating all the items.
  • For cases where queue item processor errors out, retry the item before giving up on it.

Linear task (optional)

https://linear.app/rudderstack/issue/SDK-3066/event-processing-queue-issues

Cross Browser Tests

Please confirm you have tested for the following browsers:

  • Chrome
  • Firefox
  • IE11

Sanity Suite

  • All sanity suite test cases pass locally

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced error handling in the retry queue for clearer feedback on item processing.
    • Added logging and error handling capabilities to the StoreManager.
  • Bug Fixes

    • Resolved issues with item reprocessing to prevent unpredictable behavior under certain conditions.
  • Refactor

    • Improved the retry processing system with enhanced error feedback and clearer notifications to support easier troubleshooting and increased overall reliability.
    • Updated size limits for plugin configurations to accommodate larger file sizes.

@saikumarrs saikumarrs self-assigned this Mar 2, 2025
Copy link
Contributor

coderabbitai bot commented Mar 2, 2025

📝 Walkthrough

Walkthrough

This pull request updates the retry queue functionality in the analytics JS plugins. The changes include expanded constructor documentation with additional parameters, refined queue slicing logic, and a simplified requeue method signature in the RetryQueue.ts file. Error handling in the processHead method is enhanced to log detailed messages based on retry attempts, and the sorting logic is simplified. In logMessages.ts, the error message generation function now accepts an extra error message parameter to provide more descriptive outputs. Additionally, the StoreManager mock has been updated to include logging and error handling capabilities.

Changes

File(s) Summary
packages/analytics-js-plugins/src/utilities/retryQueue/RetryQueue.ts - Expanded constructor documentation with additional parameters (storeManager, storageType, logger, queueBatchItemsSizeCalculatorCb) and updated type of options
- Modified queue slicing logic to check maxItems before slicing
- Simplified requeue method signature by removing the optional error parameter
- Enhanced error handling in processHead and simplified queue sorting
packages/analytics-js-plugins/src/utilities/retryQueue/logMessages.ts - Updated RETRY_QUEUE_PROCESS_ERROR to accept an additional errMsg parameter
- Modified error string to include descriptive information along with the error message
packages/analytics-js-common/__mocks__/StoreManager.ts - Added properties logger and errorHandler to StoreManager class, initialized with defaultLogger and defaultErrorHandler respectively.
packages/analytics-js-plugins/.size-limit.mjs - Updated size limit for 'Plugins - Legacy - CDN' from '14.1 KiB' to '14.5 KiB'.
packages/analytics-js/.size-limit.mjs - Updated size limits for 'Core - Legacy - NPM (CJS)' and 'Core (Bundled) - Legacy - NPM (CJS)' from '48 KiB' to '48.2 KiB'.
packages/analytics-js-plugins/__tests__/utilities/retryQueue/RetryQueue.test.ts - Introduced new test cases and modified existing ones for RetryQueue, utilizing a new logger mock and enhancing coverage for error handling and configuration limits.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant RetryQueue
    participant Logger
    Client->>RetryQueue: Enqueue/Process queue item
    RetryQueue->>RetryQueue: Process item (processHead)
    alt Processing Successful
        RetryQueue-->>Client: Return success result
    else Error Occurs
        RetryQueue->>Logger: Log detailed error message (with retry attempt info)
        alt Max Attempts Not Reached
            RetryQueue->>RetryQueue: Requeue item for retry
        else Max Attempts Reached
            RetryQueue->>Logger: Log message indicating item drop
        end
    end
Loading

Possibly related PRs

  • fix: retry status code logic and error messages #2050: The changes in the main PR regarding error handling and retry logic in the RetryQueue class are related to the modifications in the retrieved PR that enhance the retry logic and error messaging for HTTP status codes, as both involve improving how errors are processed and reported.

Suggested reviewers

  • ChryssaAliferi
  • koladilip

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 46ae303 and 03e4dba.

📒 Files selected for processing (4)
  • packages/analytics-js-common/__mocks__/StoreManager.ts (2 hunks)
  • packages/analytics-js-plugins/.size-limit.mjs (1 hunks)
  • packages/analytics-js-plugins/__tests__/utilities/retryQueue/RetryQueue.test.ts (5 hunks)
  • packages/analytics-js/.size-limit.mjs (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
packages/analytics-js-plugins/__tests__/utilities/retryQueue/RetryQueue.test.ts (1)
Learnt from: saikumarrs
PR: rudderlabs/rudder-sdk-js#1823
File: packages/analytics-js-common/src/utilities/retryQueue/utilities.ts:0-0
Timestamp: 2024-11-12T15:14:23.319Z
Learning: The issue regarding missing test coverage for the `findOtherQueues` function in `packages/analytics-js-common/src/utilities/retryQueue/utilities.ts` is no longer applicable.
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Bundle size checks
  • GitHub Check: Security and code quality checks
  • GitHub Check: Unit Tests and Lint
🔇 Additional comments (9)
packages/analytics-js-common/__mocks__/StoreManager.ts (2)

5-6: Added logger and error handler dependencies.

The imports for defaultLogger and defaultErrorHandler have been added to enhance the error handling capabilities of the StoreManager mock.


30-31: Added logger and errorHandler properties to the StoreManager class.

These additions align with the PR objective to improve error handling in the retry queue. The properties enable proper logging and error handling during queue operations, which should help with debugging and handling edge cases.

packages/analytics-js-plugins/__tests__/utilities/retryQueue/RetryQueue.test.ts (4)

6-6: Added defaultLogger import for enhanced error testing.

This import supports the new test cases that verify error logging functionality.


37-38: Added logger parameter to RetryQueue initialization.

The test now properly initializes the RetryQueue with the logger, allowing for validation of error logging behavior in the test cases.


304-382: Comprehensive test for error handling in the retry queue.

This test case thoroughly validates the behavior when the process function throws an error, ensuring that:

  1. The queue correctly requeues items when errors occur
  2. Proper error messages are logged at each retry attempt
  3. The queue respects the maximum retry attempt limit
  4. Items are dropped after exhausting all retry attempts

The test covers the core error handling functionality mentioned in the PR objectives.


475-486: Added test for maxItems=1 edge case.

This test directly addresses one of the key objectives of the PR - handling the edge case where maxItems is set to 1. The test verifies that only the last item is kept in the queue when the limit is exceeded, ensuring proper queue behavior with this specific configuration.

packages/analytics-js-plugins/.size-limit.mjs (1)

19-19: Size limit has been increased from 14.1 KiB to 14.5 KiB

This change increases the size limit for 'Plugins - Legacy - CDN' to accommodate the code changes related to handling edge cases in the retry queue. The increase is modest (0.4 KiB) and appears necessary for the functional improvements.

Please confirm that this size limit change has been approved by the CODEOWNERS as noted in the file header comment.

packages/analytics-js/.size-limit.mjs (2)

16-16: Size limit has been increased from 48 KiB to 48.2 KiB

This change increases the size limit for 'Core - Legacy - NPM (CJS)' to accommodate the code changes related to handling edge cases in the retry queue. The increase is minimal (0.2 KiB) and appears necessary for the functional improvements.

Please confirm that this size limit change has been approved by the CODEOWNERS as noted in the file header comment.


62-62: Size limit has been increased from 48 KiB to 48.2 KiB

This change increases the size limit for 'Core (Bundled) - Legacy - NPM (CJS)' to accommodate the code changes related to handling edge cases in the retry queue. The increase is minimal (0.2 KiB) and appears necessary for the functional improvements.

Please ensure that this size limit change has been approved by the CODEOWNERS as noted in the file header comment.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

Copy link

codecov bot commented Mar 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 61.55%. Comparing base (bf72904) to head (03e4dba).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2074      +/-   ##
===========================================
+ Coverage    61.51%   61.55%   +0.03%     
===========================================
  Files          478      478              
  Lines        16437    16447      +10     
  Branches      3267     3264       -3     
===========================================
+ Hits         10112    10124      +12     
- Misses        5092     5099       +7     
+ Partials      1233     1224       -9     

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

coderabbitai[bot]
coderabbitai bot previously approved these changes Mar 2, 2025
Copy link

github-actions bot commented Mar 2, 2025

size-limit report 📦

Name Size (Base) Size (Current) Size Limit Status
Cookies Utils - Legacy - NPM (ESM) 1.54 KB 1.54 KB (0%) 2 KB
Cookies Utils - Legacy - NPM (CJS) 1.75 KB 1.75 KB (0%) 2 KB
Cookies Utils - Legacy - NPM (UMD) 1.53 KB 1.53 KB (0%) 2 KB
Cookies Utils - Modern - NPM (ESM) 1.17 KB 1.17 KB (0%) 1.5 KB
Cookies Utils - Modern - NPM (CJS) 1.4 KB 1.4 KB (0%) 1.5 KB
Cookies Utils - Modern - NPM (UMD) 1.16 KB 1.16 KB (0%) 1.5 KB
Plugins Module Federation Mapping - Legacy - CDN 332 B 332 B (0%) 512 B
Plugins Module Federation Mapping - Modern - CDN 331 B 331 B (0%) 512 B
Plugins - Legacy - CDN 14.04 KB 14.15 KB (+0.78% ▲) 14.5 KB
Plugins - Modern - CDN 5.65 KB 5.65 KB (0%) 6 KB
Common - No bundling 18.38 KB 18.38 KB (0%) 18.4 KB
Load Snippet 765 B 765 B (0%) 1 KB
Core (v1.1) - NPM (ESM) 30.13 KB 30.13 KB (0%) 32 KB
Core (v1.1) - NPM (CJS) 30.32 KB 30.32 KB (0%) 32 KB
Core (v1.1) - NPM (UMD) 30.16 KB 30.16 KB (0%) 32 KB
Core (Content Script - v1.1) - NPM (ESM) 29.6 KB 29.6 KB (0%) 30.5 KB
Core (Content Script - v1.1) - NPM (CJS) 29.85 KB 29.85 KB (0%) 30.5 KB
Core (Content Script - v1.1) - NPM (UMD) 29.71 KB 29.71 KB (0%) 30.5 KB
Core (v1.1) - Legacy - CDN 32.03 KB 32.03 KB (0%) 32.5 KB
Core (v1.1) - Modern - CDN 30.01 KB 30.01 KB (0%) 32 KB
Service Worker - Legacy - NPM (ESM) 30.32 KB 30.32 KB (0%) 31 KB
Service Worker - Legacy - NPM (CJS) 30.52 KB 30.52 KB (0%) 31 KB
Service Worker - Legacy - NPM (UMD) 30.3 KB 30.3 KB (0%) 31 KB
Service Worker - Modern - NPM (ESM) 25.51 KB 25.51 KB (0%) 26 KB
Service Worker - Modern - NPM (CJS) 25.75 KB 25.75 KB (0%) 26.5 KB
Service Worker - Modern - NPM (UMD) 25.5 KB 25.5 KB (0%) 26 KB
Core - Legacy - NPM (ESM) 47.71 KB 47.71 KB (-0.02% ▼) 48 KB
Core - Legacy - NPM (CJS) 47.92 KB 48.05 KB (+0.28% ▲) 48.2 KB
Core - Legacy - NPM (UMD) 47.73 KB 47.78 KB (+0.1% ▲) 48 KB
Core - Legacy - CDN 47.85 KB 47.96 KB (+0.24% ▲) 48 KB
Core - Modern - NPM (ESM) 26.78 KB 26.78 KB (0%) 27 KB
Core - Modern - NPM (CJS) 26.98 KB 26.98 KB (0%) 27.2 KB
Core - Modern - NPM (UMD) 26.82 KB 26.82 KB (0%) 27 KB
Core - Modern - CDN 27.02 KB 27.02 KB (0%) 27.5 KB
Core (Bundled) - Legacy - NPM (ESM) 47.71 KB 47.71 KB (-0.02% ▼) 48 KB
Core (Bundled) - Legacy - NPM (CJS) 47.94 KB 48.01 KB (+0.16% ▲) 48.2 KB
Core (Bundled) - Legacy - NPM (UMD) 47.73 KB 47.78 KB (+0.1% ▲) 48 KB
Core (Bundled) - Modern - NPM (ESM) 38.84 KB 38.95 KB (+0.29% ▲) 39 KB
Core (Bundled) - Modern - NPM (CJS) 39.11 KB 39.16 KB (+0.14% ▲) 39.2 KB
Core (Bundled) - Modern - NPM (UMD) 38.88 KB 38.94 KB (+0.16% ▲) 39 KB
Core (Content Script) - Legacy - NPM (ESM) 47.64 KB 47.71 KB (+0.15% ▲) 48 KB
Core (Content Script) - Legacy - NPM (CJS) 47.91 KB 47.95 KB (+0.07% ▲) 48 KB
Core (Content Script) - Legacy - NPM (UMD) 47.7 KB 47.71 KB (+0.02% ▲) 48 KB
Core (Content Script) - Modern - NPM (ESM) 38.79 KB 38.89 KB (+0.24% ▲) 39 KB
Core (Content Script) - Modern - NPM (CJS) 39.1 KB 39.16 KB (+0.16% ▲) 39.2 KB
Core (Content Script) - Modern - NPM (UMD) 38.8 KB 38.88 KB (+0.21% ▲) 39 KB
All Integrations - Legacy - CDN 95.08 KB 95.08 KB (0%) 95.3 KB
All Integrations - Modern - CDN 90.77 KB 90.77 KB (0%) 91 KB

@saikumarrs saikumarrs marked this pull request as ready for review March 3, 2025 03:58
@saikumarrs saikumarrs requested a review from a team as a code owner March 3, 2025 03:58
@saikumarrs saikumarrs merged commit f9263b2 into develop Mar 3, 2025
11 checks passed
@saikumarrs saikumarrs deleted the fix.retry-queue-issues-sdk-3066 branch March 3, 2025 04:52
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.

2 participants