Skip to content

Conversation

@edragain2nd
Copy link
Contributor

@edragain2nd edragain2nd commented Nov 20, 2025

Summary by CodeRabbit

  • Refactor
    • Account, user, and QoS modify flows now accept and process multiple field changes in a single request, consolidating sequential edits into one operation.
  • New Features
    • Modify operations return richer error details and clearer success messaging to better explain outcomes.
  • Behavior
    • Per-field validation and parsing now report errors tied to the specific field, improving feedback for multi-change requests.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 20, 2025

Walkthrough

Refactors account, user, and QoS modify flows to accept slices of ModifyParam, build per-parameter ModifyFieldOperation entries, and send batched RPC requests; updates protobufs to add ModifyFieldOperation and replace single-field modify_* request fields with repeated operations.

Changes

Cohort / File(s) Summary
Protobuf message & RPC changes
protos/Crane.proto
Added ModifyFieldOperation message; replaced single-field modify inputs in ModifyAccountRequest, ModifyUserRequest, and ModifyQosRequest with repeated ModifyFieldOperation operations; ModifyQosReply now carries repeated RichError.
Command handlers / param type
internal/cacctmgr/cmd.go
Added ModifyParam struct (ModifyField, NewValue, RequestType). Refactored command handlers to accumulate []ModifyParam and invoke high-level Modify* functions with the collected params.
Core modification logic
internal/cacctmgr/cacctmgr.go
Updated signatures: ModifyAccount, ModifyUser, ModifyQos now accept params []ModifyParam. Implemented per-parameter parsing/validation, construct ModifyFieldOperation entries, aggregate operations, and issue a single RPC call; adjusted error handling and output messages.

Sequence Diagram

sequenceDiagram
    participant CLI as Command Handler
    participant Cmd as Param Collector
    participant CAcct as cacctmgr.Modify*
    participant RPC as RPC Stub (CraneCtld)

    rect rgb(230, 245, 230)
    CLI->>Cmd: parse flags -> create ModifyParam(s)
    Cmd-->>CLI: params []ModifyParam
    CLI->>CAcct: ModifyAccount/ModifyUser/ModifyQos(params, ...)
    end

    rect rgb(230, 240, 255)
    CAcct->>CAcct: for each param: validate & parse value
    CAcct->>CAcct: build ModifyFieldOperation list
    CAcct->>RPC: stub.Modify*(Request{name, operations: [...]})
    RPC-->>CAcct: Reply (ok / rich_error_list)
    CAcct-->>CLI: exit code / output (success or rich errors)
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Inspect protobuf field numbering and ensure generated code/clients are updated.
  • Review per-parameter validation branches in internal/cacctmgr/cacctmgr.go for early returns and error mapping.
  • Verify construction of ModifyFieldOperation preserves field-specific semantics (Description, DefaultQos, AdminLevel, Force, JSON paths).
  • Check error propagation and formatting (rich errors) from RPC replies.

Poem

🐇 I nibble params one by one and then I bunch,

Many changes bundled — quick! — in crunchy lunch.
Operations stacked, a hop, a cheerful tweak,
Batched and sent, no single-field squeak.
Hooray for rabbits coding in a bunch!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
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.
Title check ❓ Inconclusive The PR title 'fix: duplicate modification message output' is vague and does not accurately describe the substantial changes made. The changeset involves comprehensive refactoring of modify operations across account, user, and QoS entities, replacing individual parameter calls with batch operations using a new ModifyParam structure. Consider revising the title to better reflect the main change, such as 'refactor: consolidate modify operations into batch request handling' or similar, to more accurately represent the scope of changes.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • 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

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

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 (4)
internal/cacctmgr/cmd.go (3)

587-676: Account modify aggregation correctly centralizes operations

Collecting all set/add/delete clauses into params []ModifyParam and issuing a single ModifyAccount call aligns with the new proto and removes the prior risk of duplicate success/failure messages. Logic per field and per operation type looks consistent with existing semantics.

You could later drop the intermediate Flag* assignments here (e.g., FlagDescription, FlagSetPartitionList) and write values directly into ModifyParam to reduce global state churn, but that’s not required for this fix.


724-813: User modify aggregation is consistent and validates admin level early

The new params []ModifyParam flow for user modifications mirrors the account path, and the explicit admin-level validation before building operations is good. This should ensure only a single ModifyUser RPC (and result message) per command.

