Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Activate pprof by flag #1933

Merged
merged 1 commit into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading