Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 opentdf-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ server:
maxage: 3600
grpc:
reflectionEnabled: true # Default is false
# http:
# readTimeout: 15s
# writeTimeout: 15s
# readHeaderTimeout: 10s
# idleTimeout: 20s
# maxHeaderBytes: 1 << 20 # 1 MB
cryptoProvider:
type: standard
standard:
Expand Down
46 changes: 33 additions & 13 deletions service/internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
)

const (
writeTimeout time.Duration = 5 * time.Second
readTimeout time.Duration = 10 * time.Second
shutdownTimeout time.Duration = 5 * time.Second
defaultWriteTimeout time.Duration = 5 * time.Second
defaultReadTimeout time.Duration = 10 * time.Second
shutdownTimeout time.Duration = 5 * time.Second
)

type Error string
Expand All @@ -64,7 +64,8 @@
Port int `mapstructure:"port" json:"port" default:"8080"`
Host string `mapstructure:"host,omitempty" json:"host"`
PublicHostname string `mapstructure:"public_hostname,omitempty" json:"publicHostname"`

// Http server config
HttpServerConfig HttpServerConfig `mapstructure:"http" json:"http"`

Check failure on line 68 in service/internal/server/server.go

View workflow job for this annotation

GitHub Actions / go (service)

var-naming: struct field HttpServerConfig should be HTTPServerConfig (revive)
// Enable pprof
EnablePprof bool `mapstructure:"enable_pprof" json:"enable_pprof" default:"false"`
// Trace is for configuring open telemetry based tracing.
Expand Down Expand Up @@ -109,6 +110,14 @@
Key string `mapstructure:"key" json:"key"`
}

type HttpServerConfig struct {

Check failure on line 113 in service/internal/server/server.go

View workflow job for this annotation

GitHub Actions / go (service)

var-naming: type HttpServerConfig should be HTTPServerConfig (revive)
ReadTimeout time.Duration `mapstructure:"readTimeout" json:"readTimeout"`
ReadHeaderTimeout time.Duration `mapstructure:"readHeaderTimeout" json:"readHeaderTimeout"`
WriteTimeout time.Duration `mapstructure:"writeTimeout" json:"writeTimeout"`
IdleTimeout time.Duration `mapstructure:"idleTimeout" json:"idleTimeout"`
MaxHeaderBytes int `mapstructure:"maxHeaderBytes" json:"maxHeaderBytes"`
}

// CORS Configuration for the server
type CORSConfig struct {
// Enable CORS for the server (default: true)
Expand Down Expand Up @@ -283,9 +292,8 @@
// newHTTPServer creates a new http server with the given handler and grpc server
func newHTTPServer(c Config, connectRPC http.Handler, originalGrpcGateway http.Handler, a *auth.Authentication, l *logger.Logger) (*http.Server, error) {
var (
err error
tc *tls.Config
writeTimeoutOverride = writeTimeout
err error
tc *tls.Config
)

// Adds deprecation header to any grpcGateway responses.
Expand Down Expand Up @@ -333,7 +341,9 @@
if c.EnablePprof {
grpcGateway = pprofHandler(grpcGateway)
// Need to extend write timeout to collect pprof data.
writeTimeoutOverride = 30 * time.Second //nolint:mnd // easier to read that we are overriding the default
if c.HttpServerConfig.WriteTimeout < 30*time.Second {
c.HttpServerConfig.WriteTimeout = 30 * time.Second //nolint:mnd // easier to read that we are overriding the default
}
}

var handler http.Handler
Expand All @@ -347,12 +357,22 @@
handler = routeConnectRPCRequests(connectRPC, grpcGateway)
}

if c.HttpServerConfig.ReadTimeout == 0 {
c.HttpServerConfig.ReadTimeout = defaultReadTimeout
}
if c.HttpServerConfig.WriteTimeout == 0 {
c.HttpServerConfig.WriteTimeout = defaultWriteTimeout
}

return &http.Server{
Addr: fmt.Sprintf("%s:%d", c.Host, c.Port),
WriteTimeout: writeTimeoutOverride,
ReadTimeout: readTimeout,
Handler: handler,
TLSConfig: tc,
Addr: fmt.Sprintf("%s:%d", c.Host, c.Port),
WriteTimeout: c.HttpServerConfig.WriteTimeout,
ReadTimeout: c.HttpServerConfig.ReadTimeout,
ReadHeaderTimeout: c.HttpServerConfig.ReadHeaderTimeout,
IdleTimeout: c.HttpServerConfig.IdleTimeout,
MaxHeaderBytes: c.HttpServerConfig.MaxHeaderBytes,
Handler: handler,
TLSConfig: tc,
}, nil
}

Expand Down
Loading