Skip to content

Commit 15762ad

Browse files
committed
refactor(dropwatch): rename MemcgCssAddr -> MemoryCgroupCSSAddr
Spell out the kernel jargon "memcg" so the field name carries the "cgroup" category word the way NetNamespaceCookie/Inode already carry "namespace". Apply the Go initialism rule to CSS, and align the JSON key with packet_skb_addr's _addr suffix so both kernel-pointer fields follow the same naming pattern.
1 parent 4f856c9 commit 15762ad

3 files changed

Lines changed: 49 additions & 49 deletions

File tree

cmd/dropwatch/main.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,19 @@ var (
4848

4949
// Must match struct packet_meta in bpf/dropwatch.c exactly.
5050
type packetMeta struct {
51-
KtimeNS uint64
52-
TgidPid uint64
53-
NetCookie uint64
54-
SkbAddr uint64
55-
MemcgCssAddr uint64
56-
NetdevIfindex uint32
57-
NetdevFlags uint32
58-
NetdevQueueMapping uint32
59-
DropReason uint32
60-
Type uint32
61-
NetInode uint32
62-
NetdevName [bpf.NetdevNameLen]byte
63-
Comm [bpf.TaskCommLen]byte
51+
KtimeNS uint64
52+
TgidPid uint64
53+
NetCookie uint64
54+
SkbAddr uint64
55+
MemoryCgroupCSSAddr uint64
56+
NetdevIfindex uint32
57+
NetdevFlags uint32
58+
NetdevQueueMapping uint32
59+
DropReason uint32
60+
Type uint32
61+
NetInode uint32
62+
NetdevName [bpf.NetdevNameLen]byte
63+
Comm [bpf.TaskCommLen]byte
6464
}
6565

6666
type packetRaw struct {
@@ -139,21 +139,21 @@ func formatEvent(ev *dropPacketEvent) *types.DropWatchTracing {
139139
stackStr := strings.Join(frames, "\n")
140140

141141
return &types.DropWatchTracing{
142-
ObservedTimestamp: time.Now().UTC().Format(time.RFC3339Nano),
143-
Comm: bytesutil.ToStr(ev.Meta.Comm[:]),
144-
Pid: ev.Meta.TgidPid >> 32,
145-
MemcgCssAddr: kernaddr.Format(ev.Meta.MemcgCssAddr),
146-
NetNamespaceCookie: ev.Meta.NetCookie,
147-
NetNamespaceInode: ev.Meta.NetInode,
148-
NetdevName: bytesutil.ToStr(ev.Meta.NetdevName[:]),
149-
NetdevIfindex: ev.Meta.NetdevIfindex,
150-
NetdevQueueMapping: ev.Meta.NetdevQueueMapping,
151-
NetdevLinkStatus: linkstatus.FlagsRaw(ev.Meta.NetdevFlags),
152-
PacketSkbAddr: kernaddr.Format(ev.Meta.SkbAddr),
153-
PacketEthProto: fmt.Sprintf("0x%04x", ev.Raw.EthProto),
154-
PacketLen: ev.Raw.PktLen,
155-
Layers: p,
156-
Stack: stackStr,
142+
ObservedTimestamp: time.Now().UTC().Format(time.RFC3339Nano),
143+
Comm: bytesutil.ToStr(ev.Meta.Comm[:]),
144+
Pid: ev.Meta.TgidPid >> 32,
145+
MemoryCgroupCSSAddr: kernaddr.Format(ev.Meta.MemoryCgroupCSSAddr),
146+
NetNamespaceCookie: ev.Meta.NetCookie,
147+
NetNamespaceInode: ev.Meta.NetInode,
148+
NetdevName: bytesutil.ToStr(ev.Meta.NetdevName[:]),
149+
NetdevIfindex: ev.Meta.NetdevIfindex,
150+
NetdevQueueMapping: ev.Meta.NetdevQueueMapping,
151+
NetdevLinkStatus: linkstatus.FlagsRaw(ev.Meta.NetdevFlags),
152+
PacketSkbAddr: kernaddr.Format(ev.Meta.SkbAddr),
153+
PacketEthProto: fmt.Sprintf("0x%04x", ev.Raw.EthProto),
154+
PacketLen: ev.Raw.PktLen,
155+
Layers: p,
156+
Stack: stackStr,
157157
}
158158
}
159159

core/events/dropwatch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ func handleDropwatchEvent(_ *toolstream.Session, ev *types.DropWatchTracing) err
103103

104104
func resolveContainerIDFromMeta(ev *types.DropWatchTracing) string {
105105
// 1. memcg CSS address — uniquely identifies a container.
106-
if addr, ok := kernaddr.Parse(ev.MemcgCssAddr); ok {
106+
if addr, ok := kernaddr.Parse(ev.MemoryCgroupCSSAddr); ok {
107107
ct, err := pod.ContainerByCSS(addr, pod.SubSysMemory)
108108
if err != nil {
109-
log.Debugf("dropwatch: CSS lookup %s: %v", ev.MemcgCssAddr, err)
109+
log.Debugf("dropwatch: CSS lookup %s: %v", ev.MemoryCgroupCSSAddr, err)
110110
} else if ct != nil {
111111
return ct.ID
112112
}

pkg/types/dropwatch.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,25 @@ import (
2727
// terminology and keeps the field distinct from the `Packet*` BPF-metadata
2828
// prefix family above.
2929
type DropWatchTracing struct {
30-
ObservedTimestamp string `json:"observed_timestamp"`
31-
Type string `json:"type"`
32-
DropReason string `json:"drop_reason"`
33-
Source string `json:"source,omitempty"`
34-
Comm string `json:"comm"`
35-
Pid uint64 `json:"pid"`
36-
ContainerID string `json:"container_id,omitempty"`
37-
MemcgCssAddr string `json:"memcg_css"`
38-
NetNamespaceCookie uint64 `json:"net_namespace_cookie"`
39-
NetNamespaceInode uint32 `json:"net_namespace_inode"`
40-
NetdevName string `json:"netdev_name"`
41-
NetdevIfindex uint32 `json:"netdev_ifindex"`
42-
NetdevQueueMapping uint32 `json:"netdev_queue_mapping"`
43-
NetdevLinkStatus []string `json:"netdev_linkstatus"`
44-
PacketSkbAddr string `json:"packet_skb_addr,omitempty"`
45-
PacketEthProto string `json:"packet_eth_proto"`
46-
PacketLen uint32 `json:"packet_len"`
47-
Layers *packet.Packet `json:"layers,omitempty"`
48-
Stack string `json:"stack"`
30+
ObservedTimestamp string `json:"observed_timestamp"`
31+
Type string `json:"type"`
32+
DropReason string `json:"drop_reason"`
33+
Source string `json:"source,omitempty"`
34+
Comm string `json:"comm"`
35+
Pid uint64 `json:"pid"`
36+
ContainerID string `json:"container_id,omitempty"`
37+
MemoryCgroupCSSAddr string `json:"memory_cgroup_css_addr"`
38+
NetNamespaceCookie uint64 `json:"net_namespace_cookie"`
39+
NetNamespaceInode uint32 `json:"net_namespace_inode"`
40+
NetdevName string `json:"netdev_name"`
41+
NetdevIfindex uint32 `json:"netdev_ifindex"`
42+
NetdevQueueMapping uint32 `json:"netdev_queue_mapping"`
43+
NetdevLinkStatus []string `json:"netdev_linkstatus"`
44+
PacketSkbAddr string `json:"packet_skb_addr,omitempty"`
45+
PacketEthProto string `json:"packet_eth_proto"`
46+
PacketLen uint32 `json:"packet_len"`
47+
Layers *packet.Packet `json:"layers,omitempty"`
48+
Stack string `json:"stack"`
4949
}
5050

5151
// Values for DropWatchTracing.Source.

0 commit comments

Comments
 (0)