Skip to content

Conversation

mxsm
Copy link
Owner

@mxsm mxsm commented Sep 11, 2025

Which Issue(s) This PR Fixes(Closes)

Fixes #4016

Brief Description

How Did You Test This Change?

Summary by CodeRabbit

  • Bug Fixes
    • Improved robustness when resolving the user home directory and converting paths, reducing chances of startup failures.
  • Refactor
    • Updated default locations for NameServer configuration files to use a more consistent directory structure. Existing environments relying on previous default paths may need to adjust their configuration or migrate files.

@Copilot Copilot AI review requested due to automatic review settings September 11, 2025 03:33
Copy link
Contributor

coderabbitai bot commented Sep 11, 2025

Walkthrough

Refactors path construction in namesrv_config.rs: both kv_config_path() and config_store_path() now use PathBuf with push("namesrv") and updated filenames. Replaces unwrap() calls with unwrap_or_default() for home_dir and to_str conversions. Directory and filenames differ from previous values.

Changes

Cohort / File(s) Summary
Namesrv path construction refactor
rocketmq-common/src/common/namesrv/namesrv_config.rs
Rewrote kv_config_path() and config_store_path() to build paths via PathBuf: append "namesrv" and respective filenames ("kvConfig.json", "namesrv.properties"). Previously used formatted strings with "rocketmq-namesrv" directory and "rocketmq-namesrv.properties". Replaced unwrap() with unwrap_or_default() to reduce panics on home_dir and to_str.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks (3 passed, 2 warnings)

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Linked Issues Check ⚠️ Warning The PR implements the targeted refactor by switching to PathBuf and using unwrap_or_default for the two methods, which reduces panic risk and keeps public signatures unchanged, but it does not address several checklist items from [#4016] that are coding-related (notably unit tests and performance validation) and no documentation or test artifacts are included in the PR description. Because there are no unit tests or performance measurements provided I cannot confirm the refactor meets the linked issue's requirements for verification and safety. Add unit tests covering expected and edge cases (e.g., missing home_dir and non-UTF8 paths), include a brief performance note or micro-benchmark if performance is a concern, and update the PR description to document the behavioral intent and test results.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title accurately and specifically describes the main change — refactoring kv_config_path and config_store_path for improved readability — and references the linked issue so reviewers can quickly understand the PR's intent. The emoji and issue tag are minor noise but do not obscure the meaning.
Out of Scope Changes Check ✅ Passed The changes are confined to rocketmq-common/src/common/namesrv/namesrv_config.rs and only modify the internal path-construction logic for kv_config_path and config_store_path without changing public signatures or touching unrelated modules, so there are no apparent out-of-scope modifications.

Poem

I hop through paths where configs lie,
From rocketmq-namesrv to namesrv, oh my!
With PathBuf crumbs, I trace the trail,
unwrap_or_default so I won’t derail.
Two tidy routes, no panic to dread—
A refactor nibble, then off I tread! 🥕🐇

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor-4016

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@rocketmq-rust-bot
Copy link
Collaborator

🔊@mxsm 🚀Thanks for your contribution🎉!

💡CodeRabbit(AI) will review your code first🔥!

Note

🚨The code review suggestions from CodeRabbit are to be used as a reference only, and the PR submitter can decide whether to make changes based on their own judgment. Ultimately, the project management personnel will conduct the final code review💥.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Refactors the path construction methods in namesrv_config.rs to improve code readability by replacing string formatting with Path API methods.

  • Simplified kv_config_path() and config_store_path() methods using PathBuf operations instead of manual string concatenation
  • Enhanced error handling by using unwrap_or_default() for safer path operations

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +41 to +48
kv_config_path.push("namesrv");
kv_config_path.push("kvConfig.json");
kv_config_path.to_str().unwrap_or_default().to_string()
}

