From bd111272c49f64328de3a1a89e142f778d269236 Mon Sep 17 00:00:00 2001 From: prombot Date: Tue, 4 Jun 2024 17:48:02 +0000 Subject: [PATCH 1/3] Update common Prometheus files Signed-off-by: prombot --- .github/workflows/golangci-lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 5ceb5909..8de7af63 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -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 From e416d6dbc784c46140d50cfe49b7cc4aa8867d06 Mon Sep 17 00:00:00 2001 From: Timur Alperovich Date: Mon, 17 Jun 2024 10:55:08 -0700 Subject: [PATCH 2/3] Fix parsing NSpids field in /proc/{PID}/status The NSpids field uses a tab (\t) to separate the list of PIDs. The procfs parser should split on \t, rather than space. This was not caught because the test fixtures themselves used the space character. The patch updates the parser, the fixtures, and adds an explicit test for NSpids. Signed-off-by: Timur Alperovich --- proc_status.go | 18 +++++++++++------- proc_status_test.go | 16 ++++++++++++++++ testdata/fixtures.ttar | 8 ++++---- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/proc_status.go b/proc_status.go index a055197c..dd8aa568 100644 --- a/proc_status.go +++ b/proc_status.go @@ -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": @@ -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 } diff --git a/proc_status_test.go b/proc_status_test.go index 9644bf01..e41d36ba 100644 --- a/proc_status_test.go +++ b/proc_status_test.go @@ -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) + } +} diff --git a/testdata/fixtures.ttar b/testdata/fixtures.ttar index 4bc508b8..f2bd5e56 100644 --- a/testdata/fixtures.ttar +++ b/testdata/fixtures.ttar @@ -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 From 0e0b4b16e172f6c40f789a4d43c2f51495a45e22 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Jul 2024 20:58:52 +0000 Subject: [PATCH 3/3] Bump golang.org/x/sys from 0.20.0 to 0.21.0 Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.20.0 to 0.21.0. - [Commits](https://github.com/golang/sys/compare/v0.20.0...v0.21.0) --- updated-dependencies: - dependency-name: golang.org/x/sys dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 6e9fd6f7..8b7c4f47 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index cc15e2fb..535a646e 100644 --- a/go.sum +++ b/go.sum @@ -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=