Skip to content

Commit

Permalink
Fix linter pointed issues
Browse files Browse the repository at this point in the history
Signed-off-by: Kemal Akkoyun <[email protected]>
  • Loading branch information
kakkoyun committed Feb 13, 2024
1 parent 20b8211 commit 33e94f7
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 90 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ issues:
- gosec
- musttag
- perfsprint
- dupl
- path: pkg/elfwriter
linters:
- dupl
Expand Down
75 changes: 0 additions & 75 deletions test/integration/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@
package integration

import (
"bufio"
"bytes"
"fmt"
"sort"
"strconv"
"strings"
"testing"

pprofprofile "github.com/google/pprof/profile"
Expand Down Expand Up @@ -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 <[email protected]>

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{}))
Expand Down
2 changes: 1 addition & 1 deletion test/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 3 additions & 5 deletions test/integration/native_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
// limitations under the License.
//

//go:build integration
// +build integration

package integration

import (
Expand All @@ -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"
)

Expand Down
15 changes: 10 additions & 5 deletions test/integration/python_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand All @@ -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.
Expand Down Expand Up @@ -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)
})
}
}
14 changes: 10 additions & 4 deletions test/integration/ruby_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,23 @@ 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()

// Start a Ruby container.
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,
},
Expand All @@ -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.
Expand Down Expand Up @@ -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)
})
}
}

0 comments on commit 33e94f7

Please sign in to comment.