diff --git a/README.md b/README.md index c3d58a803..e7bf358e4 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ Usage: Flags: --config string config file (default is $HOME/.flowlogs-pipeline) --health.port string Health server port (default "8080") + --profile.port int Go Pprof listen port (default disabled) -h, --help help for flowlogs-pipeline --log-level string Log level: debug, info, warning, error (default "error") --parameters string json of config file parameters field diff --git a/cmd/flowlogs-pipeline/main.go b/cmd/flowlogs-pipeline/main.go index 25a054167..9c6de32dc 100644 --- a/cmd/flowlogs-pipeline/main.go +++ b/cmd/flowlogs-pipeline/main.go @@ -20,11 +20,14 @@ package main import ( "encoding/json" "fmt" + "net/http" "os" "path/filepath" "strings" "time" + _ "net/http/pprof" + jsoniter "github.com/json-iterator/go" "github.com/netobserv/flowlogs-pipeline/pkg/config" "github.com/netobserv/flowlogs-pipeline/pkg/operational/health" @@ -135,6 +138,7 @@ func initFlags() { rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", fmt.Sprintf("config file (default is $HOME/%s)", defaultLogFileName)) rootCmd.PersistentFlags().StringVar(&logLevel, "log-level", "error", "Log level: debug, info, warning, error") rootCmd.PersistentFlags().StringVar(&opts.Health.Port, "health.port", "8080", "Health server port") + rootCmd.PersistentFlags().IntVar(&opts.Profile.Port, "profile.port", 0, "Go pprof tool port (default: disabled)") rootCmd.PersistentFlags().StringVar(&opts.PipeLine, "pipeline", "", "json of config file pipeline field") rootCmd.PersistentFlags().StringVar(&opts.Parameters, "parameters", "", "json of config file parameters field") } @@ -178,6 +182,14 @@ func run() { os.Exit(1) } + if opts.Profile.Port != 0 { + go func() { + log.WithField("port", opts.Profile.Port).Info("starting PProf HTTP listener") + log.WithError(http.ListenAndServe(fmt.Sprintf(":%d", opts.Profile.Port), nil)). + Error("PProf HTTP listener stopped working") + }() + } + // Start health report server health.NewHealthServer(&opts, mainPipeline) diff --git a/pkg/config/config.go b/pkg/config/config.go index c25ac8440..27e693768 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -29,6 +29,7 @@ type Options struct { PipeLine string Parameters string Health Health + Profile Profile } type ConfigFileStruct struct { @@ -41,6 +42,10 @@ type Health struct { Port string } +type Profile struct { + Port int +} + type Stage struct { Name string `yaml:"name" json:"name"` Follows string `yaml:"follows,omitempty" json:"follows,omitempty"`