Skip to content

Commit

Permalink
Update to v0.4.6 to fix debug data
Browse files Browse the repository at this point in the history
This also includes a test to make sure debug data is marshalled
correctly.
  • Loading branch information
simonswine committed Apr 26, 2024
1 parent f4129f4 commit 5bf8176
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ require (
github.com/grafana/loki/pkg/push v0.0.0-20231212100434-384e5c2dc872 // k180 branch
github.com/grafana/pyroscope-go/godeltaprof v0.1.7
github.com/grafana/pyroscope/api v0.4.0
github.com/grafana/pyroscope/ebpf v0.4.5
github.com/grafana/pyroscope/ebpf v0.4.6
github.com/grafana/regexp v0.0.0-20221123153739-15dc172cd2db
github.com/grafana/snowflake-prometheus-exporter v0.0.0-20221213150626-862cad8e9538
github.com/grafana/tail v0.0.0-20230510142333-77b18831edf0
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1072,8 +1072,10 @@ github.com/grafana/pyroscope-go/godeltaprof v0.1.7 h1:C11j63y7gymiW8VugJ9ZW0pWfx
github.com/grafana/pyroscope-go/godeltaprof v0.1.7/go.mod h1:Tk376Nbldo4Cha9RgiU7ik8WKFkNpfds98aUzS8omLE=
github.com/grafana/pyroscope/api v0.4.0 h1:J86DxoNeLOvtJhB1Cn65JMZkXe682D+RqeoIUiYc/eo=
github.com/grafana/pyroscope/api v0.4.0/go.mod h1:MFnZNeUM4RDsDOnbgKW3GWoLSBpLzMMT9nkvhHHo81o=
github.com/grafana/pyroscope/ebpf v0.4.5 h1:35WfAfCQxY4DiBzXsP5+xqhUEeO9ebgfo/VWqS4Q5Bg=
github.com/grafana/pyroscope/ebpf v0.4.5/go.mod h1:0iOWpGm2M6KXiP2nGa4wf02knSSjEtu11vpUOdQT5AY=
github.com/grafana/pyroscope/ebpf v0.4.6-0.20240426163159-8575ca65f70b h1:BXLaXB9gPvlbPeiwOkauVFvf7iaZwqS+BYCmHiAue64=
github.com/grafana/pyroscope/ebpf v0.4.6-0.20240426163159-8575ca65f70b/go.mod h1:0iOWpGm2M6KXiP2nGa4wf02knSSjEtu11vpUOdQT5AY=
github.com/grafana/pyroscope/ebpf v0.4.6 h1:8A6vddwCF2q8XXrOebFuDczr9xOHCfqPN2QwIkXKxgU=
github.com/grafana/pyroscope/ebpf v0.4.6/go.mod h1:0iOWpGm2M6KXiP2nGa4wf02knSSjEtu11vpUOdQT5AY=
github.com/grafana/regexp v0.0.0-20221123153739-15dc172cd2db h1:7aN5cccjIqCLTzedH7MZzRZt5/lsAHch6Z3L2ZGn5FA=
github.com/grafana/regexp v0.0.0-20221123153739-15dc172cd2db/go.mod h1:M5qHK+eWfAv8VR/265dIuEpL3fNfeC21tXXp9itM24A=
github.com/grafana/smimesign v0.2.1-0.20220408144937-2a5adf3481d3 h1:UPkAxuhlAcRmJT3/qd34OMTl+ZU7BLLfOO2+NXBlJpY=
Expand Down
115 changes: 109 additions & 6 deletions internal/component/pyroscope/ebpf/ebpf_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@ import (
"testing"
"time"

"github.com/grafana/alloy/internal/component"
"github.com/grafana/alloy/internal/component/discovery"
"github.com/grafana/alloy/internal/component/pyroscope"
"github.com/grafana/alloy/internal/util"
"github.com/grafana/alloy/syntax"
ebpfspy "github.com/grafana/pyroscope/ebpf"
"github.com/grafana/pyroscope/ebpf/pprof"
"github.com/grafana/pyroscope/ebpf/sd"
"github.com/grafana/pyroscope/ebpf/symtab"
"github.com/grafana/pyroscope/ebpf/symtab/elf"
"github.com/oklog/run"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/require"

"github.com/grafana/alloy/internal/component"
"github.com/grafana/alloy/internal/component/discovery"
"github.com/grafana/alloy/internal/component/pyroscope"
"github.com/grafana/alloy/internal/util"
"github.com/grafana/alloy/syntax"
)

type mockSession struct {
Expand Down Expand Up @@ -68,7 +71,36 @@ func (m *mockSession) CollectProfiles(f pprof.CollectProfilesCallback) error {
}

func (m *mockSession) DebugInfo() interface{} {
return nil
return ebpfspy.SessionDebugInfo{
ElfCache: symtab.ElfCacheDebugInfo{
BuildIDCache: symtab.GCacheDebugInfo[elf.SymTabDebugInfo]{},
SameFileCache: symtab.GCacheDebugInfo[elf.SymTabDebugInfo]{
LRUSize: 10,
RoundSize: 10,
CurrentRound: 1,
LRUDump: []elf.SymTabDebugInfo{
{
Name: "X",
Size: 123,
LastUsedRound: 1,
},
},
},
},
PidCache: symtab.GCacheDebugInfo[symtab.ProcTableDebugInfo]{
LRUSize: 10,
RoundSize: 10,
CurrentRound: 1,
LRUDump: []symtab.ProcTableDebugInfo{
{
Pid: 666,
Size: 123,
},
},
},
Arch: "my-arch",
Kernel: "my-kernel",
}
}

func TestShutdownOnError(t *testing.T) {
Expand Down Expand Up @@ -244,6 +276,77 @@ pid_map_size = 0
}
}

type mockTargetFinder struct {
sd.TargetFinder
}

func (m *mockTargetFinder) DebugInfo() []map[string]string {
return []map[string]string{
{"__container_id__": "foo", "__name__": "process_cpu", "container": "kube-proxy"},
{"__container_id__": "baz", "__name__": "process_cpu", "container": "kube-proxy"},
}
}

func TestDebugInfo(t *testing.T) {
c := &Component{
session: &mockSession{},
targetFinder: &mockTargetFinder{},
}

c.updateDebugInfo()
di := c.DebugInfo()

v, err := syntax.Marshal(di)
require.NoError(t, err)

require.Equal(t, `targets = [{
__container_id__ = "foo",
__name__ = "process_cpu",
container = "kube-proxy",
}, {
__container_id__ = "baz",
__name__ = "process_cpu",
container = "kube-proxy",
}]
session = {
elf_cache = {
build_id_cache = {
lru_size = 0,
round_size = 0,
current_round = 0,
lru_dump = [],
round_dump = [],
},
same_file_cache = {
lru_size = 10,
round_size = 10,
current_round = 1,
lru_dump = [{
name = "X",
symbol_count = 123,
file = "",
last_used_round = 1,
}],
round_dump = [],
},
},
pid_cache = {
lru_size = 10,
round_size = 10,
current_round = 1,
lru_dump = [{
elfs = {},
size = 123,
pid = 666,
last_used_round = 0,
}],
round_dump = [],
},
arch = "my-arch",
kernel = "my-kernel",
}`, string(v))
}

func newTestComponent(opts component.Options, args Arguments, session *mockSession, targetFinder sd.TargetFinder, ms *metrics) *Component {
alloyAppendable := pyroscope.NewFanout(args.ForwardTo, opts.ID, opts.Registerer)
res := &Component{
Expand Down

0 comments on commit 5bf8176

Please sign in to comment.