CLI commands do not return trace ID on failure #1716

Closed
opened 2025-04-14 12:48:43 +00:00 by a-savchuk · 1 comment
Member

CLI commands don't return trace ID on failure.

Expected Behavior

Each CLI command that supports --trace flag returns trace ID on both success and failure.

Added debug output here.

$ ./frostfs-cli -c configs/s01-cli.yml object delete --cid CqW5c8srCyDrRt5rGZZr3fa2wcQQr8A1egD9WkxgQnvW --oid DykbPhMrVoafdDJFKgaPsnkxco7TEh2RKbfw3qw2H1va --trace
> start span
rpc error: remove object via client: status: code = 1024 message = incomplete object PUT by placement: could not write header: (*writer.remoteWriter) could not put single object to [/dns4/s02.frostfs.devenv/tcp/8080]: put single object via client: status: code = 1024 message = incomplete object PUT by placement: could not delete objects from tombstone locally: status: code = 2050 message = object is locked
> exit on err
> persistent post run hook is <nil>
$ ./frostfs-cli -c configs/s01-cli.yml object get --cid CqW5c8srCyDrRt5rGZZr3fa2wcQQr8A1egD9WkxgQnvW --oid DykbPhMrVoafdDJFKgaPsnkxco7TEh2RKbfw3qw2H1v --trace
> start span
rpc error: read object header: status: code = 2049 message = object not found
> exit on err
> persistent post run hook is <nil>

Current Behavior

At least two commands, object delete and object get, don't return trace ID. Didn't check other commands.

Possible Solution

I can't suggest a solution, but I think the problem is in misuse of some cobra hooks. In order to stop command span and print trace ID, we use PersistentPostRun. Here is where we call it when a command failed

if cmd.PersistentPostRun != nil {
cmd.PersistentPostRun(cmd, nil)
}


PersistentPostRun documentation says "PersistentPostRun: children of this command will inherit and execute after PostRun". I think "will inherit" doesn't mean "will contain". Here how cobra handles this hook ceb39aba25/command.go (L1028-L1042).

Steps to Reproduce (for bugs)

Run object get command on non-existing container with --trace flag.

Regression

Unlikely.

Your Environment

FrostFS CLI
Version: v0.44.0-23-gb348b202-dirty
GoVersion: go1.23.7

CLI commands don't return trace ID on failure. ## Expected Behavior Each CLI command that supports `--trace` flag returns trace ID on both success and failure. Added debug output [here](https://git.frostfs.info/TrueCloudLab/frostfs-node/src/commit/f37babdc5482334a3c573f09c7b43f43943d7dfa/cmd/internal/common/exit.go#L54-L56). ```console $ ./frostfs-cli -c configs/s01-cli.yml object delete --cid CqW5c8srCyDrRt5rGZZr3fa2wcQQr8A1egD9WkxgQnvW --oid DykbPhMrVoafdDJFKgaPsnkxco7TEh2RKbfw3qw2H1va --trace > start span rpc error: remove object via client: status: code = 1024 message = incomplete object PUT by placement: could not write header: (*writer.remoteWriter) could not put single object to [/dns4/s02.frostfs.devenv/tcp/8080]: put single object via client: status: code = 1024 message = incomplete object PUT by placement: could not delete objects from tombstone locally: status: code = 2050 message = object is locked > exit on err > persistent post run hook is <nil> ``` ```console $ ./frostfs-cli -c configs/s01-cli.yml object get --cid CqW5c8srCyDrRt5rGZZr3fa2wcQQr8A1egD9WkxgQnvW --oid DykbPhMrVoafdDJFKgaPsnkxco7TEh2RKbfw3qw2H1v --trace > start span rpc error: read object header: status: code = 2049 message = object not found > exit on err > persistent post run hook is <nil> ``` ## Current Behavior At least two commands, `object delete` and `object get`, don't return trace ID. Didn't check other commands. ## Possible Solution I can't suggest a solution, but I think the problem is in misuse of some `cobra` hooks. In order to stop command span and print trace ID, we use `PersistentPostRun`. Here is where we call it when a command failed https://git.frostfs.info/TrueCloudLab/frostfs-node/src/commit/f37babdc5482334a3c573f09c7b43f43943d7dfa/cmd/internal/common/exit.go#L54-L56 `PersistentPostRun` documentation says "PersistentPostRun: children of this command will inherit and execute after PostRun". I think "will inherit" doesn't mean "will contain". Here how `cobra` handles this hook https://github.com/spf13/cobra/blob/ceb39aba25c86233e4888210c4b57cdb0a78d1e1/command.go#L1028-L1042. ## Steps to Reproduce (for bugs) Run `object get` command on non-existing container with `--trace` flag. ## Regression Unlikely. ## Your Environment FrostFS CLI Version: v0.44.0-23-gb348b202-dirty GoVersion: go1.23.7
a-savchuk added the
bug
frostfs-cli
triage
observability
labels 2025-04-14 12:48:43 +00:00
Owner

Introduced in 5521737f0b.
Here is the timeline:

  1. In #406 we set PersistentPostRun hook for every command.
  2. In #808 we set EnableTraverseHooks = true and define PersistentPostRun once. But error cases are, of course, not tested, so the old code stops working.

Let's process post run hooks in ExitOnErr similarly to what we do in cobra -- this includes checking EnableTraverseHooks variable.

Introduced in 5521737f0b4cf5bb1ae22bfcfb3e7539617e8fd0. Here is the timeline: 1. In #406 we set `PersistentPostRun` hook for every command. 2. In #808 we set `EnableTraverseHooks = true` and define `PersistentPostRun` once. But error cases are, of course, not tested, so the old code stops working. Let's process post run hooks in `ExitOnErr` similarly to what we do in cobra -- this includes checking `EnableTraverseHooks` variable.
a-savchuk was assigned by fyrchik 2025-04-14 15:33:18 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: TrueCloudLab/frostfs-node#1716
No description provided.