From c715f728a9ba61b8164953dfba65bfcb433f8272 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 15 Nov 2023 16:24:36 -0800 Subject: [PATCH] config: fix profile port arg parsing In this commit, we fix a subtle bug in the parsing of the yaml config. With the way the library works, the attribute name needs to match the config attribute name. Otherwise, parsing just doesn't work. --- aperture.go | 8 +++----- config.go | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/aperture.go b/aperture.go index 95a3193..b45ed85 100644 --- a/aperture.go +++ b/aperture.go @@ -201,8 +201,8 @@ func (a *Aperture) Start(errChan chan error) error { } // Enable http profiling and validate profile port number if requested. - if a.cfg.ProfilePort != 0 { - if a.cfg.ProfilePort < 1024 || a.cfg.ProfilePort > 65535 { + if a.cfg.Profile != 0 { + if a.cfg.Profile < 1024 || a.cfg.Profile > 65535 { return fmt.Errorf("the profile port must be between " + "1024 and 65535") } @@ -212,9 +212,7 @@ func (a *Aperture) Start(errChan chan error) error { "/debug/pprof", http.StatusSeeOther, )) - listenAddr := fmt.Sprintf( - "localhost:%d", a.cfg.ProfilePort, - ) + listenAddr := fmt.Sprintf("localhost:%d", a.cfg.Profile) log.Infof("Starting profile server at %s", listenAddr) fmt.Println(http.ListenAndServe(listenAddr, nil)) diff --git a/config.go b/config.go index 928a2a6..66e55de 100644 --- a/config.go +++ b/config.go @@ -200,8 +200,8 @@ type Config struct { // BaseDir is a custom directory to store all aperture flies. BaseDir string `long:"basedir" description:"Directory to place all of aperture's files in."` - // ProfilePort is the port on which the pprof profile will be served. - ProfilePort uint16 `long:"profile" description:"Enable HTTP profiling on given port -- NOTE port must be between 1024 and 65535"` + // Profile is the port on which the pprof profile will be served. + Profile uint16 `long:"profile" description:"Enable HTTP profiling on given port -- NOTE port must be between 1024 and 65535"` } func (c *Config) validate() error {