Skip to content

Commit

Permalink
Merge branch 'prometheus:master' into add-io-fs-stats
Browse files Browse the repository at this point in the history
  • Loading branch information
mshahzeb authored Jul 15, 2024
2 parents f193e1d + 0e0b4b1 commit fecc6d2
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- name: Install Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version: 1.22.x
- name: Install snmp_exporter/generator dependencies
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ go 1.20
require (
github.com/google/go-cmp v0.6.0
golang.org/x/sync v0.7.0
golang.org/x/sys v0.20.0
golang.org/x/sys v0.21.0
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
18 changes: 11 additions & 7 deletions proc_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ func (s *ProcStatus) fillStatus(k string, vString string, vUint uint64, vUintByt
}
}
case "NSpid":
s.NSpids = calcNSPidsList(vString)
nspids, err := calcNSPidsList(vString)
if err != nil {
return err
}
s.NSpids = nspids
case "VmPeak":
s.VmPeak = vUintBytes
case "VmSize":
Expand Down Expand Up @@ -222,17 +226,17 @@ func calcCpusAllowedList(cpuString string) []uint64 {
return g
}

func calcNSPidsList(nspidsString string) []uint64 {
s := strings.Split(nspidsString, " ")
func calcNSPidsList(nspidsString string) ([]uint64, error) {
s := strings.Split(nspidsString, "\t")
var nspids []uint64

for _, nspid := range s {
nspid, _ := strconv.ParseUint(nspid, 10, 64)
if nspid == 0 {
continue
nspid, err := strconv.ParseUint(nspid, 10, 64)
if err != nil {
return nil, err
}
nspids = append(nspids, nspid)
}

return nspids
return nspids, nil
}
16 changes: 16 additions & 0 deletions proc_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,19 @@ func TestCpusAllowedList(t *testing.T) {
t.Errorf("want CpusAllowedList %v, have %v", want, have)
}
}

func TestNsPids(t *testing.T) {
p, err := getProcFixtures(t).Proc(26235)
if err != nil {
t.Fatal(err)
}

s, err := p.NewStatus()
if err != nil {
t.Fatal(err)
}

if want, have := []uint64{26235, 1}, s.NSpids; !reflect.DeepEqual(want, have) {
t.Errorf("want NsPids %v, have %v", want, have)
}
}
8 changes: 4 additions & 4 deletions testdata/fixtures.ttar
Original file line number Diff line number Diff line change
Expand Up @@ -818,10 +818,10 @@ Uid: 0 0 0 0
Gid: 0 0 0 0
FDSize: 64
Groups:
NStgid: 26235 1
NSpid: 26235 1
NSpgid: 26235 1
NSsid: 26235 1
NStgid: 26235 1
NSpid: 26235 1
NSpgid: 26235 1
NSsid: 26235 1
VmPeak: 758200 kB
VmSize: 758200 kB
VmLck: 0 kB
Expand Down

0 comments on commit fecc6d2

Please sign in to comment.