Skip to content

Commit

Permalink
Merge pull request #6 from vimeo/cleanup_pre_public-2022-08
Browse files Browse the repository at this point in the history
Cleanup pre public 2022/08/24
  • Loading branch information
dfinkel authored Dec 6, 2024
2 parents dcf6745 + 11c2b64 commit 167284a
Show file tree
Hide file tree
Showing 18 changed files with 63 additions and 39 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ jobs:
strategy:
matrix:
os: [macOS-latest, ubuntu-latest]
goversion: [1.12, 1.13]
goversion: [1.17, 1.18, 1.19]
steps:

- name: Set up Go ${{matrix.goversion}} on ${{matrix.os}}
uses: actions/setup-go@v1
uses: actions/setup-go@v3
with:
go-version: ${{matrix.goversion}}
id: go
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/staticcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: "StaticCheck"
on: ["push", "pull_request"]

jobs:
ci:
name: "staticcheck"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1
- uses: dominikh/staticcheck-action@v1.1.0
with:
version: "2022.1.3"
1 change: 1 addition & 0 deletions cgrouplimits/cgroup_darwin.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !linux
// +build !linux

package cgrouplimits
Expand Down
21 changes: 11 additions & 10 deletions cgrouplimits/cgroup_linux.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//go:build linux
// +build linux

