From 02310647f0be19a353bb09a16893a153360751d8 Mon Sep 17 00:00:00 2001 From: Justin SB Date: Sun, 28 Jul 2019 16:37:24 -0400 Subject: [PATCH] Support listen-metrics-urls option We map it through from the command line, and by passing it with an env-var we can pass it to older versions (that will ignore it) --- cmd/etcd-manager/main.go | 7 ++++++- pkg/etcd/etcdprocess.go | 8 ++++++++ pkg/etcd/etcdserver.go | 15 ++++++++++----- test/integration/harness/node.go | 6 +++++- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/cmd/etcd-manager/main.go b/cmd/etcd-manager/main.go index 6c2f77ff..86fa8a38 100644 --- a/cmd/etcd-manager/main.go +++ b/cmd/etcd-manager/main.go @@ -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") @@ -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 @@ -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) } diff --git a/pkg/etcd/etcdprocess.go b/pkg/etcd/etcdprocess.go index 2e5cac68..a77c91ec 100644 --- a/pkg/etcd/etcdprocess.go +++ b/pkg/etcd/etcdprocess.go @@ -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) { @@ -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 { diff --git a/pkg/etcd/etcdserver.go b/pkg/etcd/etcdserver.go index bba0abfb..e809dd42 100644 --- a/pkg/etcd/etcdserver.go +++ b/pkg/etcd/etcdserver.go @@ -44,6 +44,9 @@ 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 { @@ -51,7 +54,7 @@ type preparedState struct { 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, @@ -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 @@ -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 diff --git a/test/integration/harness/node.go b/test/integration/harness/node.go index acc4dc1c..b9c86f79 100644 --- a/test/integration/harness/node.go +++ b/test/integration/harness/node.go @@ -44,6 +44,8 @@ type TestHarnessNode struct { etcdController *controller.EtcdController etcdClientTLSConfig *tls.Config + + ListenMetricsURLs []string } func (n *TestHarnessNode) Init() error { @@ -76,6 +78,8 @@ func (n *TestHarnessNode) Init() error { n.ClientURL = "https://" + n.Address + ":4001" } + n.ListenMetricsURLs = []string{"https://" + n.Address + ":8080"} + return nil } @@ -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) }