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

Render container stats and configs as yaml #444

Merged
merged 5 commits into from
May 21, 2023
Merged

Render container stats and configs as yaml #444

merged 5 commits into from
May 21, 2023

Conversation

tony-sol
Copy link
Contributor

@tony-sol tony-sol commented Apr 5, 2023

Add optional config ".gui.detailsFormat" into config file, which provides ability to change output format of container stats and config details.

To preserve current behaviour, use json as default.

Keys and their order are same between json and yaml formats.

Снимок экрана 2023-04-05 в 22 00 21

@ViktorKram
Copy link

Beast.

@tony-sol
Copy link
Contributor Author

@jesseduffield would you please take a look at this?

@jesseduffield
Copy link
Owner

Sorry for the late review,

I actually much prefer the yaml appearance to the JSON appearance. I'm happy to make it yaml without it being configurable. Could you do that @tony-sol ?

@tony-sol
Copy link
Contributor Author

@jesseduffield mm, maybe just make yaml by default, but keep this setting?
I prefer yaml over json as well (that's why i made this PR 😉), but definitely there are users who like json more.

@jesseduffield
Copy link
Owner

For rendering in a UI though, I think yaml makes way more sense. k9s for example uses yaml to display pod specs and to my knowledge doesn't offer a way of instead showing it in JSON. I reckon we just switch to yaml and make it configurable if people complain. In general I want to keep configuration to a minimum where possible as it's a maintenance burden

@tony-sol
Copy link
Contributor Author

Also, there is a way to make yaml output colorized, but it requires to add goccy/go-yaml dependency with other updates in go.mod

Should we make this or common white text is just fine?

colorizedStats colorizedConfig

@jesseduffield
Copy link
Owner

Nice, let's add that dependency, it's great for readability

@tony-sol
Copy link
Contributor Author

Should i make colors fully customizable, set some pre-configured themes or just hardcode colors?

@jesseduffield
Copy link
Owner

hardcode :)

@tony-sol
Copy link
Contributor Author

I see a point of future improvements - make themes or something, to make ui look more smooth and less like christmas tree 😄
(I'll make it as soon as get free time)

@tony-sol
Copy link
Contributor Author

So, this is how it looks like now
docker-compose_config
about
stats
config

Copy link
Owner

@jesseduffield jesseduffield left a comment

Choose a reason for hiding this comment

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

Could you add a unit test for this?

Accidentally submitted review

case "json":
return dataJSON, err
case "yaml":
// Use Unmarshal->Marshal hack to convert vendor-locked objects to YAML with same structure as JSON
Copy link
Owner

Choose a reason for hiding this comment

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

Could you explain a bit more about what's happening here? What do you mean by vendor locked?

Copy link
Contributor Author

@tony-sol tony-sol May 16, 2023

Choose a reason for hiding this comment

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

Sure, container.Details declared in vendor/github.com/docker/docker/api/types/stats.go already has json tags, but not yaml.

So, in order to keep ./vendor/ files consistent and not changed in any inappropriate way, like

-- CPUUsage CPUUsage `json:"cpu_usage"`
++ CPUUsage CPUUsage `json:"cpu_usage" yaml:"cpu_usage"`

and keep the resulting yaml structure exactly as json is, let's at first marshal into json as tagged, then into "any" yaml

Copy link
Owner

Choose a reason for hiding this comment

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

Ah, that makes sense. Could you capture that in a comment in the code?

Copy link
Owner

@jesseduffield jesseduffield left a comment

Choose a reason for hiding this comment

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

Looking great! Left a couple comments. We also need to scrap the JSON-related code

// Booleans: magenta
// Numbers: yellow
// Strings: green
func ColoredYamlString(str string) string {
Copy link
Owner

Choose a reason for hiding this comment

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

Can you add a unit test for this? (Accidentally just left this as a general comment cos I'm reviewing from phone :) )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jesseduffield sure, done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And sadly, i don't get about scrapping "the JSON-related code" :c

Copy link
Owner

Choose a reason for hiding this comment

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

What I mean is, let's remove DetailsFormat and always use yaml formatting.

@tony-sol
Copy link
Contributor Author

@jesseduffield is everything good?, are we ready for merge?:)

@jesseduffield
Copy link
Owner

@tony-sol I've left a couple more comments :)

`detailsFormat` key removed from config
`MarshalIntoFormat` renamed into `marshalIntoFormat` with better
description
`MarshalIntoYaml` introduced as `marshalIntoFormat` wrapper for common
usage
@tony-sol
Copy link
Contributor Author

@jesseduffield done 😄
I'd removed detailsFormat from config, but saved MarshalIntoFormat as private, and created a wrapper MarshalIntoYaml.
Think it's better for possible improvements in future, hope you agree 😉

@jesseduffield jesseduffield merged commit 2a9ed70 into jesseduffield:master May 21, 2023
@jesseduffield
Copy link
Owner

Think it's better for possible improvements in future, hope you agree 😉

Yep that's fine.

Merged! Great work on this @tony-sol !

@jesseduffield jesseduffield changed the title Allow to render container stats and configs both in json and yaml Render container stats and configs as yaml May 21, 2023
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.

3 participants