Skip to content

make flush processor per pod #196

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 1 commit into from
Jun 6, 2025
Merged

make flush processor per pod #196

merged 1 commit into from
Jun 6, 2025

Conversation

dudizimber
Copy link
Collaborator

@dudizimber dudizimber commented Jun 6, 2025

fix #172

Summary by CodeRabbit

  • New Features
    • Improved error handling and user feedback when setting the organization context during instance creation and deletion in the authentication proxy.
  • Refactor
    • Updated data handling to support multiple pod IDs instead of a single pod ID in RDB import processes.
  • Tests
    • Adjusted test cases to accommodate the new array-based pod ID structure.

Copy link

coderabbitai bot commented Jun 6, 2025

Walkthrough

The changes update the RDB import flush instance workflow to support multiple pod IDs instead of a single pod ID. This involves schema adjustments, code modifications to iterate over arrays of pod IDs, and updates to related tests and job data structures. Additional error handling is introduced in frontend handlers for organization context setting.

Changes

Files/Paths Change Summary
backend/libs/schemas/src/services/db-importer-worker/v1/processors/rdb-import.ts Changed schema property from podId: string to podIds: string[].
backend/services/db-importer-worker/src/processors/RdbImportFlushInstanceProcessor.ts Modified to iterate over podIds array and call flushInstance for each. Removed isCluster.
backend/services/db-importer-worker/src/repositories/k8s/K8sRepository.ts Removed isCluster parameter and related logic from flushInstance method.
backend/services/db-importer-worker/src/tests/import-rdb-cluster.spec.ts
backend/services/db-importer-worker/src/tests/import-rdb-replication.spec.ts
backend/services/db-importer-worker/src/tests/import-rdb-standalone.spec.ts
Updated test job node payloads from single podId to array podIds.
backend/services/db-importer/src/repositories/tasksQueue/TaskQueueBullMQRepository.ts Updated job node creation to use podIds array instead of single podId.
frontend/apps/auth-proxy/lib/handlers/instanceCreated.ts
frontend/apps/auth-proxy/lib/handlers/instanceDeleted.ts
Added try-catch for userSetUsingOrg, logging, and error response on failure.

Sequence Diagram(s)

sequenceDiagram
    participant JobProcessor as RdbImportFlushInstanceProcessor
    participant K8sRepo as K8sRepository

    JobProcessor->>JobProcessor: Receive job with podIds[]
    loop For each podId in podIds
        JobProcessor->>K8sRepo: flushInstance(cloudProvider, clusterId, region, instanceId, podId, ...)
        K8sRepo-->>JobProcessor: (Result)
    end
