Skip to content

Commit be05a2b

Browse files
ovalentimdafsanhossainMolter73
authored
Backport PowerVM+shfmt+gperf fixes on 3.21 (4.7) (#2069)
Co-authored-by: Afsan Hossain <[email protected]> Co-authored-by: Mauro Ezequiel Moltrasio <[email protected]>
1 parent b6e5b91 commit be05a2b

File tree

7 files changed

+33
-15
lines changed

7 files changed

+33
-15
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131

3232
- name: Install shfmt
3333
run: |
34-
GOBIN="${HOME}/bin/" go install mvdan.cc/sh/v3/cmd/shfmt@latest
34+
GOBIN="${HOME}/bin/" go install mvdan.cc/sh/v3/cmd/shfmt@v3.10.0
3535
3636
- name: Install actionlint
3737
run: |

ansible/requirements.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ collections:
44
- community.general
55
- community.docker
66
- containers.podman
7-
- ibm.cloudcollection
87
- kubernetes.core
8+
- name: ibm.cloudcollection
9+
version: 1.51.0

collector/lib/ProfilerHandler.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313

1414
namespace collector {
1515

16-
const std::string ProfilerHandler::kCPUProfileFilename = "/module/cpu_profile";
16+
// The following route is used by the CPU profiler to dump information
17+
// into. When running in read only file systems, /var/profiles needs to
18+
// be writable, or the CPU profiler will not work.
19+
const std::string ProfilerHandler::kCPUProfileFilename = "/var/profiles/cpu_profile";
1720
const std::string ProfilerHandler::kBaseRoute = "/profile";
1821
const std::string ProfilerHandler::kCPURoute = kBaseRoute + "/cpu";
1922
const std::string ProfilerHandler::kHeapRoute = kBaseRoute + "/heap";

docs/troubleshooting.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,15 @@ $ curl collector:8080/profile/heap
453453
The resulting profile could be processed with `pprof` to get a human-readable
454454
output with debugging symbols.
455455

456+
Collector also exposes a CPU profiler under `/profile/cpu`, which operates in
457+
a very similar manner to the heap profiler.
458+
459+
---
460+
**_NOTE_**: If the CPU profiler fails to start, make sure /var/profiles exists
461+
in the collector container and is writable.
462+
463+
---
464+
456465
## Benchmark CI step
457466

458467
Whenever in doubt about performance implications of your changes, there is an

integration-tests/integration_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/stretchr/testify/suite"
88

99
"github.com/stackrox/collector/integration-tests/pkg/collector"
10+
"github.com/stackrox/collector/integration-tests/pkg/common"
1011
"github.com/stackrox/collector/integration-tests/pkg/config"
1112
"github.com/stackrox/collector/integration-tests/pkg/types"
1213
"github.com/stackrox/collector/integration-tests/suites"
@@ -516,6 +517,9 @@ func TestPerfEvent(t *testing.T) {
516517
}
517518

518519
func TestGperftools(t *testing.T) {
520+
if ok, arch := common.ArchSupported("x86_64"); !ok {
521+
t.Skip("[WARNING]: skip GperftoolsTestSuite on ", arch)
522+
}
519523
suite.Run(t, new(suites.GperftoolsTestSuite))
520524
}
521525

integration-tests/pkg/collector/collector_docker.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func NewDockerCollectorManager(e executor.Executor, name string) *DockerCollecto
4242
"/host/usr/lib:ro": "/usr/lib",
4343
"/host/sys/kernel/debug:ro": "/sys/kernel/debug",
4444
"/etc/stackrox:ro": "/tmp/collector-test",
45+
"/var/profiles": "", // gperftools dump directory
4546
}
4647

4748
return &DockerCollectorManager{

integration-tests/suites/gperftools.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package suites
22

33
import (
4+
"fmt"
45
"net/http"
56
"strings"
67
"time"
@@ -36,30 +37,29 @@ func (s *GperftoolsTestSuite) TearDownSuite() {
3637
// NOTE: The test will only be performed on supported architectures (only
3738
// x86_64 at the moment).
3839
func (s *GperftoolsTestSuite) TestFetchHeapProfile() {
39-
if ok, arch := common.ArchSupported("x86_64"); !ok {
40-
s.T().Skip("[WARNING]: skip GperftoolsTestSuite on ", arch)
41-
}
40+
s.runProfilerTest("heap")
41+
}
4242

43-
var (
44-
response *http.Response
45-
err error
46-
)
43+
func (s *GperftoolsTestSuite) TestFetchCpuProfile() {
44+
s.runProfilerTest("cpu")
45+
}
4746

48-
heap_api_url := "http://localhost:8080/profile/heap"
47+
func (s *GperftoolsTestSuite) runProfilerTest(resource string) {
48+
heap_api_url := fmt.Sprintf("http://localhost:8080/profile/%s", resource)
4949
data_type := "application/x-www-form-urlencoded"
5050

51-
response, err = http.Post(heap_api_url, data_type, strings.NewReader("on"))
51+
response, err := http.Post(heap_api_url, data_type, strings.NewReader("on"))
5252
s.Require().NoError(err)
53-
s.Assert().Equal(response.StatusCode, 200, "Failed to start heap profiling")
53+
s.Assert().Equalf(response.StatusCode, 200, "Failed to start %s profiling", resource)
5454

5555
// Wait a bit to collect something in the heap profile
5656
common.Sleep(1 * time.Second)
5757

5858
response, err = http.Post(heap_api_url, data_type, strings.NewReader("off"))
5959
s.Require().NoError(err)
60-
s.Assert().Equal(response.StatusCode, 200, "Failed to stop heap profiling")
60+
s.Assert().Equalf(response.StatusCode, 200, "Failed to stop %s profiling", resource)
6161

6262
response, err = http.Get(heap_api_url)
6363
s.Require().NoError(err)
64-
s.Assert().Equal(response.StatusCode, 200, "Failed to fetch heap profile")
64+
s.Assert().Equalf(response.StatusCode, 200, "Failed to fetch %s profile", resource)
6565
}

0 commit comments

Comments
 (0)