Skip to content

Support for logically separated redis instances #1647

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

Merged
merged 2 commits into from
Jan 29, 2025
Merged

Support for logically separated redis instances #1647

merged 2 commits into from
Jan 29, 2025

Conversation

ericallam
Copy link
Member

@ericallam ericallam commented Jan 29, 2025

Summary by CodeRabbit

  • Configuration

    • Added multiple Redis-related configuration options for rate limiting, caching, and pub/sub functionalities
    • Updated environment variable names for Redis connections across multiple services
  • Pub/Sub and Event Handling

    • Simplified Redis channel subscription mechanism in event repository
    • Modified event publishing logic to use more consolidated channel approach
  • Queueing Strategy

    • Removed organization disabled status checks from fair dequeuing strategy
    • Updated queue priority strategy configuration
  • New Features

    • Added a new task inspectApiTraffic for retrieving API traffic information

…qs, and the pub/sub stuff (they all default to the previously used env vars for redis)
Copy link

changeset-bot bot commented Jan 29, 2025

⚠️ No Changeset found

Latest commit: c2e9832

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Jan 29, 2025

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

apps/webapp/app/env.server.ts

Oops! Something went wrong! :(

ESLint: 8.45.0

ESLint couldn't find the config "custom" to extend from. Please check that the name of the config is correct.

The config "custom" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

apps/webapp/app/services/authorizationRateLimitMiddleware.server.ts

Oops! Something went wrong! :(

ESLint: 8.45.0

ESLint couldn't find the config "custom" to extend from. Please check that the name of the config is correct.

The config "custom" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

apps/webapp/app/services/apiRateLimit.server.ts

Oops! Something went wrong! :(

ESLint: 8.45.0

ESLint couldn't find the config "custom" to extend from. Please check that the name of the config is correct.

The config "custom" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

  • 7 others

Walkthrough

This pull request introduces comprehensive changes to the application's Redis configuration management. The modifications involve adding new environment variables in the EnvironmentSchema to support separate Redis configurations for rate limiting, caching, and pub/sub functionalities. Multiple files across the application have been updated to use these new environment variables, replacing the generic Redis configuration with more specialized, context-specific settings. The changes aim to provide more granular control over Redis connections while maintaining the existing application logic.

Changes

File Change Summary
apps/webapp/app/env.server.ts Added 21 new Redis-related configuration properties for rate limiting, caching, and pub/sub with optional transformations
apps/webapp/app/services/* Updated Redis configuration to use new environment variables with RATE_LIMIT_REDIS_*, CACHE_REDIS_*, and PUBSUB_REDIS_* prefixes
apps/webapp/app/v3/marqs/fairDequeuingStrategy.server.ts Removed checkForDisabledOrgs option and related disabled organization checking logic
apps/webapp/test/fairDequeuingStrategy.test.ts Removed checkForDisabledOrgs parameter from test cases and deleted "disabled orgs" test
references/v3-catalog/src/trigger/queues.ts Added new inspectApiTraffic task for retrieving API traffic information

Possibly related PRs

Suggested reviewers

  • matt-aitken

Poem

🐰 Redis configs dance and sway,
Separate paths for each relay,
Rate limits, cache, and pub/sub too,
A rabbit's config magic brew! 🔧✨

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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. (Beta)
  • @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
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (5)
apps/webapp/app/services/realtimeClientGlobal.server.ts (1)

11-16: Consider using dedicated Redis instance for realtime functionality

The realtime client is using the rate limiting Redis instance (RATE_LIMIT_REDIS_*), which seems architecturally incorrect. Realtime functionality and rate limiting serve different purposes and may have different scaling requirements. Consider:

  1. Using a dedicated REALTIME_REDIS_* configuration
  2. Or using the existing pub/sub Redis instance since realtime features often rely on pub/sub mechanisms

This separation would:

  • Prevent potential performance impacts between rate limiting and realtime features
  • Allow independent scaling of Redis instances based on their specific usage patterns
  • Maintain clearer architectural boundaries
references/v3-catalog/src/trigger/queues.ts (1)

44-59: Document the purpose of API traffic inspection

The task's purpose and testing methodology should be documented. Consider:

  1. Adding JSDoc comments explaining the task's purpose
  2. Documenting expected outcomes
  3. Adding parameters to configure the number of calls and timing
+/**
+ * Task to inspect API traffic patterns and response headers.
+ * @param {Object} options
+ * @param {number} [options.numberOfCalls=100] - Number of API calls to make
+ * @param {number} [options.delayBetweenCalls=0] - Delay in seconds between calls
+ */
 export const inspectApiTraffic = task({
   id: "queues/inspect-api-traffic",
-  run: async (payload: unknown, { ctx }) => {
+  run: async (payload: { numberOfCalls?: number; delayBetweenCalls?: number } = {}, { ctx }) => {
+    const { numberOfCalls = 100, delayBetweenCalls = 0 } = payload;
apps/webapp/app/env.server.ts (1)

94-179: LGTM! Well-structured Redis configuration with proper fallbacks.

The changes introduce three logically separated Redis configurations (rate limiting, caching, pub/sub) while maintaining backward compatibility through fallbacks to generic Redis configuration.

Consider adding JSDoc comments to document:

  • The purpose of each Redis configuration set
  • The fallback behavior to generic Redis configuration
  • Example configuration values
apps/webapp/app/v3/eventRepository.server.ts (2)

1102-1108: LGTM! Efficient handling of multiple publish operations.

The code efficiently handles multiple events by deduplicating trace IDs and using Promise.allSettled for resilient publishing.

Consider caching the timestamp to avoid multiple Date object creations:

+    const timestamp = new Date().toISOString();
     await Promise.allSettled(
       Array.from(uniqueTraces).map((traceId) =>
-        this._redisPublishClient.publish(traceId, new Date().toISOString())
+        this._redisPublishClient.publish(traceId, timestamp)
       )
     );

1146-1151: LGTM! Good separation of Redis configurations.

The use of PUBSUB-specific Redis configuration with secure defaults (TLS enabled by default) and performance optimization (auto-pipelining) is well implemented.

Consider adding connection timeout options to prevent hanging connections:

     {
       port: env.PUBSUB_REDIS_PORT,
       host: env.PUBSUB_REDIS_HOST,
       username: env.PUBSUB_REDIS_USERNAME,
       password: env.PUBSUB_REDIS_PASSWORD,
       enableAutoPipelining: true,
+      connectTimeout: 5000,
+      maxRetriesPerRequest: 3,
       ...(env.PUBSUB_REDIS_TLS_DISABLED === "true" ? {} : { tls: {} }),
     }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a24b2a7 and c2e9832.

📒 Files selected for processing (14)
  • apps/webapp/app/env.server.ts (1 hunks)
  • apps/webapp/app/services/apiRateLimit.server.ts (1 hunks)
  • apps/webapp/app/services/authorizationRateLimitMiddleware.server.ts (1 hunks)
  • apps/webapp/app/services/platform.v3.server.ts (1 hunks)
  • apps/webapp/app/services/rateLimiter.server.ts (1 hunks)
  • apps/webapp/app/services/realtimeClientGlobal.server.ts (1 hunks)
  • apps/webapp/app/v3/eventRepository.server.ts (3 hunks)
  • apps/webapp/app/v3/marqs/devPubSub.server.ts (1 hunks)
  • apps/webapp/app/v3/marqs/fairDequeuingStrategy.server.ts (0 hunks)
  • apps/webapp/app/v3/marqs/index.server.ts (0 hunks)
  • apps/webapp/app/v3/marqs/v2.server.ts (0 hunks)
  • apps/webapp/app/v3/services/projectPubSub.server.ts (1 hunks)
  • apps/webapp/test/fairDequeuingStrategy.test.ts (0 hunks)
  • references/v3-catalog/src/trigger/queues.ts (2 hunks)
💤 Files with no reviewable changes (4)
  • apps/webapp/app/v3/marqs/v2.server.ts
  • apps/webapp/test/fairDequeuingStrategy.test.ts
  • apps/webapp/app/v3/marqs/fairDequeuingStrategy.server.ts
  • apps/webapp/app/v3/marqs/index.server.ts
✅ Files skipped from review due to trivial changes (1)
  • apps/webapp/app/services/platform.v3.server.ts
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: typecheck / typecheck
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - pnpm)
  • GitHub Check: units / 🧪 Unit Tests
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (7)
apps/webapp/app/v3/marqs/devPubSub.server.ts (1)

24-30: LGTM! Proper use of dedicated pub/sub Redis instance

The changes correctly utilize the dedicated pub/sub Redis instance for development pub/sub functionality. This aligns well with the architectural goal of logically separating Redis instances by their purpose.

apps/webapp/app/v3/services/projectPubSub.server.ts (1)

25-30: LGTM! Consistent use of pub/sub Redis configuration

The changes maintain consistency with other pub/sub related modifications by properly utilizing the dedicated pub/sub Redis instance.

apps/webapp/app/services/apiRateLimit.server.ts (1)

8-13: LGTM! Redis configuration updated for rate limiting.

The changes correctly update the Redis configuration to use rate limit specific environment variables, providing better isolation for rate limiting functionality.

apps/webapp/app/services/rateLimiter.server.ts (1)

31-36: LGTM! Redis configuration updated consistently.

The changes correctly update the Redis configuration in the RateLimiter class to use rate limit specific environment variables, maintaining consistency with other rate limiting components.

apps/webapp/app/services/authorizationRateLimitMiddleware.server.ts (1)

166-171: LGTM! Redis configuration updated consistently.

The changes correctly update the Redis configuration in the authorization rate limit middleware to use rate limit specific environment variables, maintaining consistency with other rate limiting components.

apps/webapp/app/v3/eventRepository.server.ts (2)

994-1006: LGTM! Performance improvement in Redis subscription mechanism.

The change from pattern-based subscription (psubscribe) to direct channel subscription (subscribe) reduces the overhead of pattern matching and simplifies the event handling logic.


1011-1013: LGTM! Proper cleanup in unsubscribe logic.

The unsubscription logic correctly handles channel unsubscription, connection cleanup, and subscriber count management.

Comment on lines +47 to +50
// Retrieve the run 100 times
for (let i = 0; i < 100; i++) {
await runs.retrieve(ctx.run.id);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider optimizing the API traffic inspection approach

Making 100 identical API calls to retrieve the same run is inefficient and could:

  • Unnecessarily consume API rate limits
  • Impact system performance
  • Create unnecessary load on the server

Consider:

  1. Reducing the number of calls or making them configurable
  2. Adding delays between calls using wait.for()
  3. Using a more efficient sampling approach

Copy link

pkg-pr-new bot commented Jan 29, 2025

@trigger.dev/build

npm i https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/build@1647

@trigger.dev/react-hooks

npm i https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/react-hooks@1647

trigger.dev

npm i https://pkg.pr.new/triggerdotdev/trigger.dev@1647

@trigger.dev/rsc

npm i https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/rsc@1647

@trigger.dev/sdk

npm i https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/sdk@1647

@trigger.dev/core

npm i https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/core@1647

commit: c2e9832

@ericallam ericallam merged commit ef0fc6b into main Jan 29, 2025
13 checks passed
@ericallam ericallam deleted the ea-branch-9 branch January 29, 2025 13:54
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.

1 participant