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

pkg/gadgets/top/tcp: Align IP version field with other gadgets #2564

Merged
merged 1 commit into from
Mar 6, 2024

Conversation

blanquicet
Copy link
Member

@blanquicet blanquicet commented Mar 4, 2024

Align IP version field of top tcp with other gadgets

The top tcp gadget reports the IPVersion field as the address family AF_INET or AF_INET6. Instead, all other gadgets reporting such a field use 4 or 6 directly, which avoids further manipulation of output on CLI or third-party applications consuming the JSON. Gadgets using 4 and 6:

This change is beneficial for those folks consuming the JSON output from other applications:

Before this commit ("ipversion":2)

$ ig top tcp -o json
[{"runtime":{...},"k8s":{},"mountnsid":4026534246,"pid":19366,"comm":"kubelet","ipversion":2,"src":{"addr":"192.168.49.2","version":4,"port":39304},"dst":{"addr":"192.168.49.2","version":4,"port":8443},"sent":566,"received":2056}]

After this commit ("ipversion":4)

$ ig top tcp -o json
[{"runtime":{...},"k8s":{},"mountnsid":4026534246,"pid":19366,"comm":"kubelet","ipversion":4,"src":{"addr":"192.168.49.2","version":4,"port":35098},"dst":{"addr":"192.168.49.2","version":4,"port":8443},"sent":566,"received":2056}]

NOTE

Isn't the version inside the src and dst redundant? I think we could avoid it.

This change is particularly useful for those folks consuming the JSON
output from other applications:

Before this commit ("ipversion":2):

$ ig top tcp -o json
[{"runtime":{...},"k8s":{},"mountnsid":4026534246,"pid":19366,"comm":"kubelet","ipversion":2,"src":{"addr":"192.168.49.2","version":4,"port":39304},"dst":{"addr":"192.168.49.2","version":4,"port":8443},"sent":566,"received":2056}]

After this commit ("ipversion":4):

$ ig top tcp -o json
[{"runtime":{...},"k8s":{},"mountnsid":4026534246,"pid":19366,"comm":"kubelet","ipversion":4,"src":{"addr":"192.168.49.2","version":4,"port":35098},"dst":{"addr":"192.168.49.2","version":4,"port":8443},"sent":566,"received":2056}]

Signed-off-by: Jose Blanquicet <josebl@microsoft.com>
Copy link
Member

@flyth flyth left a comment

Choose a reason for hiding this comment

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

Thanks, makes sense to align this!

@@ -49,7 +49,7 @@ type Stats struct {

Pid int32 `json:"pid,omitempty" column:"pid,template:pid"`
Comm string `json:"comm,omitempty" column:"comm,template:comm"`
IPVersion uint16 `json:"ipversion,omitempty" column:"ip,template:ipversion"`
IPVersion int `json:"ipversion,omitempty" column:"ip,template:ipversion"`
Copy link
Member

Choose a reason for hiding this comment

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

Although we don't transmit this in binary form, yet, IMHO we should always use types with a fixed size (that aren't platform dependent) for things that can be exchanged between two different systems.

@blanquicet blanquicet merged commit 194b25b into main Mar 6, 2024
59 checks passed
@blanquicet blanquicet deleted the jose/top-tcp-ipversion branch March 6, 2024 15:10
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

2 participants