diff --git a/decoder/cgroup.go b/decoder/cgroup.go index 8469130b..69076164 100644 --- a/decoder/cgroup.go +++ b/decoder/cgroup.go @@ -1,15 +1,15 @@ - package decoder +package decoder import ( - "os" - "fmt" - "log" - "strconv" - "path/filepath" + "fmt" + "log" + "os" + "path/filepath" + "strconv" - "golang.org/x/sys/unix" "github.com/cloudflare/ebpf_exporter/config" - "github.com/iovisor/gobpf/bcc" + "github.com/iovisor/gobpf/bcc" + "golang.org/x/sys/unix" ) // CGroup is a decoder that transforms cgroup id to path in cgroupfs @@ -19,54 +19,54 @@ type CGroup struct { // Decode transforms cgroup id to path in cgroupfs func (c *CGroup) Decode(in []byte, conf config.Decoder) ([]byte, error) { - if c.cache == nil { - c.cache = map[uint64][]byte{} - } + if c.cache == nil { + c.cache = map[uint64][]byte{} + } - cgroupID, err := strconv.Atoi(string(in)) - if err != nil { - return nil, err - } + cgroupID, err := strconv.Atoi(string(in)) + if err != nil { + return nil, err + } - if path, ok := c.cache[uint64(cgroupID)]; ok { - return path, nil - } + if path, ok := c.cache[uint64(cgroupID)]; ok { + return path, nil + } - if err = c.refreshCache(); err != nil { - log.Printf("Error refreshing cgroup id to path map: %s", err) - } + if err = c.refreshCache(); err != nil { + log.Printf("Error refreshing cgroup id to path map: %s", err) + } - if path, ok := c.cache[uint64(cgroupID)]; ok { - return path, nil - } + if path, ok := c.cache[uint64(cgroupID)]; ok { + return path, nil + } - return []byte(fmt.Sprintf("unknown_cgroup_id:%d", cgroupID)), nil + return []byte(fmt.Sprintf("unknown_cgroup_id:%d", cgroupID)), nil } func (c *CGroup) refreshCache() error { - byteOrder := bcc.GetHostByteOrder() + byteOrder := bcc.GetHostByteOrder() - cgroupPath := "/sys/fs/cgroup/unified" - if _, err := os.Stat(cgroupPath); os.IsNotExist(err) { - cgroupPath = "/sys/fs/cgroup" - } + cgroupPath := "/sys/fs/cgroup/unified" + if _, err := os.Stat(cgroupPath); os.IsNotExist(err) { + cgroupPath = "/sys/fs/cgroup" + } - return filepath.Walk(cgroupPath, func(path string, info os.FileInfo, err error) error { - if err != nil { - return err - } + return filepath.Walk(cgroupPath, func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } - if !info.IsDir() { - return nil - } + if !info.IsDir() { + return nil + } - handle, _, err := unix.NameToHandleAt(unix.AT_FDCWD, path, 0) - if err != nil { - log.Printf("Error resolving handle of %s: %s", path, err) - } + handle, _, err := unix.NameToHandleAt(unix.AT_FDCWD, path, 0) + if err != nil { + log.Printf("Error resolving handle of %s: %s", path, err) + } - c.cache[byteOrder.Uint64(handle.Bytes())] = []byte(path) + c.cache[byteOrder.Uint64(handle.Bytes())] = []byte(path) - return nil - }) + return nil + }) } diff --git a/decoder/inet_ip.go b/decoder/inet_ip.go index ea0d5cb0..f10f6cfe 100644 --- a/decoder/inet_ip.go +++ b/decoder/inet_ip.go @@ -11,6 +11,6 @@ type InetIP struct{} // Decode transforms an ip byte representation into a string func (i *InetIP) Decode(in []byte, conf config.Decoder) ([]byte, error) { - ip := net.IP(in); + ip := net.IP(in) return []byte(ip.String()), nil } diff --git a/decoder/inet_ip_test.go b/decoder/inet_ip_test.go index 05bbc405..85d9f2f9 100644 --- a/decoder/inet_ip_test.go +++ b/decoder/inet_ip_test.go @@ -17,7 +17,7 @@ func TestInetIpDecoder(t *testing.T) { out: []byte("1.2.3.4"), }, { - in: []byte{ + in: []byte{ 0x24, 0x00, 0xcb, 0x00, 0x00, 0x04,