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

embed: clean up initial server start logs #9580

Merged
merged 1 commit into from
Apr 17, 2018
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
102 changes: 73 additions & 29 deletions embed/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,30 +290,40 @@ func NewConfig() *Config {
lcurl, _ := url.Parse(DefaultListenClientURLs)
acurl, _ := url.Parse(DefaultAdvertiseClientURLs)
cfg := &Config{
MaxSnapFiles: DefaultMaxSnapshots,
MaxWalFiles: DefaultMaxWALs,
Name: DefaultName,
SnapCount: etcdserver.DefaultSnapCount,
MaxTxnOps: DefaultMaxTxnOps,
MaxRequestBytes: DefaultMaxRequestBytes,
MaxSnapFiles: DefaultMaxSnapshots,
MaxWalFiles: DefaultMaxWALs,

Name: DefaultName,

SnapCount: etcdserver.DefaultSnapCount,
MaxTxnOps: DefaultMaxTxnOps,
MaxRequestBytes: DefaultMaxRequestBytes,

GRPCKeepAliveMinTime: DefaultGRPCKeepAliveMinTime,
GRPCKeepAliveInterval: DefaultGRPCKeepAliveInterval,
GRPCKeepAliveTimeout: DefaultGRPCKeepAliveTimeout,
TickMs: 100,
ElectionMs: 1000,
LPUrls: []url.URL{*lpurl},
LCUrls: []url.URL{*lcurl},
APUrls: []url.URL{*apurl},
ACUrls: []url.URL{*acurl},
ClusterState: ClusterStateFlagNew,
InitialClusterToken: "etcd-cluster",
StrictReconfigCheck: DefaultStrictReconfigCheck,
Metrics: "basic",
EnableV2: DefaultEnableV2,
CORS: map[string]struct{}{"*": {}},
HostWhitelist: map[string]struct{}{"*": {}},
AuthToken: "simple",
PreVote: false, // TODO: enable by default in v3.5

TickMs: 100,
ElectionMs: 1000,

LPUrls: []url.URL{*lpurl},
LCUrls: []url.URL{*lcurl},
APUrls: []url.URL{*apurl},
ACUrls: []url.URL{*acurl},

ClusterState: ClusterStateFlagNew,
InitialClusterToken: "etcd-cluster",

StrictReconfigCheck: DefaultStrictReconfigCheck,
Metrics: "basic",
EnableV2: DefaultEnableV2,

CORS: map[string]struct{}{"*": {}},
HostWhitelist: map[string]struct{}{"*": {}},

AuthToken: "simple",

PreVote: false, // TODO: enable by default in v3.5

loggerMu: new(sync.RWMutex),
logger: nil,
Expand Down Expand Up @@ -609,17 +619,11 @@ func (cfg *Config) Validate() error {
return err
}
if err := checkHostURLs(cfg.APUrls); err != nil {
addrs := make([]string, len(cfg.APUrls))
for i := range cfg.APUrls {
addrs[i] = cfg.APUrls[i].String()
}
addrs := cfg.getAPURLs()
return fmt.Errorf(`--initial-advertise-peer-urls %q must be "host:port" (%v)`, strings.Join(addrs, ","), err)
}
if err := checkHostURLs(cfg.ACUrls); err != nil {
addrs := make([]string, len(cfg.ACUrls))
for i := range cfg.ACUrls {
addrs[i] = cfg.ACUrls[i].String()
}
addrs := cfg.getACURLs()
return fmt.Errorf(`--advertise-client-urls %q must be "host:port" (%v)`, strings.Join(addrs, ","), err)
}
// Check if conflicting flags are passed.
Expand Down Expand Up @@ -870,3 +874,43 @@ func checkHostURLs(urls []url.URL) error {
}
return nil
}

func (cfg *Config) getAPURLs() (ss []string) {
ss = make([]string, len(cfg.APUrls))
for i := range cfg.APUrls {
ss[i] = cfg.APUrls[i].String()
}
return ss
}

func (cfg *Config) getLPURLs() (ss []string) {
ss = make([]string, len(cfg.LPUrls))
for i := range cfg.LPUrls {
ss[i] = cfg.LPUrls[i].String()
}
return ss
}

func (cfg *Config) getACURLs() (ss []string) {
ss = make([]string, len(cfg.ACUrls))
for i := range cfg.ACUrls {
ss[i] = cfg.ACUrls[i].String()
}
return ss
}

func (cfg *Config) getLCURLs() (ss []string) {
ss = make([]string, len(cfg.LCUrls))
for i := range cfg.LCUrls {
ss[i] = cfg.LCUrls[i].String()
}
return ss
}

func (cfg *Config) getMetricsURLs() (ss []string) {
ss = make([]string, len(cfg.ListenMetricsUrls))
for i := range cfg.ListenMetricsUrls {
ss[i] = cfg.ListenMetricsUrls[i].String()
}
return ss
}
113 changes: 78 additions & 35 deletions embed/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,26 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {
e = nil
}()

if e.Peers, err = startPeerListeners(cfg); err != nil {
if e.cfg.logger != nil {
e.cfg.logger.Info(
"configuring peer listeners",
zap.Strings("listen-peer-urls", e.cfg.getLPURLs()),
)
}
if e.Peers, err = configurePeerListeners(cfg); err != nil {
return e, err
}
if e.sctxs, err = startClientListeners(cfg); err != nil {

if e.cfg.logger != nil {
e.cfg.logger.Info(
"configuring client listeners",
zap.Strings("listen-client-urls", e.cfg.getLCURLs()),
)
}
if e.sctxs, err = configureClientListeners(cfg); err != nil {
return e, err
}

for _, sctx := range e.sctxs {
e.Clients = append(e.Clients, sctx.l)
}
Expand Down Expand Up @@ -189,11 +203,7 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {
}
sort.Strings(ss)
if e.cfg.logger != nil {
e.cfg.logger.Info(
"starting with CORS",
zap.String("server-id", e.Server.ID().String()),
zap.Strings("cors", ss),
)
e.cfg.logger.Info("configured CORS", zap.Strings("cors", ss))
} else {
plog.Infof("%s starting with cors %q", e.Server.ID(), ss)
}
Expand All @@ -205,11 +215,7 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {
}
sort.Strings(ss)
if e.cfg.logger != nil {
e.cfg.logger.Info(
"starting with host whitelist",
zap.String("server-id", e.Server.ID().String()),
zap.Strings("hosts", ss),
)
e.cfg.logger.Info("configured host whitelist", zap.Strings("hosts", ss))
} else {
plog.Infof("%s starting with host whitelist %q", e.Server.ID(), ss)
}
Expand Down Expand Up @@ -240,6 +246,17 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {
return e, err
}

if e.cfg.logger != nil {
e.cfg.logger.Info(
"now serving peer/client/metrics",
zap.String("local-member-id", e.Server.ID().String()),
zap.Strings("initial-advertise-peer-urls", e.cfg.getAPURLs()),
zap.Strings("listen-peer-urls", e.cfg.getLPURLs()),
zap.Strings("advertise-client-urls", e.cfg.getACURLs()),
zap.Strings("listen-client-urls", e.cfg.getLCURLs()),
zap.Strings("listen-metrics-urls", e.cfg.getMetricsURLs()),
)
}
serving = true
return e, nil
}
Expand Down Expand Up @@ -336,7 +353,7 @@ func stopServers(ctx context.Context, ss *servers) {

func (e *Etcd) Err() <-chan error { return e.errc }

func startPeerListeners(cfg *Config) (peers []*peerListener, err error) {
func configurePeerListeners(cfg *Config) (peers []*peerListener, err error) {
if err = cfg.PeerSelfCert(); err != nil {
if cfg.logger != nil {
cfg.logger.Fatal("failed to get peer self-signed certs", zap.Error(err))
Expand All @@ -360,7 +377,11 @@ func startPeerListeners(cfg *Config) (peers []*peerListener, err error) {
for i := range peers {
if peers[i] != nil && peers[i].close != nil {
if cfg.logger != nil {
cfg.logger.Info("stopping listening for peers", zap.String("address", cfg.LPUrls[i].String()))
cfg.logger.Warn(
"closing peer listener",
zap.String("address", cfg.LPUrls[i].String()),
zap.Error(err),
)
} else {
plog.Info("stopping listening for peers on ", cfg.LPUrls[i].String())
}
Expand Down Expand Up @@ -397,11 +418,6 @@ func startPeerListeners(cfg *Config) (peers []*peerListener, err error) {
peers[i].close = func(context.Context) error {
return peers[i].Listener.Close()
}
if cfg.logger != nil {
cfg.logger.Info("listening for peers", zap.String("address", u.String()))
} else {
plog.Info("listening for peers on ", u.String())
}
}
return peers, nil
}
Expand All @@ -417,6 +433,7 @@ func (e *Etcd) servePeers() (err error) {
}

for _, p := range e.Peers {
u := p.Listener.Addr().String()
gs := v3rpc.Server(e.Server, peerTLScfg)
m := cmux.New(p.Listener)
go gs.Serve(m.Match(cmux.HTTP2()))
Expand All @@ -431,21 +448,42 @@ func (e *Etcd) servePeers() (err error) {
// gracefully shutdown http.Server
// close open listeners, idle connections
// until context cancel or time-out
if e.cfg.logger != nil {
e.cfg.logger.Info(
"stopping serving peer traffic",
zap.String("address", u),
)
}
stopServers(ctx, &servers{secure: peerTLScfg != nil, grpc: gs, http: srv})
if e.cfg.logger != nil {
e.cfg.logger.Info(
"stopped serving peer traffic",
zap.String("address", u),
)
}
return nil
}
}

// start peer servers in a goroutine
for _, pl := range e.Peers {
go func(l *peerListener) {
u := l.Addr().String()
if e.cfg.logger != nil {
e.cfg.logger.Info(
"serving peer traffic",
zap.String("address", u),
)
} else {
plog.Info("listening for peers on ", u)
}
e.errHandler(l.serve())
}(pl)
}
return nil
}

func startClientListeners(cfg *Config) (sctxs map[string]*serveCtx, err error) {
func configureClientListeners(cfg *Config) (sctxs map[string]*serveCtx, err error) {
if err = cfg.ClientSelfCert(); err != nil {
if cfg.logger != nil {
cfg.logger.Fatal("failed to get client self-signed certs", zap.Error(err))
Expand All @@ -464,7 +502,6 @@ func startClientListeners(cfg *Config) (sctxs map[string]*serveCtx, err error) {
sctxs = make(map[string]*serveCtx)
for _, u := range cfg.LCUrls {
sctx := newServeCtx(cfg.logger)

if u.Scheme == "http" || u.Scheme == "unix" {
if !cfg.ClientTLSInfo.Empty() {
if cfg.logger != nil {
Expand Down Expand Up @@ -528,19 +565,19 @@ func startClientListeners(cfg *Config) (sctxs map[string]*serveCtx, err error) {
}
}

if cfg.logger != nil {
cfg.logger.Info("listening for client requests", zap.String("host", u.Host))
} else {
plog.Info("listening for client requests on ", u.Host)
}
defer func() {
if err != nil {
sctx.l.Close()
if cfg.logger != nil {
cfg.logger.Info("stopping listening for client requests", zap.String("host", u.Host))
} else {
plog.Info("stopping listening for client requests on ", u.Host)
}
if err == nil {
return
}
sctx.l.Close()
if cfg.logger != nil {
cfg.logger.Warn(
"closing peer listener",
zap.String("address", u.Host),
zap.Error(err),
)
} else {
plog.Info("stopping listening for client requests on ", u.Host)
}
}()
for k := range cfg.UserHandlers {
Expand All @@ -561,7 +598,10 @@ func startClientListeners(cfg *Config) (sctxs map[string]*serveCtx, err error) {
func (e *Etcd) serveClients() (err error) {
if !e.cfg.ClientTLSInfo.Empty() {
if e.cfg.logger != nil {
e.cfg.logger.Info("starting with client TLS", zap.String("tls-info", fmt.Sprintf("%+v", e.cfg.ClientTLSInfo)))
e.cfg.logger.Info(
"starting with client TLS",
zap.String("tls-info", fmt.Sprintf("%+v", e.cfg.ClientTLSInfo)),
)
} else {
plog.Infof("ClientTLS: %s", e.cfg.ClientTLSInfo)
}
Expand Down Expand Up @@ -627,7 +667,10 @@ func (e *Etcd) serveMetrics() (err error) {
e.metricsListeners = append(e.metricsListeners, ml)
go func(u url.URL, ln net.Listener) {
if e.cfg.logger != nil {
e.cfg.logger.Info("listening for metrics", zap.String("url", u.String()))
e.cfg.logger.Info(
"serving metrics",
zap.String("address", u.String()),
)
} else {
plog.Info("listening for metrics on ", u.String())
}
Expand Down
8 changes: 3 additions & 5 deletions embed/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ func (sctx *serveCtx) serve(
logger := defaultLog.New(ioutil.Discard, "etcdhttp", 0)
<-s.ReadyNotify()

if sctx.lg != nil {
sctx.lg.Info("ready to server client requests")
} else {
if sctx.lg == nil {
plog.Info("ready to serve client requests")
}

Expand Down Expand Up @@ -136,7 +134,7 @@ func (sctx *serveCtx) serve(
sctx.serversC <- &servers{grpc: gs, http: srvhttp}
if sctx.lg != nil {
sctx.lg.Info(
"serving insecure client requests; this is strongly discouraged!",
"serving client traffic insecurely; this is strongly discouraged!",
zap.String("address", sctx.l.Addr().String()),
)
} else {
Expand Down Expand Up @@ -186,7 +184,7 @@ func (sctx *serveCtx) serve(
sctx.serversC <- &servers{secure: true, grpc: gs, http: srv}
if sctx.lg != nil {
sctx.lg.Info(
"serving client requests",
"serving client traffic insecurely",
zap.String("address", sctx.l.Addr().String()),
)
} else {
Expand Down
Loading