Skip to content

Commit

Permalink
improves homebrew support
Browse files Browse the repository at this point in the history
  • Loading branch information
petethepig committed Jan 18, 2021
1 parent 6af5383 commit a25b8ee
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
34 changes: 34 additions & 0 deletions pkg/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"flag"
"fmt"
"os"
"path/filepath"
"reflect"
"runtime"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -47,6 +49,8 @@ func populateFlagSet(obj interface{}, flagSet *flag.FlagSet) {
t := reflect.TypeOf(v.Interface())
num := t.NumField()

installPrefix := getInstallPrefix()

for i := 0; i < num; i++ {
field := t.Field(i)
fieldV := v.Field(i)
Expand All @@ -68,6 +72,7 @@ func populateFlagSet(obj interface{}, flagSet *flag.FlagSet) {
flagSet.Var(val2, nameVal, descVal)
case reflect.TypeOf(""):
val := fieldV.Addr().Interface().(*string)
defaultValStr := strings.ReplaceAll(defaultValStr, "<installPrefix>", installPrefix)
flagSet.StringVar(val, nameVal, defaultValStr, descVal)
case reflect.TypeOf(true):
val := fieldV.Addr().Interface().(*bool)
Expand Down Expand Up @@ -104,6 +109,35 @@ func populateFlagSet(obj interface{}, flagSet *flag.FlagSet) {
}
}

// on mac pyroscope is usually installed via homebrew. homebrew installs under a prefix
// this is logic to figure out what prefix it is
func getInstallPrefix() string {
if runtime.GOOS != "darwin" {
return ""
}

executablePath, err := os.Executable()
if err != nil {
// TODO: figure out what kind of errors might happen, handle it
return ""
}
cellarPath := filepath.Clean(filepath.Join(resolvePath(executablePath), "../../../.."))

if !strings.HasSuffix(cellarPath, "Cellar") {
// looks like it's not installed via homebrew
return ""
}

return filepath.Clean(filepath.Join(cellarPath, "../"))
}

func resolvePath(path string) string {
if res, err := filepath.EvalSymlinks(path); err == nil {
return res
}
return path
}

func printUsage(c *ffcli.Command) string {
return gradientBanner() + "\n" + DefaultUsageFunc(c)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Config struct {
}

type Agent struct {
Config string `def:"/etc/pyroscope/agent.yml" desc:"location of config file"`
Config string `def:"<installPrefix>/etc/pyroscope/agent.yml" desc:"location of config file"`
LogLevel string `def:"info", desc:"debug|info|warn|error"`

// AgentCMD []string
Expand All @@ -23,16 +23,16 @@ type Agent struct {
ServerAddress string `def:"http://localhost:4040" desc:"address of the pyroscope server"`
UpstreamThreads int `def:"4"`
UpstreamRequestTimeout time.Duration `def:"10s"`
UNIXSocketPath string `def:"/var/run/pyroscope-agent.sock" desc:"path to a UNIX socket file"`
UNIXSocketPath string `def:"<installPrefix>/var/run/pyroscope-agent.sock" desc:"path to a UNIX socket file"`
}

type Server struct {
Config string `def:"/etc/pyroscope/server.yml" desc:"location of config file"`
Config string `def:"<installPrefix>/etc/pyroscope/server.yml" desc:"location of config file"`
LogLevel string `def:"info", desc:"debug|info|warn|error"`
// TODO: fix, doesn't see to work
BadgerLogLevel string `def:"error", desc:"debug|info|warn|error"`

StoragePath string `def:"/var/lib/pyroscope"`
StoragePath string `def:"<installPrefix>/var/lib/pyroscope"`
ApiBindAddr string `def:":4040"`

CacheDimensionSize int `def:"1000"`
Expand Down

0 comments on commit a25b8ee

Please sign in to comment.