Skip to content

use default logger #192

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
Jun 4, 2025
Merged

use default logger #192

merged 2 commits into from
Jun 4, 2025

Conversation

dudizimber
Copy link
Collaborator

@dudizimber dudizimber commented Jun 4, 2025

cast instead of validate
fix #172

Summary by CodeRabbit

  • Refactor
    • Updated logging throughout job processing to use a centralized debug-level logger for improved consistency.
    • Adjusted task validation approach for database tasks, enhancing how task objects are processed after retrieval.
  • Chores
    • Removed redundant logging of successful database connections.

cast instead of validate
Copy link

coderabbitai bot commented Jun 4, 2025

Walkthrough

This change replaces job-specific logging (job.log) with a centralized debug logger (logger.debug) across all RDB import and export worker processors. Additionally, the TasksDBMongoRepository adjusts task validation by switching from validateSync to cast and removes a MongoDB connection log. No control flow or business logic is altered.

Changes

Files (grouped) Change Summary
backend/services/db-importer-worker/src/processors/RdbExportCopyRDBToBucketProcessor.ts
backend/services/db-importer-worker/src/processors/RdbExportMonitorRDBMergeProcessor.ts
backend/services/db-importer-worker/src/processors/RdbExportMonitorSaveProgressProcessor.ts
backend/services/db-importer-worker/src/processors/RdbExportRequestRDBMergeProcessor.ts
backend/services/db-importer-worker/src/processors/RdbExportRequestReadSignedURL.ts
backend/services/db-importer-worker/src/processors/RdbExportSendSaveCommandProcessor.ts
backend/services/db-importer-worker/src/processors/RdbImportDeleteLocalBackupProcessor.ts
backend/services/db-importer-worker/src/processors/RdbImportFlushInstanceProcessor.ts
backend/services/db-importer-worker/src/processors/RdbImportMakeLocalBackupProcessor.ts
backend/services/db-importer-worker/src/processors/RdbImportMonitorFormatValidationProcessor.ts
backend/services/db-importer-worker/src/processors/RdbImportMonitorImportRDBProcessor.ts
backend/services/db-importer-worker/src/processors/RdbImportMonitorSaveProgressProcessor.ts
backend/services/db-importer-worker/src/processors/RdbImportMonitorSizeValidationProcessor.ts
backend/services/db-importer-worker/src/processors/RdbImportRdbFormatValidationProcessor.ts
backend/services/db-importer-worker/src/processors/RdbImportRdbSizeValidationProcessor.ts
backend/services/db-importer-worker/src/processors/RdbImportRecoverFailedImportProcessor.ts
backend/services/db-importer-worker/src/processors/RdbImportRequestRdbImportProcessor.ts
backend/services/db-importer-worker/src/processors/RdbImportSendSaveCommandProcessor.ts
backend/services/db-importer-worker/src/processors/RdbImportValidateImportKeyNumberProcessor.ts
Replaces job.log calls with logger.debug for job processing messages. No other logic changed.
backend/services/db-importer-worker/src/repositories/tasks/TasksDBMongoRepository.ts Removes MongoDB connection log; changes task validation from validateSync to cast with options.

Sequence Diagram(s)

Not included as the changes are limited to logging and validation method swaps, with no control flow or feature modifications.

Assessment against linked issues

