Skip to content

Commit

Permalink
Merge pull request #96 from ksysoev/bugfix/pprof_endpoint
Browse files Browse the repository at this point in the history
Improve documentation for using `WithProfilerEndpoint` server option
  • Loading branch information
ksysoev authored Jun 23, 2024
2 parents 7973326 + 95ada49 commit 48d0786
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"testing"
"time"

_ "net/http/pprof" //nolint:gosec // pprof is used for testing profile endpoint

"github.com/ksysoev/wasabi/mocks"
)

Expand Down Expand Up @@ -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)
}
}

0 comments on commit 48d0786

Please sign in to comment.