Skip to content

Commit

Permalink
[FEATURE] Activate pprof by flag
Browse files Browse the repository at this point in the history
Signed-off-by: Augustin Husson <husson.augustin@gmail.com>
  • Loading branch information
Nexucis committed Apr 20, 2024
1 parent c0f242c commit ccbb050
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion cmd/perses/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ __________________________________________________________

func main() {
configFile := flag.String("config", "", "Path to the YAML configuration file for the API. Configuration settings can be overridden when using environment variables.")
pprof := flag.Bool("pprof", false, "Enable pprof")
flag.Parse()
// load the config from file or/and from environment
conf, err := config.Resolve(*configFile)
if err != nil {
logrus.WithError(err).Fatalf("error reading configuration from file %q or from environment", *configFile)
}
runner, persistentManager, err := core.New(conf, banner)
runner, persistentManager, err := core.New(conf, *pprof, banner)
if err != nil {
logrus.Fatal(err)
}
Expand Down
3 changes: 2 additions & 1 deletion internal/api/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"github.com/sirupsen/logrus"
)

func New(conf config.Config, banner string) (*app.Runner, dependency.PersistenceManager, error) {
func New(conf config.Config, enablePprof bool, banner string) (*app.Runner, dependency.PersistenceManager, error) {
persistenceManager, err := dependency.NewPersistenceManager(conf.Database)
if err != nil {
logrus.WithError(err).Fatal("unable to instantiate the persistence manager")
Expand Down Expand Up @@ -81,6 +81,7 @@ func New(conf config.Config, banner string) (*app.Runner, dependency.Persistence

// register the API
runner.HTTPServerBuilder().
ActivatePprof(enablePprof).
APIRegistration(persesAPI).
GzipSkipper(func(c echo.Context) bool {
// let's skip the gzip compression when using the proxy and rely on the datasource behind.
Expand Down
2 changes: 1 addition & 1 deletion internal/api/e2e/framework/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func CreateServer(t *testing.T, conf apiConfig.Config) (*httptest.Server, *httpe
File: defaultFileConfig(),
}
}
runner, persistenceManager, err := core.New(conf, "")
runner, persistenceManager, err := core.New(conf, false, "")
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/api/schemas/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (c *cueDefs) Load() error {
schemaPath := filepath.Join(c.schemasPath, file.Name())

// load the cue files into build.Instances slice
// package `model` is imposed so that we dont mix model-related files with migration-related files
// package `model` is imposed so that we don't mix model-related files with migration-related files
buildInstances := load.Instances([]string{}, &load.Config{Dir: schemaPath, Package: "model"})
// we strongly assume that only 1 buildInstance should be returned, otherwise we skip it
// TODO can probably be improved
Expand Down Expand Up @@ -120,7 +120,7 @@ func (c *cueDefs) Load() error {
}

if !isError {
// in case there is no error we are saving the schemas loaded and the cue context that will be used during the plugin validation phase
// in case there is no error, we are saving the schemas loaded and the cue context that will be used during the plugin validation phase
c.schemas.Store(&newSchemas)
c.context.Store(cueContext)
}
Expand Down

0 comments on commit ccbb050

Please sign in to comment.