sensu-go icon indicating copy to clipboard operation
sensu-go copied to clipboard

[sensuctl] Per-resource CRUD action output

Open calebhailey opened this issue 5 years ago • 6 comments

Expected Behavior

sensuctl should generate output to indicate what action has been taken on a resource (if any). This output should be consistent across all sensuctl subcommands (e.g. sensuctl create -f foo.yaml and sensuctl check create foo --interactive).

NOTE: this feature is inspired by the Kubernetes kubectl CLI output (for reference).

Examples:

$ sensuctl create -f check_http.yaml
asset "nagios-plugins" created 
check "http-service-health" created 
filter "team-a" unchanged  

...or...

$ sensuctl check create helloworld --interactive
...
...
check "helloworld" modified

The output should follow a consistent syntax of <resource> "<resource_name>" <action> where valid actions are (subject to further specification): "created", "modified", "deleted", or "unchanged".

This output should be especially helpful when processing a resource definition which describes multiple resources via sensuctl create -f, in the event that an invalid resource definition is encountered, the CLI output will help inform the user which action(s) have been taken.

For example, a file named foo.yaml includes definitions for an asset resource, a check resource, and a handler resource, all named "foo" (in that order). The asset and handler definitions are valid, but the check definition is invalid. As sensuctl reads the file and processes the resource definitions sequentially, it would inform the user that the first resource (the asset) was created before encountering an error on the second resource (the check) and exiting without attempting to process the handler definition:

$ sensuctl create -f foo.yaml
asset "foo" created 
ERROR: <error information>

Current Behavior

Inconsistent output from sensuctl across the various subcommands.

Possible Solution

  • Update resource PUT APIs to support 202 Accepted and 304 Not Modified

    NOTE: the PUT APIs (e.g. CheckConfig PUT) already provide HTTP response code 201 Created, so adding 202 Accepted and 304 Not Modified would allow us to differentiate between created (201) vs updated (202) vs not updated (304).

  • Add tabular output support to sensuctl create

  • Add tabular output support to sensuctl prune

  • Add a --verbose flag to optionally output filenames? For example:

    $ sensuctl create -f check_http.yaml
    processing file "/path/to/check_http.yaml"...
    asset "nagios-plugins" created 
    check "http-service-health" created 
    filter "team-a" unchanged  
    

    This could help further troubleshoot sensuctl error messages if the file processing message was printed before attempting to read the file.

Steps to Reproduce (for bugs)

n/a

Context

It can be difficult to know what actions sensuctl is taking, especially when using sensuctl create -f with a file containing multiple resource definitions.

Your Environment

Sensu Go 5.0.0+

calebhailey avatar Jun 24 '19 10:06 calebhailey

Related: https://github.com/sensu/sensu-go/pull/3646

calebhailey avatar Apr 05 '20 05:04 calebhailey

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 02 '20 05:10 stale[bot]

It might be good to have the output optional via a flag. When applying over a larger group of resources stdout can add a bit of overhead to the speed that might not be necessary unless you are debugging or running in a CI job for example.

ninjaslothx avatar Oct 13 '20 23:10 ninjaslothx

Updated the "possible solution" section of the issue description with the following notes:

  • Update resource PUT APIs to support 202 Accepted and 304 Not Modified

    NOTE: the PUT APIs (e.g. CheckConfig PUT) already provide HTTP response code 201 Created, so adding 202 Accepted and 304 Not Modified would allow us to differentiate between created (201) vs updated (202) vs not updated (304).

  • Add tabular output support to sensuctl create

  • Add tabular output support to sensuctl prune

  • Add a --verbose flag to optionally output filenames? For example:

    $ sensuctl create -f check_http.yaml
    processing file "/path/to/check_http.yaml"...
    asset "nagios-plugins" created 
    check "http-service-health" created 
    filter "team-a" unchanged  
    

    This could help further troubleshoot sensuctl error messages if the file processing message was printed before attempting to read the file.

NOTE: separate this into two issues: API updates (list item 1), and Sensuctl updates (list items 2-4).

calebhailey avatar Nov 30 '20 22:11 calebhailey

Related: https://github.com/sensu/sensu-go/issues/3475

calebhailey avatar Dec 04 '20 17:12 calebhailey

Updates:

  • Add --continue or --skip-errors flag to attempt to continue processing resources (e.g. in a file with 10 resources, if the second resource has an error, could we try to process the third resource, etc)?
  • Add --quiet (or similar) flag for suppressing this output
  • Add --summary flag for printing out a summary of changes (e.g. "created 100 resources, updated 100 resources, 100 resource unchanged)
  • Should --quiet and --summary be the same thing?

calebhailey avatar Aug 11 '21 18:08 calebhailey