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

feat: add default timeouts to http server #5

Merged
merged 1 commit into from
Aug 16, 2021
Merged
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
19 changes: 18 additions & 1 deletion flexmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"net/http/pprof"
"os"
"time"

"github.com/prometheus/client_golang/prometheus/promhttp"
)
Expand All @@ -17,6 +18,18 @@ const (

// DefaultPath is the path where we expose prometheus by default.
DefaultPath = "/metrics"

// DefaultReadTimeout is the default read timeout for the http server.
DefaultReadTimeout = 5 * time.Second

// DefaultReadHeaderTimeout is the default read header timeout for the http server.
DefaultReadHeaderTimeout = 1 * time.Second

// DefaultIdleTimeout is the default idle timeout for the http server.
DefaultIdleTimeout = 1 * time.Second

// DefaultWriteTimeout is the default write timeout for the http server.
DefaultWriteTimeout = 15 * time.Second
)

type Option func(s *Server)
Expand Down Expand Up @@ -54,7 +67,11 @@ func New(options ...Option) *Server {
server := &Server{
Path: path,
Server: &http.Server{
Addr: addr,
Addr: addr,
ReadTimeout: DefaultReadTimeout,
ReadHeaderTimeout: DefaultReadHeaderTimeout,
IdleTimeout: DefaultIdleTimeout,
WriteTimeout: DefaultWriteTimeout,
},
}

Expand Down