pub fn config_store_path() -> String {
format!(
"{}{}{}{}{}",
dirs::home_dir().unwrap().to_str().unwrap(),
MAIN_SEPARATOR,
"rocketmq-namesrv",
MAIN_SEPARATOR,
"rocketmq-namesrv.properties"
)
let mut kv_config_path = dirs::home_dir().unwrap_or_default();
kv_config_path.push("namesrv");
Copy link

Copilot AI Sep 11, 2025

Choose a reason for hiding this comment

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

The directory name changed from 'rocketmq-namesrv' to 'namesrv', which is a breaking change that will cause the application to look for configuration files in a different location.

Copilot uses AI. Check for mistakes.

)
let mut kv_config_path = dirs::home_dir().unwrap_or_default();
kv_config_path.push("namesrv");
kv_config_path.push("namesrv.properties");
Copy link

Copilot AI Sep 11, 2025

Choose a reason for hiding this comment

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

The file name changed from 'rocketmq-namesrv.properties' to 'namesrv.properties', which is a breaking change that will cause the application to look for a different configuration file.

Suggested change
kv_config_path.push("namesrv.properties");
kv_config_path.push("rocketmq-namesrv.properties");

Copilot uses AI. Check for mistakes.

Copy link

codecov bot commented Sep 11, 2025

Codecov Report

❌ Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 26.58%. Comparing base (3a76306) to head (13e260d).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...cketmq-common/src/common/namesrv/namesrv_config.rs 0.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4017      +/-   ##
==========================================
- Coverage   26.58%   26.58%   -0.01%     
==========================================
  Files         565      565              
  Lines       80703    80705       +2     
==========================================
  Hits        21453    21453              
- Misses      59250    59252       +2     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Collaborator

@rocketmq-rust-bot rocketmq-rust-bot left a comment

Choose a reason for hiding this comment

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

LGTM

@rocketmq-rust-bot rocketmq-rust-bot merged commit cb17b08 into main Sep 11, 2025
21 of 23 checks passed
@rocketmq-rust-bot rocketmq-rust-bot added approved PR has approved and removed ready to review waiting-review waiting review this PR labels Sep 11, 2025
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: 3

🧹 Nitpick comments (2)
rocketmq-common/src/common/namesrv/namesrv_config.rs (2)

20-20: Remove unused import

use std::path::MAIN_SEPARATOR; is unused (the code references std::path::MAIN_SEPARATOR directly later). Drop the import to avoid warnings.

-use std::path::MAIN_SEPARATOR;

198-219: Optional: unify Default impl with PathBuf

To keep style consistent and avoid manual separators, consider refactoring the Default impl paths to use PathBuf (or the default_namesrv_file() helper), preserving the same folder/filenames.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3a76306 and 13e260d.

📒 Files selected for processing (1)
  • rocketmq-common/src/common/namesrv/namesrv_config.rs (1 hunks)
⏰ 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). (9)
  • GitHub Check: test
  • GitHub Check: build
  • GitHub Check: build (ubuntu-latest, stable)
  • GitHub Check: build (macos-latest, stable)
  • GitHub Check: build (windows-latest, nightly)
  • GitHub Check: build (windows-latest, stable)
  • GitHub Check: build (macos-latest, nightly)
  • GitHub Check: build (ubuntu-latest, nightly)
  • GitHub Check: auto-approve

Comment on lines 39 to 44
pub fn kv_config_path() -> String {
format!(
"{}{}{}{}{}",
dirs::home_dir().unwrap().to_str().unwrap(),
MAIN_SEPARATOR,
"rocketmq-namesrv",
MAIN_SEPARATOR,
"kvConfig.json"
)
let mut kv_config_path = dirs::home_dir().unwrap_or_default();
kv_config_path.push("namesrv");
kv_config_path.push("kvConfig.json");
kv_config_path.to_str().unwrap_or_default().to_string()
}
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

⚠️ Potential issue

Unintended behavior change + silent fallback: align path and avoid empty-string defaults

  • Directory changed from "rocketmq-namesrv" to "namesrv" and string conversion now silently returns "" on failure. This diverges from Default::default() (which still uses "rocketmq-namesrv") and risks subtle misconfigurations.
  • Keep PathBuf (readable), but preserve prior semantics and consistency with Default/tests.

Apply:

