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 19, 2024
1 parent c0f242c commit 8542fe6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 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
5 changes: 3 additions & 2 deletions internal/api/schemas/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ func (c *cueDefs) Load() error {
file := files[i]
if !file.IsDir() {
logrus.Warningf("Plugin %s will not be loaded: it is not a folder", file.Name())
i++
continue
}

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 +121,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 8542fe6

Please sign in to comment.