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

Improve documentation for using WithProfilerEndpoint server option #96

Merged
merged 1 commit into from
Jun 23, 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
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)
}
}
Loading