Loading
sequenceDiagram
    participant Handler as instanceCreated/instanceDeleted Handler
    participant Client as client
    Handler->>Client: userSetUsingOrg(orgId)
    alt Success
        Handler->>Handler: Log success, continue
    else Failure
        Handler->>Handler: Log error, send HTTP 500 response
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Support importing RDB files into standalone, sentinel, and cluster deployments; enable option to wipe DB before import (#172)
Implement error handling and reliability for import/export operations (#172)
Deliver comprehensive testing for import workflows (#172)

Suggested reviewers

  • AviAvni

Poem

In the warren where code flows free,
We hop from one pod to a pod ID tree.
Arrays replace singles, more robust than before,
With error checks guarding each frontend door.
Tests leap in chorus, all passing with glee—
Another day’s hop for FalkorDB!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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

github-actions bot commented Jun 6, 2025

Tofu Plan Output - observability_stack_ctrl_plane_k8s


OpenTofu used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  �[33m~�[0m update in-place�[0m

OpenTofu will perform the following actions:

�[1m  # kubernetes_namespace.api�[0m will be updated in-place
�[0m  �[33m~�[0m�[0m resource "kubernetes_namespace" "api" {
        id                               = "api"
        �[90m# (1 unchanged attribute hidden)�[0m�[0m

      �[33m~�[0m�[0m metadata {
          �[33m~�[0m�[0m labels           = {
              �[31m-�[0m�[0m "argocd.argoproj.io/instance" = "observability-stack" �[90m-> null�[0m�[0m
            }
            name             = "api"
            �[90m# (4 unchanged attributes hidden)�[0m�[0m
        }
    }

�[1mPlan:�[0m 0 to add, 1 to change, 0 to destroy.
�[0m

Copy link

github-actions bot commented Jun 6, 2025

Tofu Plan Output - observability_stack_ctrl_plane_infra


�[0m�[1m�[32mNo changes.�[0m�[1m Your infrastructure matches the configuration.�[0m

�[0mOpenTofu has compared your real infrastructure against your configuration and
found no differences, so no changes are needed.

Copy link

@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: 0

🧹 Nitpick comments (1)
backend/services/db-importer-worker/src/processors/RdbImportFlushInstanceProcessor.ts (1)

22-32: Sequential pod processing implemented correctly, but consider error handling implications.

The implementation correctly iterates over multiple pods and processes each individually. However, the current approach has some considerations:

  1. Fail-fast behavior: If one pod fails, subsequent pods won't be processed
  2. No partial success tracking: The job will fail entirely even if some pods were successfully flushed

Consider whether partial success should be tracked or if parallel processing might be more efficient for large pod arrays.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4445464 and 88885fa.

📒 Files selected for processing (9)
  • backend/libs/schemas/src/services/db-importer-worker/v1/processors/rdb-import.ts (1 hunks)
  • backend/services/db-importer-worker/src/processors/RdbImportFlushInstanceProcessor.ts (1 hunks)
  • backend/services/db-importer-worker/src/repositories/k8s/K8sRepository.ts (1 hunks)
  • backend/services/db-importer-worker/src/tests/import-rdb-cluster.spec.ts (1 hunks)
  • backend/services/db-importer-worker/src/tests/import-rdb-replication.spec.ts (1 hunks)
  • backend/services/db-importer-worker/src/tests/import-rdb-standalone.spec.ts (1 hunks)
  • backend/services/db-importer/src/repositories/tasksQueue/TaskQueueBullMQRepository.ts (1 hunks)
  • frontend/apps/auth-proxy/lib/handlers/instanceCreated.ts (1 hunks)
  • frontend/apps/auth-proxy/lib/handlers/instanceDeleted.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Plan stack observability_stack_ctrl_plane_infra
  • GitHub Check: build-and-push-docker (db-importer)
  • GitHub Check: build-and-push-docker (db-importer-worker)
  • GitHub Check: build
  • GitHub Check: build
  • GitHub Check: build-and-push-docker (db-importer-worker)
  • GitHub Check: build-and-push-docker (db-importer)
🔇 Additional comments (8)
frontend/apps/auth-proxy/lib/handlers/instanceCreated.ts (1)

61-72: Code changes look good, but they don't match the PR description.

The implementation correctly adds organization context setting with proper error handling. However, these changes are about Grafana user organization context, not "flush processor per pod" as mentioned in the PR title and objectives.

Likely an incorrect or invalid review comment.

frontend/apps/auth-proxy/lib/handlers/instanceDeleted.ts (1)

56-67: Consistent implementation with proper error handling.

The organization context setting follows the same pattern as instanceCreated.ts, which maintains consistency across both handlers. The error handling and logging are appropriate.

backend/services/db-importer-worker/src/tests/import-rdb-replication.spec.ts (1)

129-129: LGTM: Test updated correctly for multi-pod flush processor.

The change from passing a single podId to the entire podIds array aligns perfectly with the schema update for RdbImportFlushInstanceProcessor.

backend/libs/schemas/src/services/db-importer-worker/v1/processors/rdb-import.ts (1)

98-98:

✅ Verification successful

Breaking schema change requires verification of all consumers.

The change from podId: Type.String() to podIds: Type.Array(Type.String()) is a breaking change in the data contract. Ensure that all consumers of RdbImportFlushInstanceProcessorDataSchema have been updated accordingly.


🏁 Script executed:

#!/bin/bash
# Description: Verify that RdbImportFlushInstanceProcessor has been updated to handle podIds array
# Expected: The processor should iterate over podIds array instead of handling a single podId

# Search for the processor implementation
ast-grep --pattern 'class RdbImportFlushInstanceProcessor {
  $$$
}'

# Search for any remaining usage of single podId in flush processor
rg -A 10 -B 5 "RdbImportFlushInstanceProcessor" --type ts

Length of output: 26581


Verified: RdbImportFlushInstanceProcessor now correctly handles podIds array

  • Schema (RdbImportFlushInstanceProcessorDataSchema) updated to podIds: Type.Array(Type.String()).
  • Processor (backend/services/db-importer-worker/src/processors/RdbImportFlushInstanceProcessor.ts) iterates over job.data.podIds.
  • All related tests (import-rdb-replication.spec.ts, import-rdb-standalone.spec.ts, import-rdb-cluster.spec.ts) have been updated to pass podIds.
  • Other processors/schemas remain unchanged (still use podId) as intended.

No further code changes are required here. Ensure any downstream consumers are aware of this breaking change and bump package version accordingly.

backend/services/db-importer-worker/src/tests/import-rdb-cluster.spec.ts (1)

129-129: LGTM: Consistent update for cluster test scenario.

The change correctly updates the test to pass the entire podIds array, which is particularly relevant for cluster scenarios with multiple pods (6 pods in this test case).

backend/services/db-importer/src/repositories/tasksQueue/TaskQueueBullMQRepository.ts (1)

329-329: LGTM: Job data correctly updated for multi-pod flush processor.

The change from podId: task.payload.podIds[0] to podIds: task.payload.podIds correctly implements the new data structure for the flush instance processor while maintaining single pod handling for other processors in the flow.

backend/services/db-importer-worker/src/tests/import-rdb-standalone.spec.ts (1)

129-129: LGTM: Test data correctly updated for multi-pod support.

The change from passing a single podId to the entire podIds array aligns with the updated processor schema and logic.

backend/services/db-importer-worker/src/repositories/k8s/K8sRepository.ts (1)

867-899:

❓ Verification inconclusive

Verify cluster functionality after removing isCluster parameter.

The removal of the isCluster parameter and the associated --cluster call localhost:6379 argument from the redis-cli command represents a significant change that could impact cluster deployments.

Please ensure this change doesn't break existing cluster functionality and that all callers have been updated accordingly.


🏁 Script executed:

#!/bin/bash
# Description: Verify all calls to flushInstance method have been updated to match new signature

# Search for flushInstance method calls to ensure they don't pass isCluster parameter
rg -A 10 "flushInstance\(" --type ts

Length of output: 2351


🏁 Script executed:

#!/bin/bash
# Description: Check if there are any references to cluster-specific flush logic that might be affected

# Search for cluster-related flush operations
rg -B 5 -A 5 "cluster.*flush|flush.*cluster" --type ts

Length of output: 56


Verify cluster functionality after flushInstance signature change

  • Confirmed all calls to flushInstance have been updated to the new signature (no isCluster parameter).
  • No references to cluster-specific flush flags (e.g., --cluster call) were found in the repository.

Please validate in a staging or QA environment that flush, AOF rewrite, and save operations still behave correctly on Redis cluster deployments.

@dudizimber dudizimber merged commit a33072d into main Jun 6, 2025
22 checks passed
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.

Create RDB import service
2 participants