Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Commit

Permalink
Merge pull request #232 from justinsb/add_listen_metrics_urls
Browse files Browse the repository at this point in the history
Support listen-metrics-urls option
  • Loading branch information
justinsb authored Jul 29, 2019
2 parents 9cc24a0 + 0231064 commit b6cd218
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
7 changes: 6 additions & 1 deletion cmd/etcd-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func main() {
flag.StringVar(&o.Address, "address", o.Address, "local address to use")
flag.StringVar(&o.PeerUrls, "peer-urls", o.PeerUrls, "peer-urls to use")
flag.IntVar(&o.GrpcPort, "grpc-port", o.GrpcPort, "grpc-port to use")
flag.StringVar(&o.ListenMetricsURLs, "listen-metric-urls", o.ListenMetricsURLs, "listen-metric-urls configure etcd dedicated metrics URL endpoints")
flag.StringVar(&o.ClientUrls, "client-urls", o.ClientUrls, "client-urls to use for normal operation")
flag.StringVar(&o.QuarantineClientUrls, "quarantine-client-urls", o.QuarantineClientUrls, "client-urls to use when etcd should be quarantined e.g. when offline")
flag.StringVar(&o.ClusterName, "cluster-name", o.ClusterName, "name of cluster")
Expand Down Expand Up @@ -143,6 +144,9 @@ type EtcdManagerOptions struct {

// We have an explicit option for insecure configuration for etcd
EtcdInsecure bool

// ListenMetricsURLs allows configuration of the special etcd metrics urls
ListenMetricsURLs string
}

// InitDefaults populates the default flag values
Expand Down Expand Up @@ -383,7 +387,8 @@ func RunEtcdManager(o *EtcdManagerOptions) error {
glog.Fatalf("error performing scan for legacy data: %v", err)
}

etcdServer, err := etcd.NewEtcdServer(o.DataDir, o.ClusterName, o.ListenAddress, etcdNodeInfo, peerServer, dnsProvider, etcdClientsCA, etcdPeersCA)
listenMetricsURLs := expandUrls(o.ListenMetricsURLs, o.Address, name)
etcdServer, err := etcd.NewEtcdServer(o.DataDir, o.ClusterName, o.ListenAddress, listenMetricsURLs, etcdNodeInfo, peerServer, dnsProvider, etcdClientsCA, etcdPeersCA)
if err != nil {
return fmt.Errorf("error initializing etcd server: %v", err)
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/etcd/etcdprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ type etcdProcess struct {

// ListenAddress is the address we bind to
ListenAddress string

// ListenMetricsURLs is the set of urls we should listen for metrics on
ListenMetricsURLs []string
}

func (p *etcdProcess) ExitState() (error, *os.ProcessState) {
Expand Down Expand Up @@ -189,6 +192,11 @@ func (p *etcdProcess) Start() error {
env["ETCD_ADVERTISE_CLIENT_URLS"] = strings.Join(clientUrls, ",")
env["ETCD_INITIAL_ADVERTISE_PEER_URLS"] = strings.Join(me.PeerUrls, ",")

// This is only supported in 3.3 and later, but by using an env var it simply won't be picked up
if len(p.ListenMetricsURLs) != 0 {
env["ETCD_LISTEN_METRICS_URLS"] = strings.Join(p.ListenMetricsURLs, ",")
}

if p.CreateNewCluster {
env["ETCD_INITIAL_CLUSTER_STATE"] = "new"
} else {
Expand Down
15 changes: 10 additions & 5 deletions pkg/etcd/etcdserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@ type EtcdServer struct {

etcdClientsCA *pki.Keypair
etcdPeersCA *pki.Keypair

// listenMetricsURLs is the set of URLs where etcd should listen for metrics
listenMetricsURLs []string
}

type preparedState struct {
validUntil time.Time
clusterToken string
}

func NewEtcdServer(baseDir string, clusterName string, listenAddress string, etcdNodeConfiguration *protoetcd.EtcdNode, peerServer *privateapi.Server, dnsProvider dns.Provider, etcdClientsCA *pki.Keypair, etcdPeersCA *pki.Keypair) (*EtcdServer, error) {
func NewEtcdServer(baseDir string, clusterName string, listenAddress string, listenMetricsURLs []string, etcdNodeConfiguration *protoetcd.EtcdNode, peerServer *privateapi.Server, dnsProvider dns.Provider, etcdClientsCA *pki.Keypair, etcdPeersCA *pki.Keypair) (*EtcdServer, error) {
s := &EtcdServer{
baseDir: baseDir,
clusterName: clusterName,
Expand All @@ -61,6 +64,7 @@ func NewEtcdServer(baseDir string, clusterName string, listenAddress string, etc
etcdNodeConfiguration: etcdNodeConfiguration,
etcdClientsCA: etcdClientsCA,
etcdPeersCA: etcdPeersCA,
listenMetricsURLs: listenMetricsURLs,
}

// Make sure we have read state from disk before serving
Expand Down Expand Up @@ -565,10 +569,11 @@ func (s *EtcdServer) startEtcdProcess(state *protoetcd.EtcdState) error {
ClusterToken: state.Cluster.ClusterToken,
Nodes: state.Cluster.Nodes,
},
Quarantined: state.Quarantined,
MyNodeName: s.etcdNodeConfiguration.Name,
ListenAddress: s.listenAddress,
DisableTLS: !meNode.TlsEnabled,
Quarantined: state.Quarantined,
MyNodeName: s.etcdNodeConfiguration.Name,
ListenAddress: s.listenAddress,
DisableTLS: !meNode.TlsEnabled,
ListenMetricsURLs: s.listenMetricsURLs,
}

// We always generate the keypairs, as this allows us to switch to TLS without a restart
Expand Down
6 changes: 5 additions & 1 deletion test/integration/harness/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type TestHarnessNode struct {
etcdController *controller.EtcdController

etcdClientTLSConfig *tls.Config

ListenMetricsURLs []string
}

func (n *TestHarnessNode) Init() error {
Expand Down Expand Up @@ -76,6 +78,8 @@ func (n *TestHarnessNode) Init() error {
n.ClientURL = "https://" + n.Address + ":4001"
}

n.ListenMetricsURLs = []string{"https://" + n.Address + ":8080"}

return nil
}

Expand Down Expand Up @@ -192,7 +196,7 @@ func (n *TestHarnessNode) Run() {
etcdPeersCA = nil
}

etcdServer, err := etcd.NewEtcdServer(n.NodeDir, n.TestHarness.ClusterName, n.Address, me, peerServer, dnsProvider, etcdClientsCA, etcdPeersCA)
etcdServer, err := etcd.NewEtcdServer(n.NodeDir, n.TestHarness.ClusterName, n.Address, n.ListenMetricsURLs, me, peerServer, dnsProvider, etcdClientsCA, etcdPeersCA)
if err != nil {
t.Fatalf("error building EtcdServer: %v", err)
}
Expand Down

0 comments on commit b6cd218

Please sign in to comment.