Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: Add JSON and Pretty Print formatting for consul snapshot inspect #9006

Merged
merged 6 commits into from
Oct 29, 2020

Conversation

schristoff
Copy link
Contributor

@schristoff schristoff commented Oct 21, 2020

Previous functionality still available unchanged:

consul snapshot inspect backup.snap
 ID           2-13-1603221729747
 Size         5141
 Index        13
 Term         2
 Version      1

 Type                        Count      Size
 ----                        ----       ----
 Register                    3          1.7KB
 ConnectCA                   1          1.2KB
 ConnectCAProviderState      1          1.1KB
 Index                       12         344B
 Autopilot                   1          199B
 ConnectCAConfig             1          197B
 FederationState             1          139B
 SystemMetadata              1          68B
 ChunkingState               1          12B
 ----                        ----       ----
 Total                                  5KB

However the addition of JSON output with specified flag is available:

$ consul snapshot inspect -format=json backup.snap
{
   "Meta": {
      "ID": "2-13-1603221729747",
      "Size": 5141,
      "Index": 13,
      "Term": 2,
      "Version": 1
   },
   "Stats": {
      "0": {
         "Name": "Register",
         "Sum": 1750,
         "Count": 3
      },
      "13": {
         "Name": "ConnectCA",
         "Sum": 1258,
         "Count": 1
      },
      "14": {
         "Name": "ConnectCAProviderState",
         "Sum": 1174,
         "Count": 1
      },
      "15": {
         "Name": "ConnectCAConfig",
         "Sum": 197,
         "Count": 1
      },
      "16": {
         "Name": "Index",
         "Sum": 344,
         "Count": 12
      },
      "29": {
         "Name": "ChunkingState",
         "Sum": 12,
         "Count": 1
      },
      "30": {
         "Name": "FederationState",
         "Sum": 139,
         "Count": 1
      },
      "31": {
         "Name": "SystemMetadata",
         "Sum": 68,
         "Count": 1
      },
      "9": {
         "Name": "Autopilot",
         "Sum": 199,
         "Count": 1
      }
   },
   "Offset": 5141
}

@schristoff schristoff changed the title Add JSON and Pretty Print formatting for consul snapshot inspect cli: Add JSON and Pretty Print formatting for consul snapshot inspect Oct 22, 2020
Copy link
Member

@mkeeler mkeeler left a comment

Choose a reason for hiding this comment

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

The code looks great. I just have the one question about the JSON formats structure.

// through the formatter
type OutputFormat struct {
Meta *MetadataInfo
Stats map[structs.MessageType]typeStats
Copy link
Member

Choose a reason for hiding this comment

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

I wonder whether this field should be Stats []typeStats. In the pretty output I see that you are creating a slice of these and then sorting. For the JSON output I wonder whether it would be better to see:

"Stats": [
   {
      "Name": "Register",
      "Count": 20,
      "Sum": 1537,
   }
]

Having the MessageType (int) as a map key in JSON doesn't seem that useful. Also having it in an array would more easily allow us to aggregate stats for namespaces without having the map keys conflict.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I didn't even notice that, good catch.

Copy link
Member

@mkeeler mkeeler left a comment

Choose a reason for hiding this comment

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

:shipit:

@schristoff schristoff merged commit 79ce24e into master Oct 29, 2020
@schristoff schristoff deleted the consul_snappyshot_with_json branch October 29, 2020 16:31
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.

None yet

3 participants