Project

General

Profile

Actions

Bug #63692

closed

mgr/nfs: return tuple convention not being followed in case of a failure

Added by Dhairya Parmar 6 months ago. Updated 4 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Correctness/Safety
Target version:
-
% Done:

0%

Source:
Development
Tags:
Backport:
Regression:
No
Severity:
3 - minor
Reviewed:
Affected Versions:
ceph-qa-suite:
Component(FS):
mgr/nfs
Labels (FS):
NFS-cluster
Pull request ID:
Crash signature (v1):
Crash signature (v2):

Description

This came to the light while discussing [0] with venky where we saw that the tuple returned by the Responder decorator (used for the NFS CLI commands) is in format `retval, body, statusval` while the mgr module convention for returning failure tuple is `self.errno, "", self.error_str` (present in `pybind/mgr/mgr_util.py`').

This never became an issue because the `ActivePyModule::handle_command` in mgr cpp code just accepts the second and third arg are string, the result from handle_command() is passed on to the pybind/mgr/mgr_module.py:

class HandleCommandResult(NamedTuple):
    """ 
    Tuple containing the result of `handle_command()`

    Only write to stderr if there is an error, or in extraordinary circumstances

    Avoid having `ceph foo bar` commands say "did foo bar" on success unless there
    is critical information to include there.

    Everything programmatically consumable should be put on stdout
    """ 
    retval: int = 0             # return code. E.g. 0 or -errno.EINVAL
    stdout: str = ""            # data of this result.
    stderr: str = ""            # Typically used for error messages.

When it comes to following the convention, the comment states that anything trivial like "xyz success" must be avoided and only something of value should be put on stdout but for the nfs commands like `ceph nfs export apply -i` we do send out a json response for success:

[
  {
    "pseudo": "/ceph",
    "state": "added" 
  },
  {
    "pseudo": "/ceph1",
    "state": "added" 
  }
]

so it seems we've already been violating the convention at places.

[0] https://github.com/ceph/ceph/pull/53431


Related issues 2 (1 open1 closed)

Blocks mgr - Backport #63690: quincy: mgr/(object_format && nfs/export): enhance nfs export update failure responseRejectedDhairya ParmarActions
Blocks mgr - Backport #63691: reef: mgr/(object_format && nfs/export): enhance nfs export update failure responseIn ProgressDhairya ParmarActions
Actions #1

Updated by Dhairya Parmar 6 months ago

  • Description updated (diff)
  • Category set to Correctness/Safety
  • Source set to Development
  • Component(FS) mgr/nfs added
  • Labels (FS) NFS-cluster added
Actions #2

Updated by Dhairya Parmar 6 months ago

  • Related to Backport #63690: quincy: mgr/(object_format && nfs/export): enhance nfs export update failure response added
Actions #3

Updated by Dhairya Parmar 6 months ago

  • Related to deleted (Backport #63690: quincy: mgr/(object_format && nfs/export): enhance nfs export update failure response)
Actions #4

Updated by Dhairya Parmar 6 months ago

  • Blocks Backport #63690: quincy: mgr/(object_format && nfs/export): enhance nfs export update failure response added
Actions #5

Updated by Dhairya Parmar 6 months ago

  • Blocked by Backport #63691: reef: mgr/(object_format && nfs/export): enhance nfs export update failure response added
Actions #6

Updated by Dhairya Parmar 6 months ago

  • Blocked by deleted (Backport #63691: reef: mgr/(object_format && nfs/export): enhance nfs export update failure response)
Actions #7

Updated by Dhairya Parmar 6 months ago

  • Blocks Backport #63691: reef: mgr/(object_format && nfs/export): enhance nfs export update failure response added
Actions #8

Updated by Venky Shankar 5 months ago

(Sorry for the late update)

This was discussed in cephfs standup. mgr/nfs returns data in both stdout and stderr (say, when trying up update multiple exports and some of exports fail to update). The data returned in stderr is a string while the one in stdout is a JSON. While this is not totally incorrect and ceph-mgr cpp handles this, the question is should mgr/nfs stick to the convention of either retuning stdout or stderr.

Leonid mentioned that its not totally incorrect to use both, but in mgr/nfs case, the stdout is a JSON carrying information for the failed exports and stderr being a string giving some more details about the exports.

Actions #9

Updated by Leonid Usov 5 months ago

I don't see any issue with the example stdout response for a successful operation - or any operation status, for that matter. The JSON's contents are irrelevant to this discussion, as long as it's a well-formed JSON following the documented schema.

I want to challenge the part of the comment where it requests that stderr output should be kept minimal and only used for error cases. It could be a good rule of thumb for default command output, but commands may include a verbosity control, in which case the user would expect arbitrarily more output. This additional output is usually expected on stderr to not interfere with the command's documented result format that is to be consumed via the stdout.

Hence, while I completely agree with the statement that "Everything programmatically consumable should be put on stdout", I'd be fine with some affirmative messages on stderr for a successful operation, though I'd prefer if I could control the verbosity, which could be in the form of a --quite mode to suppress this output if it's there by default.

As for having 'state': "added" as part of the json object returned on the stdout, IMO it's not violating the general cli contract. It is a question to the designers of the specific command and this command's intended usage scenario.

Actions #10

Updated by Dhairya Parmar 5 months ago

Venky Shankar wrote:

(Sorry for the late update)

This was discussed in cephfs standup. mgr/nfs returns data in both stdout and stderr (say, when trying up update multiple exports and some of exports fail to update). The data returned in stderr is a string while the one in stdout is a JSON. While this is not totally incorrect and ceph-mgr cpp handles this, the question is should mgr/nfs stick to the convention of either retuning stdout or stderr.

Leonid mentioned that its not totally incorrect to use both, but in mgr/nfs case, the stdout is a JSON carrying information for the failed exports and stderr being a string giving some more details about the exports.

How about segregating export (creation/update) failure and successes and feeding the data accordingly to stdout and stderr?

Actions #11

Updated by Dhairya Parmar 5 months ago

Venky Shankar wrote:

(Sorry for the late update)

This was discussed in cephfs standup. mgr/nfs returns data in both stdout and stderr (say, when trying up update multiple exports and some of exports fail to update). The data returned in stderr is a string while the one in stdout is a JSON. While this is not totally incorrect and ceph-mgr cpp handles this, the question is should mgr/nfs stick to the convention of either retuning stdout or stderr.

If we are to follow this convention then IMO even a single export creation/update failure should be treated as failure as whole; that means the success data would also land up in stderr(this might look a bit weird but my rationale here is that we must prioritise failures first since it is the programmatically consumable and non-trivial bit of information rather than a JSON entry saying "state" : "added")

Actions #12

Updated by Venky Shankar 5 months ago

Leonid Usov wrote:

I don't see any issue with the example stdout response for a successful operation - or any operation status, for that matter. The JSON's contents are irrelevant to this discussion, as long as it's a well-formed JSON following the documented schema.

I want to challenge the part of the comment where it requests that stderr output should be kept minimal and only used for error cases. It could be a good rule of thumb for default command output, but commands may include a verbosity control, in which case the user would expect arbitrarily more output. This additional output is usually expected on stderr to not interfere with the command's documented result format that is to be consumed via the stdout.

Agree that tools that have verbose switch should dump information strings to stderr, these cli commands are kind of an query interface that's wired up in ceph-mgr and I can only guess the limitation arises from somewhere around that (although one can dump loads of (json) string to stdout, so why not for stderr).

Hence, while I completely agree with the statement that "Everything programmatically consumable should be put on stdout", I'd be fine with some affirmative messages on stderr for a successful operation, though I'd prefer if I could control the verbosity, which could be in the form of a --quite mode to suppress this output if it's there by default.

As for having 'state': "added" as part of the json object returned on the stdout, IMO it's not violating the general cli contract. It is a question to the designers of the specific command and this command's intended usage scenario.

That's likely a best programming practice and (kind of) rule to not have commands tell what they did.

As far as this tracker is concerned, it looks like there isn't any violation of contract. So, I'm fine with closing this unless there is more to discuss.

Actions #13

Updated by Venky Shankar 5 months ago

  • Status changed from New to Need More Info
Actions #14

Updated by Venky Shankar 4 months ago

  • Status changed from Need More Info to Closed
Actions

Also available in: Atom PDF