Skip to content

fix: log when calculated top-up-amount is not a positive value#1861

Merged
baktun14 merged 1 commit intoakash-network:mainfrom
jzsfkzm:bugfixes/1841-log-non-positive-top-up
Aug 28, 2025
Merged

fix: log when calculated top-up-amount is not a positive value#1861
baktun14 merged 1 commit intoakash-network:mainfrom
jzsfkzm:bugfixes/1841-log-non-positive-top-up

Conversation

@jzsfkzm
Copy link
Contributor

@jzsfkzm jzsfkzm commented Aug 27, 2025

refs #1841

Summary by CodeRabbit

  • Chores
    • Added non-fatal warning logs when computed top-up amounts are non-positive, including contextual details to aid troubleshooting.
    • Improved observability for deployment settings and managed top-up flows without changing behavior or interfaces.
    • No user-facing changes; existing functionality and outcomes remain the same.

@jzsfkzm jzsfkzm requested a review from a team as a code owner August 27, 2025 23:08
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 27, 2025

Walkthrough

Added non-fatal warning logs when computed top-up amounts are non-positive in two services: DeploymentSettingService.withEstimatedTopUpAmount and TopUpManagedDeploymentsService.collectMessages. Introduced a LoggerService instance in DeploymentSettingService. No control flow or public API changes.

Changes

Cohort / File(s) Summary
Logging in Deployment Settings
apps/api/src/deployment/services/deployment-setting/deployment-setting.service.ts
Added LoggerService usage; logs a warning when estimatedTopUpAmount <= 0 with event and context (estimatedTopUpAmount, dseq, userId). No API changes.
Logging in Managed Top-Ups
apps/api/src/deployment/services/top-up-managed-deployments/top-up-managed-deployments.service.ts
Added warning log in collectMessages when desiredAmount <= 0 with context (desiredAmount, dseq, address, blockRate). Flow continues unchanged.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Caller
  participant DSS as DeploymentSettingService
  participant Logger

  Caller->>DSS: withEstimatedTopUpAmount(dseq, userId, ...)
  DSS->>DSS: compute estimatedTopUpAmount
  alt estimatedTopUpAmount <= 0
    DSS->>Logger: warn(TOP_UP_AMOUNT_NON_POSITIVE, {estimatedTopUpAmount, dseq, userId})
  end
  DSS-->>Caller: result (unchanged structure)
Loading
sequenceDiagram
  autonumber
  actor Scheduler
  participant TUMD as TopUpManagedDeploymentsService
  participant Balance as BalanceCalculator
  participant Logger

  Scheduler->>TUMD: collectMessages(...)
  TUMD->>Balance: compute balance, desiredAmount
  alt desiredAmount <= 0
    TUMD->>Logger: warn(TOP_UP_AMOUNT_NON_POSITIVE, {desiredAmount, dseq, address, blockRate})
  end
  TUMD->>Balance: reserveSufficientAmount(desiredAmount)
  TUMD-->>Scheduler: prepared messages (flow unchanged)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • ygrishajev

Poem

A carrot of logs in the garden of code,
I thump-thump notes on a non-positive road.
Warnings sprout softly—no flow to upend—
Breadcrumbs for burrows our queries can friend.
Hop on, dear bytes, with a whisker-wide grin—🥕🐇

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between b9da01f and 5e55d18.

📒 Files selected for processing (2)
  • apps/api/src/deployment/services/deployment-setting/deployment-setting.service.ts (3 hunks)
  • apps/api/src/deployment/services/top-up-managed-deployments/top-up-managed-deployments.service.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/api/src/deployment/services/deployment-setting/deployment-setting.service.ts
  • apps/api/src/deployment/services/top-up-managed-deployments/top-up-managed-deployments.service.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbit in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbit 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:
    • @coderabbit gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbit read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbit help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbit ignore or @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbit summary or @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbit or @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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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: 0

🧹 Nitpick comments (3)
apps/api/src/deployment/services/deployment-setting/deployment-setting.service.ts (2)

7-7: Avoid mixing two LoggerService implementations

This file imports LoggerService from "@src/core/providers/logging.provider" while TopUpManagedDeploymentsService uses "@akashnetwork/logging". Standardize on one to prevent divergent behaviors and config. If both are aliases, consolidate to the shared package for clarity.

Proposed change:

-import { LoggerService } from "@src/core/providers/logging.provider";
+import { LoggerService } from "@akashnetwork/logging";

85-92: Good: non-positive estimate warning; confirm consumer expectations for negatives

The warning is helpful. Verify that API consumers expect negative estimatedTopUpAmount values; otherwise consider normalizing to 0 at the return site to avoid UI confusion.

apps/api/src/deployment/services/top-up-managed-deployments/top-up-managed-deployments.service.ts (1)

91-99: Log is good; optionally skip message construction on non-positive desiredAmount and include dryRun in the log

Continuing to build a message for desiredAmount <= 0 can waste work or produce invalid txs depending on downstream behavior. Optionally short-circuit and add dryRun for parity with other logs.

-          if (desiredAmount <= 0) {
-            this.logger.warn({
-              event: "TOP_UP_AMOUNT_NON_POSITIVE",
-              desiredAmount,
-              dseq: deployment.dseq,
-              address: deployment.address,
-              blockRate: deployment.blockRate
-            });
-          }
+          if (desiredAmount <= 0) {
+            this.logger.warn({
+              event: "TOP_UP_AMOUNT_NON_POSITIVE",
+              desiredAmount,
+              dseq: deployment.dseq,
+              address: deployment.address,
+              blockRate: deployment.blockRate,
+              dryRun: options.dryRun
+            });
+            return;
+          }

Also consider centralizing event names as constants/enums to avoid typos across services.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between cbb3570 and b9da01f.

📒 Files selected for processing (2)
  • apps/api/src/deployment/services/deployment-setting/deployment-setting.service.ts (3 hunks)
  • apps/api/src/deployment/services/top-up-managed-deployments/top-up-managed-deployments.service.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Never use type any or cast to type any. Always define the proper TypeScript types.

Files:

  • apps/api/src/deployment/services/top-up-managed-deployments/top-up-managed-deployments.service.ts
  • apps/api/src/deployment/services/deployment-setting/deployment-setting.service.ts
**/*.{js,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

**/*.{js,ts,tsx}: Never use deprecated methods from libraries.
Don't add unnecessary comments to the code

Files:

  • apps/api/src/deployment/services/top-up-managed-deployments/top-up-managed-deployments.service.ts
  • apps/api/src/deployment/services/deployment-setting/deployment-setting.service.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
🔇 Additional comments (1)
apps/api/src/deployment/services/deployment-setting/deployment-setting.service.ts (1)

21-21: LGTM: contextual logger setup

Consistent with other services and enables scoped logs.

@jzsfkzm jzsfkzm force-pushed the bugfixes/1841-log-non-positive-top-up branch from b9da01f to 5e55d18 Compare August 28, 2025 07:33
@baktun14 baktun14 merged commit 5090f75 into akash-network:main Aug 28, 2025
57 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.

2 participants

Comments