diff --git a/.golangci.yml b/.golangci.yml index 95a92fbb26..819f960677 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -51,6 +51,7 @@ issues: - gosec - musttag - perfsprint + - dupl - path: pkg/elfwriter linters: - dupl diff --git a/test/integration/helpers_test.go b/test/integration/helpers_test.go index f5d0eed081..4150aea82b 100644 --- a/test/integration/helpers_test.go +++ b/test/integration/helpers_test.go @@ -14,12 +14,7 @@ package integration import ( - "bufio" - "bytes" - "fmt" "sort" - "strconv" - "strings" "testing" pprofprofile "github.com/google/pprof/profile" @@ -92,76 +87,6 @@ func aggregateStacks(profile *pprofprofile.Profile) ([][]string, error) { return aggregatedStacks, nil } -type convertConfig struct { - lineNumbers, sampleTypes bool -} - -func convertToFolded(profile *pprofprofile.Profile, cfgs ...*convertConfig) (string, error) { - // Original code: https://github.com/felixge/pprofutils/blob/4ab5689918f23a12d358a09e89bd206b4e1dcb26/internal/legacy/protobuf.go - // The MIT License (MIT) - // Copyright © 2021 Felix Geisendörfer - - if len(cfgs) == 0 { - cfgs = append(cfgs, &convertConfig{}) - } - cfg := cfgs[0] - - var ( - in bytes.Buffer - out bytes.Buffer - ) - if err := profile.Write(&in); err != nil { - return "", err - } - - w := bufio.NewWriter(&out) - if cfg.sampleTypes { - var sampleTypes []string - for _, sampleType := range profile.SampleType { - sampleTypes = append(sampleTypes, sampleType.Type+"/"+sampleType.Unit) - } - w.WriteString(strings.Join(sampleTypes, " ") + "\n") - } - if err := profile.Aggregate(true, true, false, cfg.lineNumbers, false, false); err != nil { - return "", err - } - profile = profile.Compact() - sort.Slice(profile.Sample, func(i, j int) bool { - return profile.Sample[i].Value[0] > profile.Sample[j].Value[0] - }) - for _, sample := range profile.Sample { - var frames []string - for i := range sample.Location { - loc := sample.Location[len(sample.Location)-i-1] - for j := range loc.Line { - line := loc.Line[len(loc.Line)-j-1] - name := line.Function.Name - if cfg.lineNumbers { - name = name + ":" + strconv.FormatInt(line.Line, 10) - } - frames = append(frames, name) - } - } - var values []string - for _, val := range sample.Value { - values = append(values, fmt.Sprintf("%d", val)) - if !cfg.sampleTypes { - break - } - } - fmt.Fprintf( - w, - "%s %s\n", - strings.Join(frames, ";"), - strings.Join(values, " "), - ) - } - if err := w.Flush(); err != nil { - return "", err - } - return out.String(), nil -} - func TestAnyStackContains(t *testing.T) { // Edge cases. require.True(t, anyStackContains([][]string{{"a", "b"}}, []string{})) diff --git a/test/integration/integration_test.go b/test/integration/integration_test.go index d0eae23d21..89dcfb6d78 100644 --- a/test/integration/integration_test.go +++ b/test/integration/integration_test.go @@ -78,7 +78,7 @@ func (tpw *testProfileStore) Store(_ context.Context, labels model.LabelSet, pro } // sampleForProcess returns the first or last matching sample for a given PID. -func (tpw *testProfileStore) sampleForProcess(pid int, last bool) *sample { +func (tpw *testProfileStore) sampleForProcess(pid int, last bool) *sample { // nolint:unparam for i := range tpw.samples { var sample sample if last { diff --git a/test/integration/native_test.go b/test/integration/native_test.go index 6f6610a67e..3fbfafd652 100644 --- a/test/integration/native_test.go +++ b/test/integration/native_test.go @@ -12,9 +12,6 @@ // limitations under the License. // -//go:build integration -// +build integration - package integration import ( @@ -31,13 +28,14 @@ import ( "github.com/go-kit/log/level" pprofprofile "github.com/google/pprof/profile" - "github.com/parca-dev/parca-agent/pkg/logger" - "github.com/parca-dev/parca-agent/pkg/profiler/cpu" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/stretchr/testify/require" "go.uber.org/goleak" + "github.com/parca-dev/parca-agent/pkg/logger" + "github.com/parca-dev/parca-agent/pkg/profiler/cpu" + "github.com/parca-dev/parca-agent/pkg/objectfile" ) diff --git a/test/integration/python_test.go b/test/integration/python_test.go index 7db9ee9298..bf53238bc6 100644 --- a/test/integration/python_test.go +++ b/test/integration/python_test.go @@ -113,17 +113,22 @@ func TestPython(t *testing.T) { }, } for _, tt := range tests { + var ( + imageTag = tt.imageTag + program = tt.program + want = tt.want + name = tt.name + ) t.Run(tt.name, func(t *testing.T) { t.Parallel() - // Start a python container. ctx := context.Background() python, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ - Image: fmt.Sprintf("python:%s", tt.imageTag), + Image: fmt.Sprintf("python:%s", imageTag), Files: []testcontainers.ContainerFile{ { - HostFilePath: tt.program, + HostFilePath: program, ContainerFilePath: "/test.py", FileMode: 0o700, }, @@ -145,7 +150,7 @@ func TestPython(t *testing.T) { require.NoError(t, err) if !state.Running { - t.Logf("python (%s) is not running", tt.name) + t.Logf("python (%s) is not running", name) } // Start the agent. @@ -207,7 +212,7 @@ func TestPython(t *testing.T) { aggregatedStack, err := aggregateStacks(sample.profile) require.NoError(t, err) - requireAnyStackContains(t, aggregatedStack, tt.want) + requireAnyStackContains(t, aggregatedStack, want) }) } } diff --git a/test/integration/ruby_test.go b/test/integration/ruby_test.go index 3d9a4faf75..29d6aa163c 100644 --- a/test/integration/ruby_test.go +++ b/test/integration/ruby_test.go @@ -78,6 +78,12 @@ func TestRuby(t *testing.T) { }, } for _, tt := range tests { + var ( + imageTag = tt.imageTag + program = tt.program + want = tt.want + name = tt.name + ) t.Run(tt.name, func(t *testing.T) { t.Parallel() @@ -85,10 +91,10 @@ func TestRuby(t *testing.T) { ctx := context.Background() ruby, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ - Image: fmt.Sprintf("ruby:%s", tt.imageTag), + Image: fmt.Sprintf("ruby:%s", imageTag), Files: []testcontainers.ContainerFile{ { - HostFilePath: tt.program, + HostFilePath: program, ContainerFilePath: "/test.rb", FileMode: 0o700, }, @@ -110,7 +116,7 @@ func TestRuby(t *testing.T) { require.NoError(t, err) if !state.Running { - t.Logf("ruby (%s) is not running", tt.name) + t.Logf("ruby (%s) is not running", name) } // Start the agent. @@ -172,7 +178,7 @@ func TestRuby(t *testing.T) { aggregatedStack, err := aggregateStacks(sample.profile) require.NoError(t, err) - requireAnyStackContains(t, aggregatedStack, tt.want) + requireAnyStackContains(t, aggregatedStack, want) }) } }