From 83ed59d323e4f39b81e5486fa6d0ca91f65de9fb Mon Sep 17 00:00:00 2001 From: Vladislav Byrgazov Date: Mon, 12 Aug 2024 15:08:40 +0500 Subject: [PATCH 1/2] Updated pprof naming and method signature Signed-off-by: Vladislav Byrgazov --- .../{pprof/pprof.go => pprofutils/pprofutils.go} | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) rename pkg/tools/{pprof/pprof.go => pprofutils/pprofutils.go} (87%) diff --git a/pkg/tools/pprof/pprof.go b/pkg/tools/pprofutils/pprofutils.go similarity index 87% rename from pkg/tools/pprof/pprof.go rename to pkg/tools/pprofutils/pprofutils.go index 9adc18ecc..392ecff92 100644 --- a/pkg/tools/pprof/pprof.go +++ b/pkg/tools/pprofutils/pprofutils.go @@ -14,22 +14,22 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package pprof provides ability to enable pprof if required -package pprof +// Package pprofutils provides ability to enable pprof if required +package pprofutils import ( "context" - "fmt" "net/http" "net/http/pprof" + "net/url" "time" "github.com/networkservicemesh/sdk/pkg/tools/log" ) -// Init - configures pprof http handlers -func Init(ctx context.Context, port uint16) { - log.FromContext(ctx).Infof("Profiler is enabled. Listening on %d", port) +// ListenAndServe - configures pprof http handlers +func ListenAndServe(ctx context.Context, listenOn *url.URL) { + log.FromContext(ctx).Infof("Profiler is enabled. Listening on %s", listenOn.Host) mux := http.NewServeMux() mux.HandleFunc("/debug/pprof/", pprof.Index) mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) @@ -43,7 +43,7 @@ func Init(ctx context.Context, port uint16) { mux.Handle("/debug/pprof/mutex", pprof.Handler("mutex")) mux.Handle("/debug/pprof/threadcreate", pprof.Handler("threadcreate")) server := &http.Server{ - Addr: fmt.Sprintf("localhost:%d", port), + Addr: listenOn.Host, Handler: mux, ReadTimeout: 10 * time.Second, WriteTimeout: 10 * time.Second, From 1b2ac0283b82693dab2b468192560870cff547f6 Mon Sep 17 00:00:00 2001 From: Vladislav Byrgazov Date: Mon, 12 Aug 2024 15:31:40 +0500 Subject: [PATCH 2/2] Update listenOn param type from URL to string Signed-off-by: Vladislav Byrgazov --- pkg/tools/pprofutils/pprofutils.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pkg/tools/pprofutils/pprofutils.go b/pkg/tools/pprofutils/pprofutils.go index 392ecff92..cbc23251e 100644 --- a/pkg/tools/pprofutils/pprofutils.go +++ b/pkg/tools/pprofutils/pprofutils.go @@ -21,15 +21,14 @@ import ( "context" "net/http" "net/http/pprof" - "net/url" "time" "github.com/networkservicemesh/sdk/pkg/tools/log" ) // ListenAndServe - configures pprof http handlers -func ListenAndServe(ctx context.Context, listenOn *url.URL) { - log.FromContext(ctx).Infof("Profiler is enabled. Listening on %s", listenOn.Host) +func ListenAndServe(ctx context.Context, listenOn string) { + log.FromContext(ctx).Infof("Profiler is enabled. Listening on %s", listenOn) mux := http.NewServeMux() mux.HandleFunc("/debug/pprof/", pprof.Index) mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) @@ -43,7 +42,7 @@ func ListenAndServe(ctx context.Context, listenOn *url.URL) { mux.Handle("/debug/pprof/mutex", pprof.Handler("mutex")) mux.Handle("/debug/pprof/threadcreate", pprof.Handler("threadcreate")) server := &http.Server{ - Addr: listenOn.Host, + Addr: listenOn, Handler: mux, ReadTimeout: 10 * time.Second, WriteTimeout: 10 * time.Second,