Objective Addressed Explanation
Provide monitoring and logging capabilities for import/export tasks (#172)
Design backend for scalability, concurrency, and reliability, including task creation, worker execution, status updates, and logging (#172)

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Switch from validateSync to cast for task validation (backend/services/db-importer-worker/src/repositories/tasks/TasksDBMongoRepository.ts) This alters validation logic, which is not directly related to logging improvements or objectives specified.

Possibly related PRs

  • add import rdb service #189: Introduces new import RDB service functionality, including processors and task flows, which are directly affected by the logging and task handling refactor in this PR.

Poem

In the land of logs, a bunny hops,
Swapping job logs for debug stops.
Centralized logging, neat and clear,
Every import task, we now hear.
With validation tweaked and code refined,
The warren’s workers are well-aligned!
🐇✨

✨ 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 4, 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 4, 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: 1

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

14-14: Prefer structured logging to avoid unnecessary JSON serialization.
Rather than interpolating a string with JSON.stringify, leverage Pino’s structured logging so the payload is only serialized when the level is enabled:

logger.debug(
  { jobId: job.id, data: job.data },
  "Processing 'rdb-export-monitor-save-progress' job"
);
backend/services/db-importer-worker/src/processors/RdbImportMonitorSizeValidationProcessor.ts (1)

16-16: Use structured log parameters instead of JSON.stringify.
Passing the data object directly avoids always serializing, improving performance when debug is off:

logger.debug(
  { jobId: job.id, data: job.data },
  "Processing 'rdb-import-monitor-size-validation-progress' job"
);
backend/services/db-importer-worker/src/processors/RdbImportSendSaveCommandProcessor.ts (1)

14-14: Switch to structured logging for clarity and efficiency.
Supply the job context as an object so Pino controls serialization:

logger.debug(
  { jobId: job.id, data: job.data },
  "Processing 'rdb-import-send-save-command' job"
);
backend/services/db-importer-worker/src/processors/RdbExportRequestReadSignedURL.ts (1)

14-14: Adopt structured logging to eliminate redundant JSON.stringify calls.
Pino can log the payload directly and defer serialization:

logger.debug(
  { jobId: job.id, data: job.data },
  "Processing 'rdb-export-request-read-signed-url' job"
);
backend/services/db-importer-worker/src/processors/RdbImportMonitorFormatValidationProcessor.ts (1)

15-15: Leverage Pino’s structured logging API.
Avoid manual JSON serialization by passing the context object to the logger:

logger.debug(
  { jobId: job.id, data: job.data },
  "Processing 'rdb-import-monitor-format-validation-progress' job"
);
backend/services/db-importer-worker/src/processors/RdbExportCopyRDBToBucketProcessor.ts (1)

15-15: Use structured logging instead of JSON.stringify
Pino supports passing objects directly to its log methods, which avoids costly stringification at disabled log levels and yields richer structured logs. For example:

logger.debug(
  { jobId: job.id, data: job.data },
  "Processing 'rdb-export-copy-rdb-to-bucket' job"
);
backend/services/db-importer-worker/src/processors/RdbImportMonitorImportRDBProcessor.ts (1)

16-16: Use structured logging instead of JSON.stringify
Pino supports passing objects directly to its log methods, which avoids costly stringification at disabled log levels and yields richer structured logs. For example:

logger.debug(
  { jobId: job.id, data: job.data },
  "Processing 'rdb-import-monitor-import-rdb' job"
);
backend/services/db-importer-worker/src/processors/RdbImportRecoverFailedImportProcessor.ts (1)

14-14: Use structured logging instead of JSON.stringify
Pino supports passing objects directly to its log methods, which avoids costly stringification at disabled log levels and yields richer structured logs. For example:

logger.debug(
  { jobId: job.id, data: job.data },
  "Processing 'rdb-import-recover-failed-import' job"
);
backend/services/db-importer-worker/src/processors/RdbImportMakeLocalBackupProcessor.ts (1)

14-14: Use structured logging instead of JSON.stringify
Pino supports passing objects directly to its log methods, which avoids costly stringification at disabled log levels and yields richer structured logs. For example:

logger.debug(
  { jobId: job.id, data: job.data },
  "Processing 'rdb-import-make-local-backup' job"
);
backend/services/db-importer-worker/src/processors/RdbImportFlushInstanceProcessor.ts (1)

14-14: Use structured logging instead of JSON.stringify
Pino supports passing objects directly to its log methods, which avoids costly stringification at disabled log levels and yields richer structured logs. For example:

logger.debug(
  { jobId: job.id, data: job.data },
  "Processing 'rdb-import-flush-instance' job"
);
backend/services/db-importer-worker/src/processors/RdbImportRdbFormatValidationProcessor.ts (1)

14-14: Centralize and structure log metadata
Using logger.debug is a solid improvement. For richer, searchable logs, pass the job metadata as structured fields instead of stringifying:

logger.debug(
  { jobId: job.id, jobData: job.data },
  "Processing 'rdb-import-rdb-format-validation' job"
);
backend/services/db-importer-worker/src/processors/RdbExportMonitorRDBMergeProcessor.ts (1)

14-14: Adopt structured logging for clarity
Switching to logger.debug is appropriate. To leverage Pino’s structured logging, pass the relevant context instead of interpolating JSON manually:

logger.debug(
  { jobId: job.id, jobData: job.data },
  "Processing 'rdb-export-monitor-rdb-merge' job"
);
backend/services/db-importer-worker/src/processors/RdbExportSendSaveCommandProcessor.ts (1)

14-14: Enhance log calls with structured context
Good move to standardize on logger.debug. For better observability, log the job details as fields:

logger.debug(
  { jobId: job.id, jobData: job.data },
  "Processing 'rdb-export-send-save-command' job"
);
backend/services/db-importer-worker/src/processors/RdbImportDeleteLocalBackupProcessor.ts (1)

14-14: Use structured fields in debug logs
This change centralizes logging nicely. Consider sending metadata as an object for downstream log processing:

logger.debug(
  { jobId: job.id, jobData: job.data },
  "Processing 'rdb-import-delete-local-backup' job"
);
backend/services/db-importer-worker/src/repositories/tasks/TasksDBMongoRepository.ts (1)

20-22: Consider adding error handling for MongoDB connection.

Based on the AI summary, logging for successful MongoDB connection was removed. While this aligns with using the default logger, ensure that connection failures are still properly handled and logged.

Consider adding error handling:

 this._client.connect()
   .then(() => this._client.db(this._db).createIndex(this._collection, 'taskId', { unique: true }))
+  .catch((error) => this._options.logger.error({ error }, 'Failed to connect to MongoDB'));
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 62ee44d and 7ca008f.

📒 Files selected for processing (20)
  • backend/services/db-importer-worker/src/processors/RdbExportCopyRDBToBucketProcessor.ts (1 hunks)
  • backend/services/db-importer-worker/src/processors/RdbExportMonitorRDBMergeProcessor.ts (1 hunks)
  • backend/services/db-importer-worker/src/processors/RdbExportMonitorSaveProgressProcessor.ts (1 hunks)
  • backend/services/db-importer-worker/src/processors/RdbExportRequestRDBMergeProcessor.ts (1 hunks)
  • backend/services/db-importer-worker/src/processors/RdbExportRequestReadSignedURL.ts (1 hunks)
  • backend/services/db-importer-worker/src/processors/RdbExportSendSaveCommandProcessor.ts (1 hunks)
  • backend/services/db-importer-worker/src/processors/RdbImportDeleteLocalBackupProcessor.ts (1 hunks)
  • backend/services/db-importer-worker/src/processors/RdbImportFlushInstanceProcessor.ts (1 hunks)
  • backend/services/db-importer-worker/src/processors/RdbImportMakeLocalBackupProcessor.ts (1 hunks)
  • backend/services/db-importer-worker/src/processors/RdbImportMonitorFormatValidationProcessor.ts (1 hunks)
  • backend/services/db-importer-worker/src/processors/RdbImportMonitorImportRDBProcessor.ts (1 hunks)
  • backend/services/db-importer-worker/src/processors/RdbImportMonitorSaveProgressProcessor.ts (1 hunks)
  • backend/services/db-importer-worker/src/processors/RdbImportMonitorSizeValidationProcessor.ts (1 hunks)
  • backend/services/db-importer-worker/src/processors/RdbImportRdbFormatValidationProcessor.ts (1 hunks)
  • backend/services/db-importer-worker/src/processors/RdbImportRdbSizeValidationProcessor.ts (1 hunks)
  • backend/services/db-importer-worker/src/processors/RdbImportRecoverFailedImportProcessor.ts (1 hunks)
  • backend/services/db-importer-worker/src/processors/RdbImportRequestRdbImportProcessor.ts (1 hunks)
  • backend/services/db-importer-worker/src/processors/RdbImportSendSaveCommandProcessor.ts (1 hunks)
  • backend/services/db-importer-worker/src/processors/RdbImportValidateImportKeyNumberProcessor.ts (1 hunks)
  • backend/services/db-importer-worker/src/repositories/tasks/TasksDBMongoRepository.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
backend/services/db-importer-worker/src/repositories/tasks/TasksDBMongoRepository.ts (1)
backend/services/db-importer-worker/src/schemas/rdb-task.ts (1)
  • RDBTask (87-120)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Plan stack observability_stack_ctrl_plane_k8s
  • GitHub Check: Plan stack observability_stack_ctrl_plane_infra
  • GitHub Check: push
🔇 Additional comments (5)
backend/services/db-importer-worker/src/processors/RdbImportMonitorSaveProgressProcessor.ts (1)

14-14: Use default logger for job processing messages

The change from job.log to logger.debug unifies the logging approach; ensure the old job.log invocation was removed and the logger is properly injected.

backend/services/db-importer-worker/src/processors/RdbImportRdbSizeValidationProcessor.ts (1)

14-14: Use default logger for job processing messages

Switching from job.log() to logger.debug() standardizes logging across processors; confirm the injection of the logger and removal of any remaining job.log calls.

backend/services/db-importer-worker/src/processors/RdbImportRequestRdbImportProcessor.ts (1)

15-15: Use default logger for job processing messages

Replacing the job-specific job.log with logger.debug aligns with the new centralized logging strategy; verify that no legacy job.log calls remain.

backend/services/db-importer-worker/src/processors/RdbExportRequestRDBMergeProcessor.ts (1)

15-15: Use default logger for job processing messages

Standardizing on logger.debug instead of job.log ensures consistency; double-check that the injected logger is correctly configured for these processors.

backend/services/db-importer-worker/src/processors/RdbImportValidateImportKeyNumberProcessor.ts (1)

19-19: Use default logger for job processing messages

Converting job.log() calls to logger.debug() centralizes logging; confirm that the container provides the proper logger instance and that job.log is no longer used.

Comment on lines +32 to 34
return RDBTask.cast(task, {
stripUnknown: true,
}) as RDBTaskType;
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Critical: Validation behavior change may compromise data integrity.

The switch from RDBTask.validateSync to RDBTask.cast introduces a significant behavioral change that could compromise data integrity:

  1. validateSync would throw validation errors for invalid data, ensuring only valid tasks are processed
  2. cast performs type coercion but doesn't enforce validation rules, potentially allowing invalid data to pass through

Given that the RDBTask schema (from backend/services/db-importer-worker/src/schemas/rdb-task.ts) is marked as .strict().noUnknown().required(), this change removes critical validation safeguards.

Recommended approaches:

  1. Revert to validation with proper error handling:
-return RDBTask.cast(task, {
-  stripUnknown: true,
-}) as RDBTaskType;
+try {
+  return RDBTask.validateSync(task, {
+    stripUnknown: true,
+    strict: true
+  }) as RDBTaskType;
+} catch (error) {
+  this._options.logger.error({ taskId, error }, 'Task validation failed');
+  throw error;
+}
  1. Or use validate (async) if you need to handle validation errors gracefully:
-return RDBTask.cast(task, {
-  stripUnknown: true,
-}) as RDBTaskType;
+try {
+  return await RDBTask.validate(task, {
+    stripUnknown: true,
+    strict: true
+  }) as RDBTaskType;
+} catch (error) {
+  this._options.logger.error({ taskId, error }, 'Task validation failed');
+  return null; // or handle as appropriate
+}

Verify the impact of this change by checking if there are error handling mechanisms downstream:


🏁 Script executed:

#!/bin/bash
# Description: Check for error handling of invalid task data downstream
# Expected: Find places where task properties are accessed that might fail with invalid data

echo "Searching for task property access patterns that might fail with invalid data..."
rg -A 3 -B 1 "\.taskId|\.type|\.status|\.payload|\.output" --type ts

Length of output: 66091


🏁 Script executed:

#!/bin/bash
echo "Finding TasksDBMongoRepository.ts files..."
fd -e ts TasksDBMongoRepository.ts

Length of output: 294


🏁 Script executed:

#!/bin/bash
# Display imports and the RDBTask usage around lines 1-60
sed -n '1,60p' backend/services/db-importer-worker/src/repositories/tasks/TasksDBMongoRepository.ts

Length of output: 1615


Preserve runtime validation in getTaskById

Switching from RDBTask.validateSync to RDBTask.cast bypasses Yup’s required‐field and strict schema checks, so malformed or incomplete documents could slip through and cause silent failures or data corruption. There’s no downstream catch for invalid tasks, so we need to restore validation at the repository boundary.

• File: backend/services/db-importer-worker/src/repositories/tasks/TasksDBMongoRepository.ts
Location: return in async getTaskById (around lines 32–34)

Recommended diff:

-    return RDBTask.cast(task, {
-      stripUnknown: true,
-    }) as RDBTaskType;
+    try {
+      return RDBTask.validateSync(task, {
+        stripUnknown: true,
+        strict: true,
+      }) as RDBTaskType;
+    } catch (error) {
+      this._options.logger.error({ taskId, error }, 'Task validation failed');
+      throw error;
+    }

Or, to use async validation:

-    return RDBTask.cast(task, {
-      stripUnknown: true,
-    }) as RDBTaskType;
+    try {
+      return await RDBTask.validate(task, {
+        stripUnknown: true,
+        strict: true,
+      }) as RDBTaskType;
+    } catch (error) {
+      this._options.logger.error({ taskId, error }, 'Task validation failed');
+      throw error;
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return RDBTask.cast(task, {
stripUnknown: true,
}) as RDBTaskType;
try {
return RDBTask.validateSync(task, {
stripUnknown: true,
strict: true,
}) as RDBTaskType;
} catch (error) {
this._options.logger.error({ taskId, error }, 'Task validation failed');
throw error;
}
🤖 Prompt for AI Agents
In
backend/services/db-importer-worker/src/repositories/tasks/TasksDBMongoRepository.ts
around lines 32 to 34, the code currently uses RDBTask.cast which only coerces
types without enforcing validation, risking invalid data passing through. To fix
this, revert to using RDBTask.validateSync or use the async RDBTask.validate
method to perform strict validation according to the schema, ensuring required
fields and no unknown fields are enforced. Also, add proper error handling for
validation failures to prevent silent data corruption and maintain data
integrity at the repository boundary.

@dudizimber dudizimber merged commit 9834f90 into main Jun 4, 2025
22 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Jun 5, 2025
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