Skip to content

Commit fecc6d2

Browse files
author
Muhammad Shahzeb
authored
Merge branch 'prometheus:master' into add-io-fs-stats
2 parents f193e1d + 0e0b4b1 commit fecc6d2

File tree

6 files changed

+35
-15
lines changed

6 files changed

+35
-15
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- name: Checkout repository
2727
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
2828
- name: Install Go
29-
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
29+
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
3030
with:
3131
go-version: 1.22.x
3232
- name: Install snmp_exporter/generator dependencies

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ go 1.20
55
require (
66
github.com/google/go-cmp v0.6.0
77
golang.org/x/sync v0.7.0
8-
golang.org/x/sys v0.20.0
8+
golang.org/x/sys v0.21.0
99
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
22
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
33
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
44
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
5-
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
6-
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
5+
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
6+
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=

proc_status.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ func (s *ProcStatus) fillStatus(k string, vString string, vUint uint64, vUintByt
146146
}
147147
}
148148
case "NSpid":
149-
s.NSpids = calcNSPidsList(vString)
149+
nspids, err := calcNSPidsList(vString)
150+
if err != nil {
151+
return err
152+
}
153+
s.NSpids = nspids
150154
case "VmPeak":
151155
s.VmPeak = vUintBytes
152156
case "VmSize":
@@ -222,17 +226,17 @@ func calcCpusAllowedList(cpuString string) []uint64 {
222226
return g
223227
}
224228

225-
func calcNSPidsList(nspidsString string) []uint64 {
226-
s := strings.Split(nspidsString, " ")
229+
func calcNSPidsList(nspidsString string) ([]uint64, error) {
230+
s := strings.Split(nspidsString, "\t")
227231
var nspids []uint64
228232

229233
for _, nspid := range s {
230-
nspid, _ := strconv.ParseUint(nspid, 10, 64)
231-
if nspid == 0 {
232-
continue
234+
nspid, err := strconv.ParseUint(nspid, 10, 64)
235+
if err != nil {
236+
return nil, err
233237
}
234238
nspids = append(nspids, nspid)
235239
}
236240

237-
return nspids
241+
return nspids, nil
238242
}

proc_status_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,19 @@ func TestCpusAllowedList(t *testing.T) {
139139
t.Errorf("want CpusAllowedList %v, have %v", want, have)
140140
}
141141
}
142+
143+
func TestNsPids(t *testing.T) {
144+
p, err := getProcFixtures(t).Proc(26235)
145+
if err != nil {
146+
t.Fatal(err)
147+
}
148+
149+
s, err := p.NewStatus()
150+
if err != nil {
151+
t.Fatal(err)
152+
}
153+
154+
if want, have := []uint64{26235, 1}, s.NSpids; !reflect.DeepEqual(want, have) {
155+
t.Errorf("want NsPids %v, have %v", want, have)
156+
}
157+
}

testdata/fixtures.ttar

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -818,10 +818,10 @@ Uid: 0 0 0 0
818818
Gid: 0 0 0 0
819819
FDSize: 64
820820
Groups:
821-
NStgid: 26235 1
822-
NSpid: 26235 1
823-
NSpgid: 26235 1
824-
NSsid: 26235 1
821+
NStgid: 26235 1
822+
NSpid: 26235 1
823+
NSpgid: 26235 1
824+
NSsid: 26235 1
825825
VmPeak: 758200 kB
826826
VmSize: 758200 kB
827827
VmLck: 0 kB

0 commit comments

Comments
 (0)