-    let mut kv_config_path = dirs::home_dir().unwrap_or_default();
-    kv_config_path.push("namesrv");
-    kv_config_path.push("kvConfig.json");
-    kv_config_path.to_str().unwrap_or_default().to_string()
+    let mut path = dirs::home_dir().expect("home_dir unavailable");
+    path.push("rocketmq-namesrv");
+    path.push("kvConfig.json");
+    path.to_string_lossy().into_owned()

Optional helper to DRY both functions (place inside defaults module, outside this hunk):

fn default_namesrv_file(file: &str) -> String {
    let mut p = dirs::home_dir().expect("home_dir unavailable");
    p.push("rocketmq-namesrv");
    p.push(file);
    p.to_string_lossy().into_owned()
}
🤖 Prompt for AI Agents
In rocketmq-common/src/common/namesrv/namesrv_config.rs around lines 39 to 44,
restore the original semantics by keeping a PathBuf and using the
"rocketmq-namesrv" directory (not "namesrv"), avoid silently returning an empty
string on to_str failure, and surface errors instead of falling back: build the
path from dirs::home_dir().expect("home_dir unavailable"), push
"rocketmq-namesrv" and the filename, then convert to a String with
to_string_lossy().into_owned() (or use the provided default_namesrv_file helper
in the defaults module and call it here) so behavior matches Default/tests and
avoids empty-string fallbacks.

💡 Verification agent

🧩 Analysis chain

Repo-wide check for path changes

Scan for usages that assume "rocketmq-namesrv" or "rocketmq-namesrv.properties" to ensure no hidden breakages if names were to change.

Also applies to: 46-51


🏁 Script executed:

#!/bin/bash
# Find hardcoded paths and filenames that could be impacted.
rg -n -C2 -S $'rocketmq-namesrv\\.properties|namesrv\\.properties|rocketmq-namesrv[/\\\\]|[/\\\\]namesrv[/\\\\]' -g '!**/target/**'

Length of output: 148


🏁 Script executed:

#!/bin/bash
set -euo pipefail
echo "PWD: $(pwd)"
echo "Top-level listing:"
ls -la | sed -n '1,200p' || true

echo
echo "Checking ripgrep (rg) availability..."
if command -v rg >/dev/null 2>&1; then
  rg --version || true
  echo
  echo "Searching repository for 'namesrv' and related filenames (no exclusion globs)..."
  rg -n -C2 -S 'rocketmq-namesrv\.properties|namesrv\.properties|rocketmq-namesrv[/\\]|[/\\]namesrv[/\\]|\bnamesrv\b|rocketmq-namesrv' --hidden -uu || true
else
  echo "rg not found, falling back to grep"
  grep -R -n --exclude-dir=target -E 'rocketmq-namesrv\.properties|namesrv\.properties|rocketmq-namesrv[/\\]|[/\\]namesrv[/\\]|\bnamesrv\b|rocketmq-namesrv' . || true
fi

echo
echo "Show target file if present: rocketmq-common/src/common/namesrv/namesrv_config.rs"
if [ -f rocketmq-common/src/common/namesrv/namesrv_config.rs ]; then
  echo "---- file content start ----"
  sed -n '1,240p' rocketmq-common/src/common/namesrv/namesrv_config.rs || true
  echo "---- file content end ----"
else
  echo "File not found at rocketmq-common/src/common/namesrv/namesrv_config.rs"
fi

Length of output: 73664


Unify namesrv path naming: resolve 'namesrv' vs 'rocketmq-namesrv' inconsistency