Similar to the account path, the Flag* intermediates (e.g., FlagSetPartitionList, FlagUserDefaultQos) could be made local or inlined into ModifyParam later to reduce reliance on package globals.


850-901: QoS modify path: consider setting RequestType explicitly and using it

Currently, QoS ModifyParam entries are created without RequestType, and ModifyQos (in internal/cacctmgr/cacctmgr.go) ignores param.RequestType and relies on the proto’s default OperationType. That’s probably fine today since only set semantics are supported, but it’s less explicit and could bite you if OperationType ever changes or QoS gains add/delete semantics.

I’d recommend:

  • Explicitly setting RequestType: protos.OperationType_Overwrite when building QoS ModifyParam values; and
  • In ModifyQos, passing Type: param.RequestType when appending ModifyFieldOperation.

Example diff for this file:

-  case "maxcpusperuser":
+  case "maxcpusperuser":
       if err := validateUintValue(value, "maxCpusPerUser", 32); err != nil {
         return util.ErrorCmdArg
       }
       FlagMaxCpu = value
       params = append(params, ModifyParam{
         ModifyField: protos.ModifyField_MaxCpusPerUser,
         NewValue:    FlagMaxCpu,
+        RequestType: protos.OperationType_Overwrite,
       })

(and similarly for the other QoS fields).

Please double‑check the OperationType enum definition (in your proto) to ensure the current default actually corresponds to overwrite; if not, this change becomes functionally necessary rather than cosmetic.

internal/cacctmgr/cacctmgr.go (1)

785-822: QoS modification batching is correct but should ideally carry explicit operation types

ModifyQos correctly aggregates QoS field updates into operations and issues a single RPC, fixing duplicate messages along this path as well. However, it currently ignores param.RequestType and relies on the default OperationType on the server side.

To stay consistent with account/user handling and avoid relying on enum defaults, consider:

for _, param := range params {
-  req.Operations = append(req.Operations, &protos.ModifyFieldOperation{
-    ModifyField: param.ModifyField,
-    ValueList:   []string{param.NewValue},
-  })
+  req.Operations = append(req.Operations, &protos.ModifyFieldOperation{
+    ModifyField: param.ModifyField,
+    ValueList:   []string{param.NewValue},
+    Type:        param.RequestType,
+  })
}

This pairs with explicitly setting RequestType in executeModifyQosCommand (see comment in internal/cacctmgr/cmd.go), and keeps behavior robust if QoS ever supports non‑overwrite operations.

Please confirm the current server expects or ignores OperationType for QoS modifications so we know whether this is just a clarity improvement or required for correctness.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7aebd01 and aacc673.

