Skip to content

Commit

Permalink
Merge pull request #105 from zuzzas/goimports
Browse files Browse the repository at this point in the history
Ran goimports on the whole project
  • Loading branch information
bobrik authored Sep 5, 2021
2 parents 7c1da66 + c15f362 commit 10d3aa4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 46 deletions.
88 changes: 44 additions & 44 deletions decoder/cgroup.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
})
}
2 changes: 1 addition & 1 deletion decoder/inet_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion decoder/inet_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 10d3aa4

Please sign in to comment.