package cgrouplimits

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"
Expand All @@ -27,16 +28,16 @@ const cgroupMemOOMControlFile = "memory.oom_control"
func GetCgroupCPULimit() (float64, error) {
cpuPath, cgroupFindErr := cgroups.GetOwnCgroupPath("cpu")
if cgroupFindErr != nil {
return -1.0, fmt.Errorf("Unable to find cgroup directory: %s", cgroupFindErr)
return -1.0, fmt.Errorf("unable to find cgroup directory: %s", cgroupFindErr)
}

quotaFilePath := filepath.Join(cpuPath, cgroupCFSQuotaFile)
quotaStr, quotaReadErr := ioutil.ReadFile(quotaFilePath)
quotaStr, quotaReadErr := os.ReadFile(quotaFilePath)
if quotaReadErr != nil {
return -1.0, fmt.Errorf("failed to read quota file %q: %s", quotaFilePath, quotaReadErr)
}
enforcePeriodFilePath := filepath.Join(cpuPath, cgroupCFSPeriodFile)
enforcePeriodStr, periodReadErr := ioutil.ReadFile(enforcePeriodFilePath)
enforcePeriodStr, periodReadErr := os.ReadFile(enforcePeriodFilePath)
if periodReadErr != nil {
return -1.0, fmt.Errorf("failed to read cfs period file %q: %s",
enforcePeriodFilePath, periodReadErr)
Expand Down Expand Up @@ -66,10 +67,10 @@ func GetCgroupCPULimit() (float64, error) {
func GetCgroupMemoryLimit() (int64, error) {
memPath, cgroupFindErr := cgroups.GetOwnCgroupPath("memory")
if cgroupFindErr != nil {
return -1, fmt.Errorf("Unable to find cgroup directory: %s", cgroupFindErr)
return -1, fmt.Errorf("unable to find cgroup directory: %s", cgroupFindErr)
}
limitFilePath := filepath.Join(memPath, cgroupMemLimitFile)
limitFileContents, limitReadErr := ioutil.ReadFile(limitFilePath)
limitFileContents, limitReadErr := os.ReadFile(limitFilePath)
if limitReadErr != nil {
return -1, fmt.Errorf("failed to read cgroup memory limit file %q: %s",
limitFilePath, limitReadErr)
Expand All @@ -87,7 +88,7 @@ func GetCgroupMemoryLimit() (int64, error) {
func GetCgroupMemoryStats() (MemoryStats, error) {
memPath, cgroupFindErr := cgroups.GetOwnCgroupPath("memory")
if cgroupFindErr != nil {
return MemoryStats{}, fmt.Errorf("Unable to find cgroup directory: %s", cgroupFindErr)
return MemoryStats{}, fmt.Errorf("unable to find cgroup directory: %s", cgroupFindErr)
}
mg := fs.MemoryGroup{}
st := cgroups.NewStats()
Expand Down Expand Up @@ -130,7 +131,7 @@ type MemCgroupOOMControl struct {
// used in portable applications.
func ReadCGroupOOMControl(memCgroupPath string) (MemCgroupOOMControl, error) {
oomControlPath := filepath.Join(memCgroupPath, cgroupMemOOMControlFile)
oomControlBytes, oomControlReadErr := ioutil.ReadFile(oomControlPath)
oomControlBytes, oomControlReadErr := os.ReadFile(oomControlPath)
if oomControlReadErr != nil {
return MemCgroupOOMControl{}, fmt.Errorf(
"failed to read contents of %q: %s",
Expand Down Expand Up @@ -168,12 +169,12 @@ func getCgroupOOMs(memCgroupPath string) (int32, error) {
func GetCgroupCPUStats() (CPUStats, error) {
cpuPath, cgroupFindErr := cgroups.GetOwnCgroupPath("cpu")
if cgroupFindErr != nil {
return CPUStats{}, fmt.Errorf("Unable to find cgroup directory: %s",
return CPUStats{}, fmt.Errorf("unable to find cgroup directory: %s",
cgroupFindErr)
}
cpuAcctPath, cgroupFindErr := cgroups.GetOwnCgroupPath("cpuacct")
if cgroupFindErr != nil {
return CPUStats{}, fmt.Errorf("Unable to find cgroup directory: %s",
return CPUStats{}, fmt.Errorf("unable to find cgroup directory: %s",
cgroupFindErr)
}
cg := fs.CpuGroup{}
Expand Down
7 changes: 4 additions & 3 deletions cgrouplimits/host_linux.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
//go:build linux
// +build linux

package cgrouplimits

import (
"fmt"
"io/ioutil"
"os"

"github.com/vimeo/procstats/pparser"
)

func getMemInfo() (hostMemInfo, error) {
const procMemInfo = "/proc/meminfo"
memInfoBytes, procReadErr := ioutil.ReadFile(procMemInfo)
memInfoBytes, procReadErr := os.ReadFile(procMemInfo)
if procReadErr != nil {
return hostMemInfo{}, fmt.Errorf(
"failed to read contents of %q: %s",
Expand All @@ -30,7 +31,7 @@ func getMemInfo() (hostMemInfo, error) {
func getVMStat() (hostVMStat, error) {

const procVMStat = "/proc/vmstat"
vmStatBytes, procReadErr := ioutil.ReadFile(procVMStat)
vmStatBytes, procReadErr := os.ReadFile(procVMStat)
if procReadErr != nil {
return hostVMStat{}, fmt.Errorf(
"failed to read contents of %q: %s",
Expand Down
1 change: 1 addition & 0 deletions cgrouplimits/host_linux_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build linux
// +build linux

package cgrouplimits
Expand Down
1 change: 1 addition & 0 deletions cgrouplimits/host_null.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !linux
// +build !linux

package cgrouplimits
Expand Down
10 changes: 7 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
module github.com/vimeo/procstats

go 1.13
go 1.18

require (
github.com/docker/go-units v0.4.0 // indirect
github.com/opencontainers/runc v1.0.0-rc9
golang.org/x/sys v0.0.0-20220823224334-20c2bfdbfe24
)

require (
github.com/docker/go-units v0.4.0 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.1 // indirect
github.com/opencontainers/runtime-spec v1.0.1 // indirect
github.com/pkg/errors v0.8.1 // indirect
github.com/sirupsen/logrus v1.4.2 // indirect
github.com/stretchr/testify v1.4.0 // indirect
golang.org/x/sys v0.0.0-20191218084908-4a24b4065292
)
5 changes: 2 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191218084908-4a24b4065292 h1:Y8q0zsdcgAd+JU8VUA8p8Qv2YhuY9zevDG2ORt5qBUI=
golang.org/x/sys v0.0.0-20191218084908-4a24b4065292/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
golang.org/x/sys v0.0.0-20220823224334-20c2bfdbfe24 h1:TyKJRhyo17yWxOMCTHKWrc5rddHORMlnZ/j57umaUd8=
golang.org/x/sys v0.0.0-20220823224334-20c2bfdbfe24/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
7 changes: 4 additions & 3 deletions proc_pid_status_linux.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//go:build linux
// +build linux

package procstats

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"

Expand Down Expand Up @@ -80,7 +81,7 @@ var procPidStatusParser = pparser.NewLineKVFileParser(ProcPidStatus{}, ":")
// (ProcessCPUTime, MaxRSS, and RSS) rather than the low-level.
func ReadProcStatus(pid int) (*ProcPidStatus, error) {
statusPath := filepath.Join("/proc", strconv.Itoa(pid), "status")
contents, err := ioutil.ReadFile(statusPath)
contents, err := os.ReadFile(statusPath)
if err != nil {
return nil, fmt.Errorf("failed to read file %q: %s",
statusPath, err)
Expand Down Expand Up @@ -117,5 +118,5 @@ func resetMaxRSS(pid int) error {
// current resident set size value.

// As such, write the value "5" to /proc/$PID/clear_refs to reset the VmHWM value.
return ioutil.WriteFile(refsPath, []byte{'5'}, 0)
return os.WriteFile(refsPath, []byte{'5'}, 0)
}
4 changes: 2 additions & 2 deletions proc_stats_bsd.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// +build freebsd
// +build cgo
//go:build freebsd && cgo
// +build freebsd,cgo

package procstats

Expand Down
4 changes: 2 additions & 2 deletions proc_stats_darwin.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// +build darwin
// +build cgo
//go:build darwin && cgo
// +build darwin,cgo

package procstats

Expand Down
8 changes: 4 additions & 4 deletions proc_stats_linux.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//go:build linux
// +build linux

package procstats

import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
Expand All @@ -15,7 +15,7 @@ import (

func init() {
const self = "/proc/self/stat"
b, err := ioutil.ReadFile(self)
b, err := os.ReadFile(self)
if err != nil {
panic(fmt.Sprintf("unexpected kernel shenanigans: %v", err))
}
Expand All @@ -33,7 +33,7 @@ func init() {
var ct *CPUTime
for i := 0; i < 30 || (*ct == CPUTime{}); i++ {
<-t.C
b, err := ioutil.ReadFile(self)
b, err := os.ReadFile(self)
if err != nil {
panic(fmt.Sprintf("unexpected kernel shenanigans: %v", err))
}
Expand All @@ -52,7 +52,7 @@ func procFileName(pid int, leafName string) string {

func procFileContents(pid int, leafName string) ([]byte, error) {
fn := procFileName(pid, leafName)
contents, err := ioutil.ReadFile(fn)
contents, err := os.ReadFile(fn)
if err != nil {
return nil, fmt.Errorf("failed to read %s with error: %s", leafName, err)
}
Expand Down
1 change: 1 addition & 0 deletions proc_stats_null.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !linux && !cgo
// +build !linux,!cgo

package procstats
Expand Down
2 changes: 1 addition & 1 deletion pstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

// ErrUnimplementedPlatform indicates that this request is not implemented for
// this specific platform.
var ErrUnimplementedPlatform = errors.New("Unimplemented for this platform")
var ErrUnimplementedPlatform = errors.New("unimplemented for this platform")

// RSS takes a pid and returns the RSS of that process (or an error)
// This may return ErrUnimplementedPlatform on non-linux and non-darwin platforms.
Expand Down
4 changes: 2 additions & 2 deletions sysconf_darwin_cgo.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// +build darwin
// +build cgo
//go:build darwin && cgo
// +build darwin,cgo

package procstats

Expand Down
4 changes: 2 additions & 2 deletions sysconf_linux_cgo.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// +build linux
// +build cgo
//go:build linux && cgo
// +build linux,cgo

package procstats

Expand Down
4 changes: 2 additions & 2 deletions sysconf_linux_nocgo.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// +build linux
// +build !cgo
//go:build linux && !cgo
// +build linux,!cgo

package procstats

Expand Down

0 comments on commit 167284a

Please sign in to comment.