Skip to content

Commit

Permalink
Allow pid maps to be configured
Browse files Browse the repository at this point in the history
This also modifieds the way we do defaulting and valides those two new
fields.
  • Loading branch information
simonswine committed Apr 26, 2024
1 parent 7aea726 commit 655784f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
2 changes: 2 additions & 0 deletions docs/sources/reference/components/pyroscope.ebpf.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ Name | Type | Description
`collect_kernel_profile` | `bool` | A flag to enable/disable collection of kernelspace profiles | true | no
`demangle` | `string` | C++ demangle mode. Available options are: `none`, `simplified`, `templates`, `full` | `none` | no
`python_enabled` | `bool` | A flag to enable/disable python profiling | true | no
`symbols_map_size` | `int` | The size of eBPF symbols map | 16384 | no
`pid_map_size` | `int` | The size of eBPF PID map | 2048 | no

## Exported fields

Expand Down
15 changes: 15 additions & 0 deletions internal/component/pyroscope/ebpf/args.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ebpf

import (
"errors"
"time"

"github.com/grafana/alloy/internal/component/discovery"
Expand All @@ -21,4 +22,18 @@ type Arguments struct {
CollectKernelProfile bool `alloy:"collect_kernel_profile,attr,optional"`
Demangle string `alloy:"demangle,attr,optional"`
PythonEnabled bool `alloy:"python_enabled,attr,optional"`
SymbolsMapSize int `alloy:"symbols_map_size,attr,optional"`
PIDMapSize int `alloy:"pid_map_size,attr,optional"`
}

// Validate implements syntax.Validator.
func (arg *Arguments) Validate() error {
var errs []error
if arg.SymbolsMapSize <= 0 {
errs = append(errs, errors.New("symbols_map_size must be greater than 0"))
}
if arg.PIDMapSize <= 0 {
errs = append(errs, errors.New("pid_map_size must be greater than 0"))
}
return errors.Join(errs...)
}
20 changes: 14 additions & 6 deletions internal/component/pyroscope/ebpf/ebpf_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,10 @@ func New(opts component.Options, args Arguments) (component.Component, error) {
return res, nil
}

func (rc *Arguments) UnmarshalAlloy(f func(interface{}) error) error {
*rc = defaultArguments()
type config Arguments
return f((*config)(rc))
}
var DefaultArguments = NewDefaultArguments()

func defaultArguments() Arguments {
// NewDefaultArguments create the default settings for a scrape job.
func NewDefaultArguments() Arguments {
return Arguments{
CollectInterval: 15 * time.Second,
SampleRate: 97,
Expand All @@ -85,9 +82,16 @@ func defaultArguments() Arguments {
CollectKernelProfile: true,
Demangle: "none",
PythonEnabled: true,
SymbolsMapSize: 2048,
PIDMapSize: 16384,
}
}

// SetToDefault implements syntax.Defaulter.
func (arg *Arguments) SetToDefault() {
*arg = NewDefaultArguments()
}

type Component struct {
options component.Options
args Arguments
Expand Down Expand Up @@ -251,5 +255,9 @@ func convertSessionOptions(args Arguments, ms *metrics) ebpfspy.SessionOptions {
KeepRounds: args.CacheRounds,
},
},
BPFMapsOptions: ebpfspy.BPFMapsOptions{
SymbolsMapSize: uint32(args.SymbolsMapSize),
PIDMapSize: uint32(args.PIDMapSize),
},
}
}

0 comments on commit 655784f

Please sign in to comment.