diff --git a/server/server.go b/server/server.go index 02a45194..425de88c 100644 --- a/server/server.go +++ b/server/server.go @@ -181,19 +181,36 @@ type Server struct { // New makes a new Server func New(cfg Config) (*Server, error) { + // If user doesn't supply a logging implementation, by default instantiate + // logrus. + log := cfg.Log + if log == nil { + log = logging.NewLogrus(cfg.LogLevel) + } + + // If user doesn't supply a registerer/gatherer, use Prometheus' by default. + reg := cfg.Registerer + if reg == nil { + reg = prometheus.DefaultRegisterer + } + gatherer := cfg.Gatherer + if gatherer == nil { + gatherer = prometheus.DefaultGatherer + } + tcpConnections := prometheus.NewGaugeVec(prometheus.GaugeOpts{ Namespace: cfg.MetricsNamespace, Name: "tcp_connections", Help: "Current number of accepted TCP connections.", }, []string{"protocol"}) - prometheus.MustRegister(tcpConnections) + reg.MustRegister(tcpConnections) tcpConnectionsLimit := prometheus.NewGaugeVec(prometheus.GaugeOpts{ Namespace: cfg.MetricsNamespace, Name: "tcp_connections_limit", Help: "The max number of TCP connections that can be accepted (0 means no limit).", }, []string{"protocol"}) - prometheus.MustRegister(tcpConnectionsLimit) + reg.MustRegister(tcpConnectionsLimit) network := cfg.HTTPListenNetwork if network == "" { @@ -226,23 +243,6 @@ func New(cfg Config) (*Server, error) { grpcListener = netutil.LimitListener(grpcListener, cfg.GRPCConnLimit) } - // If user doesn't supply a logging implementation, by default instantiate - // logrus. - log := cfg.Log - if log == nil { - log = logging.NewLogrus(cfg.LogLevel) - } - - // If user doesn't supply a registerer/gatherer, use Prometheus' by default. - reg := cfg.Registerer - if reg == nil { - reg = prometheus.DefaultRegisterer - } - gatherer := cfg.Gatherer - if gatherer == nil { - gatherer = prometheus.DefaultGatherer - } - // Setup TLS var httpTLSConfig *tls.Config if len(cfg.HTTPTLSConfig.TLSCertPath) > 0 && len(cfg.HTTPTLSConfig.TLSKeyPath) > 0 {