diff --git a/e2e/cluster_test.go b/e2e/cluster_test.go index ebd2c265d7e0..b8e6741240b6 100644 --- a/e2e/cluster_test.go +++ b/e2e/cluster_test.go @@ -114,6 +114,9 @@ type etcdProcessClusterConfig struct { initialToken string quotaBackendBytes int64 noStrictReconfig bool + + metricsURL bool + insecureMetricsURL bool } // newEtcdProcessCluster launches a new cluster from etcd processes, returning @@ -175,7 +178,7 @@ func (cfg *etcdProcessClusterConfig) etcdServerProcessConfigs() []*etcdServerPro for i := 0; i < cfg.clusterSize; i++ { var curls []string var curl, curltls string - port := cfg.basePort + 4*i + port := cfg.basePort + 5*i curlHost := fmt.Sprintf("localhost:%d", port) switch cfg.clientTLS { @@ -221,6 +224,15 @@ func (cfg *etcdProcessClusterConfig) etcdServerProcessConfigs() []*etcdServerPro if cfg.noStrictReconfig { args = append(args, "--strict-reconfig-check=false") } + var murl string + if cfg.metricsURL { + scheme, mhost := cfg.clientScheme(), fmt.Sprintf("localhost:%d", port+2) + if cfg.insecureMetricsURL { + scheme = "http" + } + murl = (&url.URL{Scheme: scheme, Host: mhost}).String() + args = append(args, "--listen-metrics-urls", murl) + } args = append(args, cfg.tlsArgs()...) etcdCfgs[i] = &etcdServerProcessConfig{ @@ -232,6 +244,7 @@ func (cfg *etcdProcessClusterConfig) etcdServerProcessConfigs() []*etcdServerPro name: name, purl: purl, acurl: curl, + murl: murl, initialToken: cfg.initialToken, } } diff --git a/e2e/etcd_process.go b/e2e/etcd_process.go index cfde0255a6e6..3ae710563c43 100644 --- a/e2e/etcd_process.go +++ b/e2e/etcd_process.go @@ -29,6 +29,7 @@ var etcdServerReadyLines = []string{"enabled capabilities for version", "publish type etcdProcess interface { EndpointsV2() []string EndpointsV3() []string + EndpointsMetrics() []string Start() error Restart() error @@ -57,6 +58,7 @@ type etcdServerProcessConfig struct { purl url.URL acurl string + murl string initialToken string initialCluster string @@ -74,8 +76,9 @@ func newEtcdServerProcess(cfg *etcdServerProcessConfig) (*etcdServerProcess, err return &etcdServerProcess{cfg: cfg, donec: make(chan struct{})}, nil } -func (ep *etcdServerProcess) EndpointsV2() []string { return []string{ep.cfg.acurl} } -func (ep *etcdServerProcess) EndpointsV3() []string { return ep.EndpointsV2() } +func (ep *etcdServerProcess) EndpointsV2() []string { return []string{ep.cfg.acurl} } +func (ep *etcdServerProcess) EndpointsV3() []string { return ep.EndpointsV2() } +func (ep *etcdServerProcess) EndpointsMetrics() []string { return []string{ep.cfg.murl} } func (ep *etcdServerProcess) Start() error { if ep.proc != nil { diff --git a/e2e/v2_curl_test.go b/e2e/v2_curl_test.go index 2322a8549f6a..2d044adca868 100644 --- a/e2e/v2_curl_test.go +++ b/e2e/v2_curl_test.go @@ -125,6 +125,8 @@ type cURLReq struct { value string expected string header string + + metricsURL bool } // cURLPrefixArgs builds the beginning of a curl command for a given key @@ -143,6 +145,9 @@ func cURLPrefixArgs(clus *etcdProcessCluster, method string, req cURLReq) []stri } else if clus.cfg.clientTLS == clientTLS { cmdArgs = append(cmdArgs, "--cacert", caPath, "--cert", certPath, "--key", privateKeyPath) } + if req.metricsURL { + acurl = clus.procs[rand.Intn(clus.cfg.clusterSize)].EndpointsMetrics()[0] + } ep := acurl + req.endpoint if req.username != "" || req.password != "" { diff --git a/e2e/v3_curl_test.go b/e2e/v3_curl_test.go index a15fa214213a..6fe87b977735 100644 --- a/e2e/v3_curl_test.go +++ b/e2e/v3_curl_test.go @@ -246,3 +246,27 @@ func TestV3CurlAuth(t *testing.T) { } } + +func TestV3CurlMetricsSecure(t *testing.T) { testV3CurlMetrics(t, false) } +func TestV3CurlMetricsInsecure(t *testing.T) { testV3CurlMetrics(t, true) } +func testV3CurlMetrics(t *testing.T, insecureMetricsURL bool) { + defer testutil.AfterTest(t) + + cfg := configTLS + cfg.metricsURL = true + cfg.insecureMetricsURL = insecureMetricsURL + + epc, err := newEtcdProcessCluster(&cfg) + if err != nil { + t.Fatalf("could not start etcd process cluster (%v)", err) + } + defer func() { + if cerr := epc.Close(); err != nil { + t.Fatalf("error closing etcd processes (%v)", cerr) + } + }() + + if err = cURLGet(epc, cURLReq{endpoint: "/metrics", expected: `health 1`, metricsURL: true}); err != nil { + t.Fatalf("failed get with curl (%v)", err) + } +}