Skip to content

Commit

Permalink
e2e: test '/metrics' endpoints, metrics handler
Browse files Browse the repository at this point in the history
Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
  • Loading branch information
gyuho committed Jul 19, 2017
1 parent f1def71 commit a731fb1
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
19 changes: 17 additions & 2 deletions e2e/etcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ type etcdProcessConfig struct {
acurltls string
acurlHost string

murl string

initialToken string
initialCluster string

Expand Down Expand Up @@ -185,6 +187,9 @@ type etcdProcessClusterConfig struct {
initialToken string
quotaBackendBytes int64
noStrictReconfig bool

metricsURL bool
insecureMetricsURL bool
}

// newEtcdProcessCluster launches a new cluster from etcd processes, returning
Expand Down Expand Up @@ -266,7 +271,7 @@ func (cfg *etcdProcessClusterConfig) etcdProcessConfigs() []*etcdProcessConfig {
for i := 0; i < cfg.clusterSize; i++ {
var curls []string
var curl, curltls string
port := cfg.basePort + 2*i
port := cfg.basePort + 3*i
curlHost := fmt.Sprintf("localhost:%d", port)

switch cfg.clientTLS {
Expand Down Expand Up @@ -312,6 +317,15 @@ func (cfg *etcdProcessClusterConfig) etcdProcessConfigs() []*etcdProcessConfig {
if cfg.noStrictReconfig {
args = append(args, "--strict-reconfig-check=false")
}
var murl string
if cfg.metricsURL {
scheme, mhost := 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] = &etcdProcessConfig{
Expand All @@ -324,11 +338,12 @@ func (cfg *etcdProcessClusterConfig) etcdProcessConfigs() []*etcdProcessConfig {
acurl: curl,
acurltls: curltls,
acurlHost: curlHost,
murl: murl,
initialToken: cfg.initialToken,
}
}
for i := 0; i < cfg.proxySize; i++ {
port := cfg.basePort + 2*cfg.clusterSize + i + 1
port := cfg.basePort + 3*cfg.clusterSize + i + 1
curlHost := fmt.Sprintf("localhost:%d", port)
curl := url.URL{Scheme: clientScheme, Host: curlHost}
name := fmt.Sprintf("testname-proxy%d", i)
Expand Down
5 changes: 5 additions & 0 deletions e2e/v2_curl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ type cURLReq struct {
value string
expected string
header string

metricsURL bool
}

// cURLPrefixArgs builds the beginning of a curl command for a given key
Expand All @@ -146,6 +148,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)].cfg.murl
}
ep := acurl + req.endpoint

if req.username != "" || req.password != "" {
Expand Down
24 changes: 24 additions & 0 deletions e2e/v3_curl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit a731fb1

Please sign in to comment.