defaults::kv_config_path / defaults::config_store_path build paths under ~/namesrv/* while Default::default and format! calls build ~/rocketmq-namesrv/* — this will cause inconsistent runtime locations and break config/kv loading. Pick one canonical directory name (or add explicit fallback checks) and update all occurrences.

Locations to fix:

  • rocketmq-common/src/common/namesrv/namesrv_config.rs — defaults::kv_config_path (lines ~39–43) and defaults::config_store_path (46–50); Default::default uses "rocketmq-namesrv" (lines ~204–217) and format! uses "rocketmq-namesrv" (lines ~483–496).
  • distribution/config/nameserver/namesrv.toml and distribution/config/nameserver/namesrv.conf — kvConfigPath/configStorePath point to ${user.home}/namesrv/... (lines ~20–24).
🤖 Prompt for AI Agents
In rocketmq-common/src/common/namesrv/namesrv_config.rs around lines 39–44, the
kv_config_path currently builds a path under ~/namesrv/* which conflicts with
other code that uses ~/rocketmq-namesrv/*; change the directory component from
"namesrv" to "rocketmq-namesrv" (and apply the same change for config_store_path
near lines 46–50) so all defaults use a single canonical directory name, or
alternatively implement a fallback check that prefers ~/rocketmq-namesrv/* and
falls back to ~/namesrv/* when files are missing; update any hardcoded format!
or Default::default occurrences to the same canonical name to keep runtime
locations consistent.

Comment on lines 46 to 51
pub fn config_store_path() -> String {
format!(
"{}{}{}{}{}",
dirs::home_dir().unwrap().to_str().unwrap(),
MAIN_SEPARATOR,
"rocketmq-namesrv",
MAIN_SEPARATOR,
"rocketmq-namesrv.properties"
)
let mut kv_config_path = dirs::home_dir().unwrap_or_default();
kv_config_path.push("namesrv");
kv_config_path.push("namesrv.properties");
kv_config_path.to_str().unwrap_or_default().to_string()
}
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

Filename and folder regressions + misnamed local var

  • Folder changed to "namesrv" and file to "namesrv.properties" (was "rocketmq-namesrv.properties"), which breaks backward compatibility and differs from Default::default().
  • Local var kv_config_path is misleading in config_store_path().

Apply:

-    let mut kv_config_path = dirs::home_dir().unwrap_or_default();
-    kv_config_path.push("namesrv");
-    kv_config_path.push("namesrv.properties");
-    kv_config_path.to_str().unwrap_or_default().to_string()
+    let mut path = dirs::home_dir().expect("home_dir unavailable");
+    path.push("rocketmq-namesrv");
+    path.push("rocketmq-namesrv.properties");
+    path.to_string_lossy().into_owned()

If you add the helper suggested above:

-    let mut path = dirs::home_dir().expect("home_dir unavailable");
-    path.push("rocketmq-namesrv");
-    path.push("rocketmq-namesrv.properties");
-    path.to_string_lossy().into_owned()
+    default_namesrv_file("rocketmq-namesrv.properties")
📝 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
pub fn config_store_path() -> String {
format!(
"{}{}{}{}{}",
dirs::home_dir().unwrap().to_str().unwrap(),
MAIN_SEPARATOR,
"rocketmq-namesrv",
MAIN_SEPARATOR,
"rocketmq-namesrv.properties"
)
let mut kv_config_path = dirs::home_dir().unwrap_or_default();
kv_config_path.push("namesrv");
kv_config_path.push("namesrv.properties");
kv_config_path.to_str().unwrap_or_default().to_string()
}
pub fn config_store_path() -> String {
- let mut kv_config_path = dirs::home_dir().unwrap_or_default();
- kv_config_path.push("namesrv");
- kv_config_path.push("namesrv.properties");
let mut path = dirs::home_dir().expect("home_dir unavailable");
path.push("rocketmq-namesrv");
path.push("rocketmq-namesrv.properties");
path.to_string_lossy().into_owned()
}
🤖 Prompt for AI Agents
In rocketmq-common/src/common/namesrv/namesrv_config.rs around lines 46 to 51,
the function changed the folder/file to "namesrv/namesrv.properties" and uses a
misleading local variable name `kv_config_path`; restore backward compatibility
by using the original filename "rocketmq-namesrv.properties" (and the original
folder if applicable to match Default::default()), and rename the local variable
to a clearer name such as `config_path` or `path`; if you added the suggested
helper, call it here instead of duplicating logic so the path generation is
centralized and consistent with Default::default().

@mxsm mxsm deleted the refactor-4016 branch September 11, 2025 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI review first Ai review pr first approved PR has approved auto merge refactor♻️ refactor code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Refactor♻️]Refactor: Simplify kv_config_path and config_store_path methods for improved readability

3 participants