Repository: etcd-io/etcd
File: server/etcdserver/server.go (Go)

Code before:
		if m.ID != b.cluster.nodeID {
			tr.AddRemote(m.ID, m.PeerURLs)
		}
	}
	for _, m := range b.cluster.cl.Members() {
		if m.ID != b.cluster.nodeID {
			tr.AddPeer(m.ID, m.PeerURLs)
		}
	}
	srv.r.transport = tr

	return srv, nil
}

func (s *EtcdServer) Logger() *zap.Logger {
	s.lgMu.RLock()
	l := s.lg
	s.lgMu.RUnlock()
	return l
}

func (s *EtcdServer) Config() config.ServerConfig {
	return s.Cfg
}

func (s *EtcdServer) ServerMetrics() *grpc_prometheus.ServerMetrics {
	var mopts []grpc_prometheus.ServerMetricsOption
	if s.Cfg.Metrics == "extensive" {
		mopts = append(mopts, grpc_prometheus.WithServerHandlingTimeHistogram())
	}
	serverMetrics := grpc_prometheus.NewServerMetrics(mopts...)
	s.metricsOnce.Do(func() {
		err := prometheus.Register(serverMetrics)
		if err != nil {
			s.Cfg.Logger.Warn("etcdserver: failed to register grpc metrics", zap.Error(err))
		}
	})
	return serverMetrics
}

// FeatureEnabled returns true if the feature is enabled by the etcd server, false otherwise.
func (s *EtcdServer) FeatureEnabled(f featuregate.Feature) bool {
	return s.Cfg.ServerFeatureGate.Enabled(f)
}

func tickToDur(ticks int, tickMs uint) string {
	return fmt.Sprintf("%v", time.Duration(ticks)*time.Duration(tickMs)*time.Millisecond)
}

func (s *EtcdServer) adjustTicks() {
	lg := s.Logger()

Review comment (performance):
I think we can have function instead of method on EtcdServer here, since they're registered into global default registry.

```go
var metricsLock sync.Mutex
var metricsCache map[string]*grpc_prometheus.ServerMetrics 

func getServerMetrics(metricType string) (*grpc_prometheus.ServerMetrics, error) {
       metricsLock.Lock()
       defer metricsLock.Unlock()
       
        if res, ok := metricsCache[mericsType]; ok {
               return res, nil
        }

        var mopts []grpc_prometheus.ServerMetricsOption
	     if metricType == "extensive" {
		       mopts = append(mopts, grpc_prometheus.WithServerHandlingTimeHistogram())
	     }
	     serverMetrics := grpc_prometheus.NewServerMetrics(mopts...)
         err := prometheus.Register(serverMetrics)
          if err != nil {
               return nil, err
           }
           metricsCache[mericsType] = serverMetrics
           return serverMetrics
}
```

What do you think?

Code after:
	}
	for _, m := range b.cluster.cl.Members() {
		if m.ID != b.cluster.nodeID {
			tr.AddPeer(m.ID, m.PeerURLs)
		}
	}
	srv.r.transport = tr

	return srv, nil
}

func (s *EtcdServer) Logger() *zap.Logger {
	s.lgMu.RLock()
	l := s.lg
	s.lgMu.RUnlock()
	return l
}

func (s *EtcdServer) Config() config.ServerConfig {
	return s.Cfg
}

// FeatureEnabled returns true if the feature is enabled by the etcd server, false otherwise.
func (s *EtcdServer) FeatureEnabled(f featuregate.Feature) bool {
	return s.Cfg.ServerFeatureGate.Enabled(f)
}

func tickToDur(ticks int, tickMs uint) string {
	return fmt.Sprintf("%v", time.Duration(ticks)*time.Duration(tickMs)*time.Millisecond)
}

func (s *EtcdServer) adjustTicks() {
	lg := s.Logger()
	clusterN := len(s.cluster.Members())

	// single-node fresh start, or single-node recovers from snapshot
	if clusterN == 1 {
		ticks := s.Cfg.ElectionTicks - 1
		lg.Info(
			"started as single-node; fast-forwarding election ticks",
			zap.String("local-member-id", s.MemberID().String()),
			zap.Int("forward-ticks", ticks),
			zap.String("forward-duration", tickToDur(ticks, s.Cfg.TickMs)),
			zap.Int("election-ticks", s.Cfg.ElectionTicks),
			zap.String("election-timeout", tickToDur(s.Cfg.ElectionTicks, s.Cfg.TickMs)),
		)
		s.r.advanceTicks(ticks)
		return
	}

	if !s.Cfg.InitialElectionTickAdvance {