github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/adhoc/connect.go (about) 1 package adhoc 2 3 import ( 4 "fmt" 5 6 "github.com/sirupsen/logrus" 7 8 "github.com/pyroscope-io/pyroscope/pkg/agent/types" 9 "github.com/pyroscope-io/pyroscope/pkg/agent/upstream/direct" 10 "github.com/pyroscope-io/pyroscope/pkg/config" 11 "github.com/pyroscope-io/pyroscope/pkg/exec" 12 "github.com/pyroscope-io/pyroscope/pkg/exporter" 13 "github.com/pyroscope-io/pyroscope/pkg/storage" 14 ) 15 16 func newConnect(cfg *config.Adhoc, st *storage.Storage, logger *logrus.Logger) (runner, error) { 17 spyName := cfg.SpyName 18 if cfg.Pid == -1 { 19 if spyName != "" && spyName != "ebpfspy" { 20 return nil, fmt.Errorf("pid -1 can only be used with ebpfspy") 21 } 22 spyName = "ebpfspy" 23 } 24 if err := exec.PerformChecks(spyName); err != nil { 25 return nil, err 26 } 27 28 upstream := direct.New(st, exporter.MetricsExporter{}) 29 30 // if the sample rate is zero, use the default value 31 sampleRate := uint32(types.DefaultSampleRate) 32 if cfg.SampleRate != 0 { 33 sampleRate = uint32(cfg.SampleRate) 34 } 35 36 return &exec.Connect{ 37 Logger: logger, 38 Upstream: upstream, 39 SpyName: spyName, 40 ApplicationName: exec.CheckApplicationName(logger, cfg.ApplicationName, spyName, []string{}), 41 SampleRate: sampleRate, 42 DetectSubprocesses: cfg.DetectSubprocesses, 43 Pid: cfg.Pid, 44 PHPSpyArgs: cfg.PHPSpyArgs, 45 }, nil 46 }