From 95ada49de96e95fbf4561111230f1ef4734d482e Mon Sep 17 00:00:00 2001 From: Kirill Sysoev Date: Sun, 23 Jun 2024 17:26:51 +0800 Subject: [PATCH] Improves documentation for usung `WithProfilerEndpoint` server option --- server/server.go | 6 ++++++ server/server_test.go | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/server/server.go b/server/server.go index 8462a6d..6bc2b40 100644 --- a/server/server.go +++ b/server/server.go @@ -239,6 +239,12 @@ func WithTLS(certFile, keyFile string, config ...*tls.Config) Option { // WithProfilerEndpoint is an option function that enables the profiler endpoint for the server. // Enabling the profiler endpoint allows profiling and performance monitoring of the server. // The profiler endpoint is available at /debug/pprof/. +// To use the profiler endpoint, import the net/http/pprof package in your application. +// Example: +// +// import _ "net/http/pprof" +// +// The profiler endpoint is disabled by default. func WithProfilerEndpoint() Option { return func(s *Server) { s.pprofEnabled = true diff --git a/server/server_test.go b/server/server_test.go index 9a14890..eefe407 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -10,6 +10,8 @@ import ( "testing" "time" + _ "net/http/pprof" //nolint:gosec // pprof is used for testing profile endpoint + "github.com/ksysoev/wasabi/mocks" ) @@ -350,4 +352,17 @@ func TestServer_WithProfilerEndpoint(t *testing.T) { case <-time.After(1 * time.Second): t.Error("Expected server to start") } + + // Check if the profiler endpoint is enabled + resp, err := http.Get("http://" + server.Addr().String() + "/debug/pprof/") + + if err != nil { + t.Errorf("Got unexpected error: %v", err) + } + + defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK { + t.Errorf("Expected status code 200, but got %d", resp.StatusCode) + } }