-
Notifications
You must be signed in to change notification settings - Fork 487
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
Prototype using our own embedded HTTP server #3780
Closed
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,30 +3,62 @@ | |
package net | ||
|
||
import ( | ||
"flag" | ||
"github.com/gorilla/mux" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/weaveworks/common/logging" | ||
"github.com/weaveworks/common/middleware" | ||
"time" | ||
|
||
weaveworks "github.com/weaveworks/common/server" | ||
) | ||
|
||
const ( | ||
DefaultHTTPPort = 8080 | ||
DefaultGRPCPort = 8081 | ||
) | ||
|
||
// ServerConfig is a River configuration that allows one to configure a weaveworks.Server. It | ||
// exposes a subset of the available configurations. | ||
// ServerConfig for a Server | ||
type ServerConfig struct { | ||
|
||
// ==== configuration exposed in River configs === | ||
|
||
// HTTP configures the HTTP weaveworks. Note that despite the block being present or not, | ||
// the weaveworks is always started. | ||
HTTP *HTTPConfig `river:"http,block,optional"` | ||
|
||
// GRPC configures the gRPC weaveworks. Note that despite the block being present or not, | ||
// the weaveworks is always started. | ||
GRPC *GRPCConfig `river:"grpc,block,optional"` | ||
|
||
// GracefulShutdownTimeout configures a timeout to gracefully shut down the server. | ||
GracefulShutdownTimeout time.Duration `river:"graceful_shutdown_timeout,attr,optional"` | ||
|
||
// ==== configuration NOT exposed in River configs === | ||
|
||
Comment on lines
+30
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exposing these in River would be trivial now and all components could benefit from new configuration options, e.g. TLS. |
||
MetricsNamespace string | ||
HTTPListenNetwork string | ||
|
||
CipherSuites string | ||
MinVersion string | ||
HTTPTLSConfig TLSConfig | ||
|
||
RegisterInstrumentation bool | ||
ExcludeRequestInLog bool | ||
DisableRequestSuccessLog bool | ||
|
||
HTTPMiddleware []middleware.Interface | ||
Router *mux.Router | ||
DoNotAddDefaultHTTPMiddleware bool | ||
|
||
LogFormat logging.Format | ||
LogLevel logging.Level | ||
Log logging.Interface | ||
LogSourceIPs bool | ||
LogSourceIPsHeader string | ||
LogSourceIPsRegex string | ||
LogRequestAtInfoLevel bool | ||
|
||
// If not set, default signal handler is used. | ||
SignalHandler SignalHandler | ||
|
||
// If not set, default Prometheus registry is used. | ||
Registerer prometheus.Registerer | ||
Gatherer prometheus.Gatherer | ||
|
||
PathPrefix string | ||
} | ||
|
||
// HTTPConfig configures the HTTP weaveworks started by weaveworks.Server. | ||
|
@@ -39,40 +71,12 @@ type HTTPConfig struct { | |
ServerIdleTimeout time.Duration `river:"server_idle_timeout,attr,optional"` | ||
} | ||
|
||
// Into applies the configs from HTTPConfig into a weaveworks.Into. | ||
func (h *HTTPConfig) Into(c *weaveworks.Config) { | ||
c.HTTPListenAddress = h.ListenAddress | ||
c.HTTPListenPort = h.ListenPort | ||
c.HTTPConnLimit = h.ConnLimit | ||
c.HTTPServerReadTimeout = h.ServerReadTimeout | ||
c.HTTPServerWriteTimeout = h.ServerWriteTimeout | ||
c.HTTPServerIdleTimeout = h.ServerIdleTimeout | ||
} | ||
|
||
// GRPCConfig configures the gRPC weaveworks started by weaveworks.Server. | ||
type GRPCConfig struct { | ||
ListenAddress string `river:"listen_address,attr,optional"` | ||
ListenPort int `river:"listen_port,attr,optional"` | ||
ConnLimit int `river:"conn_limit,attr,optional"` | ||
MaxConnectionAge time.Duration `river:"max_connection_age,attr,optional"` | ||
MaxConnectionAgeGrace time.Duration `river:"max_connection_age_grace,attr,optional"` | ||
MaxConnectionIdle time.Duration `river:"max_connection_idle,attr,optional"` | ||
ServerMaxRecvMsg int `river:"server_max_recv_msg_size,attr,optional"` | ||
ServerMaxSendMsg int `river:"server_max_send_msg_size,attr,optional"` | ||
ServerMaxConcurrentStreams uint `river:"server_max_concurrent_streams,attr,optional"` | ||
} | ||
|
||
// Into applies the configs from GRPCConfig into a weaveworks.Into. | ||
func (g *GRPCConfig) Into(c *weaveworks.Config) { | ||
c.GRPCListenAddress = g.ListenAddress | ||
c.GRPCListenPort = g.ListenPort | ||
c.GRPCConnLimit = g.ConnLimit | ||
c.GRPCServerMaxConnectionAge = g.MaxConnectionAge | ||
c.GRPCServerMaxConnectionAgeGrace = g.MaxConnectionAgeGrace | ||
c.GRPCServerMaxConnectionIdle = g.MaxConnectionIdle | ||
c.GPRCServerMaxRecvMsgSize = g.ServerMaxRecvMsg | ||
c.GRPCServerMaxSendMsgSize = g.ServerMaxSendMsg | ||
c.GPRCServerMaxConcurrentStreams = g.ServerMaxConcurrentStreams | ||
// TLSConfig contains TLS parameters for ServerConfig. | ||
type TLSConfig struct { | ||
TLSCertPath string | ||
TLSKeyPath string | ||
ClientAuth string | ||
ClientCAs string | ||
} | ||
|
||
func (c *ServerConfig) UnmarshalRiver(f func(v interface{}) error) error { | ||
|
@@ -83,32 +87,3 @@ func (c *ServerConfig) UnmarshalRiver(f func(v interface{}) error) error { | |
|
||
return nil | ||
} | ||
|
||
// Convert converts the River-based ServerConfig into a weaveworks.Config object. | ||
func (c *ServerConfig) Convert() weaveworks.Config { | ||
cfg := newDefaultConfig() | ||
if c.HTTP != nil { | ||
c.HTTP.Into(&cfg) | ||
} | ||
if c.GRPC != nil { | ||
c.GRPC.Into(&cfg) | ||
} | ||
// If set, override. Don't allow a zero-value since it configure a context.WithTimeout, so the user should at least | ||
// give a >0 value to it | ||
if c.GracefulShutdownTimeout != 0 { | ||
cfg.ServerGracefulShutdownTimeout = c.GracefulShutdownTimeout | ||
} | ||
return cfg | ||
} | ||
|
||
// newDefaultConfig creates a new weaveworks.Config object with some overridden defaults. | ||
func newDefaultConfig() weaveworks.Config { | ||
c := weaveworks.Config{} | ||
c.RegisterFlags(flag.NewFlagSet("empty", flag.ContinueOnError)) | ||
c.HTTPListenPort = DefaultHTTPPort | ||
c.GRPCListenPort = DefaultGRPCPort | ||
// By default, do not register instrumentation since every metric is later registered | ||
// inside a custom register | ||
c.RegisterInstrumentation = false | ||
return c | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This struct is a merge of our ServerConfig and the weaveworks' server Config.
But we would be in control of how this works and what is available in River.