📒 Files selected for processing (3)
  • internal/cacctmgr/cacctmgr.go (3 hunks)
  • internal/cacctmgr/cmd.go (8 hunks)
  • protos/Crane.proto (8 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
internal/cacctmgr/cmd.go (1)
internal/cacctmgr/cacctmgr.go (3)
  • ModifyAccount (646-712)
  • ModifyUser (714-783)
  • ModifyQos (785-822)
internal/cacctmgr/cacctmgr.go (3)
internal/cacctmgr/cmd.go (2)
  • ModifyParam (92-96)
  • FlagForce (60-60)
internal/util/err.go (2)
  • ExitCode (30-30)
  • ErrorCmdArg (36-36)
internal/util/string.go (1)
  • ParseStringParamList (1087-1096)
🔇 Additional comments (6)
internal/cacctmgr/cmd.go (1)

92-96: ModifyParam struct shape looks appropriate

Fields map cleanly to ModifyFieldOperation usage and keep the command layer decoupled from proto details. No issues here.

protos/Crane.proto (3)

343-347: ModifyFieldOperation message design is compatible with the new param model

The modify_field, value_list, and type fields map cleanly to the Go ModifyParam usage and allow batching heterogeneous modifications in a single request.


349-379: Modify*Request message reshaping aligns with batched operations

Using name plus repeated ModifyFieldOperation operations in ModifyAccountRequest, ModifyUserRequest, and ModifyQosRequest matches the new client‑side aggregation and enables multi‑field changes per RPC. Field numbering (keeping uid = 1 and introducing new tags for the additional fields) looks safe for coordinated client/server upgrades.


990-1129: Service definition changes are formatting-only

The changes in the service blocks here are line‑wrapping and comment formatting; RPC names and request/reply types are unchanged, so there’s no behavioral impact.

internal/cacctmgr/cacctmgr.go (2)

646-712: Account modification implementation matches new proto and avoids duplicate output

ModifyAccount now iterates over params, parses value lists once per param, validates single-value fields (Description, DefaultQos), and builds a single ModifyAccountRequest.Operations slice before calling the RPC. Error handling is consistent, and success/failure messages are printed exactly once per command, addressing the duplicate‑message issue.


714-783: User modification batching is correct and preserves validation semantics

ModifyUser correctly validates AdminLevel upfront, enforces single‑value semantics for AdminLevel, DefaultQos, and DefaultAccount, and appends each operation (including add/delete) with its RequestType. As with accounts, this yields one RPC and one set of messages per command instead of per‑field calls.

@Nativu5
Copy link
Collaborator

Nativu5 commented Nov 26, 2025

rebase 一下吧

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: 1

🧹 Nitpick comments (1)
internal/cacctmgr/cacctmgr.go (1)

362-399: ModifyAccount: validation and batched operations look correct

  • Per‑param parsing via ParseStringParamList and tailored error messages for Qos / Partition are reasonable.
  • Enforcing single values for DefaultQos and Description avoids ambiguous multi‑value updates.
  • Building req.Operations with ModifyField, ValueList, and Type: param.RequestType matches the new proto and enables multiple field updates in a single RPC.
  • Consolidated reply handling (single success/failure message with iteration over RichErrorList) prevents duplicated output and improves clarity.

Only minor style nit: valueList/err could be declared inside the loop to reduce scope, but current code is functionally fine.

Also applies to: 415-428

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aacc673 and 99e200b.

📒 Files selected for processing (3)
  • internal/cacctmgr/cacctmgr.go (6 hunks)
  • internal/cacctmgr/cmd.go (8 hunks)
  • protos/Crane.proto (8 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/cacctmgr/cmd.go
🧰 Additional context used
🧬 Code graph analysis (1)
internal/cacctmgr/cacctmgr.go (3)
internal/cacctmgr/cmd.go (2)
  • ModifyParam (102-106)
  • FlagForce (60-60)
internal/util/err.go (4)
  • ExitCode (30-30)
  • ErrorCmdArg (36-36)
  • ErrorSuccess (34-34)
  • ErrMsg (203-208)
internal/util/string.go (1)
  • ParseStringParamList (1132-1141)
🔇 Additional comments (4)
protos/Crane.proto (3)

352-356: New ModifyFieldOperation message is consistent with client usage

The fields (ModifyField, value_list, OperationType) line up with how internal/cacctmgr/cacctmgr.go constructs operations; using a shared operation message across account/user/QoS requests looks clean and extensible.


358-363: Batched modify request/reply shapes look coherent

Switching ModifyAccountRequest, ModifyUserRequest, and ModifyQosRequest to use repeated ModifyFieldOperation operations plus changing ModifyQosReply to repeated RichError rich_error_list matches the new client logic (building multiple operations per call and iterating over rich errors). From the frontend side the shapes are internally consistent and enable clearer multi-error reporting.

Also applies to: 370-377, 384-388, 390-393


1005-1010: RPC formatting changes are cosmetic only

The reflowed rpc declarations and wrapped comments (multi-line returns (...) and banner comments) are purely stylistic and improve readability without changing wire contracts or method names.

Also applies to: 1029-1033, 1042-1045, 1051-1058, 1062-1063, 1069-1070, 1079-1081, 1090-1092, 1095-1098, 1103-1106, 1108-1113, 1120-1125, 1131-1138

internal/cacctmgr/cacctmgr.go (1)

431-470: ModifyUser: good per‑field validation and operation construction

  • Admin level values are validated early against the allowed set (none|operator|admin), which prevents bad requests.
  • ParseStringParamList followed by a single‑value check for AdminLevel, DefaultQos, and DefaultAccount correctly enforces scalar semantics where expected.
  • req.Operations is populated with ModifyField, parsed ValueList, and Type: param.RequestType, consistent with the new proto.
  • Reply handling mirrors ModifyAccount, with a single success/failure message and detailed iteration over RichErrorList, avoiding repeated messages.

No functional issues spotted; this aligns with the new batched modify design.

Also applies to: 487-500

@Nativu5 Nativu5 requested a review from huerni December 15, 2025 14:06
@Nativu5
Copy link
Collaborator

Nativu5 commented Dec 15, 2025

@huerni 帮忙看一下 cacctmgr 前后端的修改吧?

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