Skip to content

Commit

Permalink
e2e: test /metrics endpoints with health information
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 22, 2017
1 parent 695e325 commit f44e6c6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
15 changes: 14 additions & 1 deletion e2e/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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{
Expand All @@ -232,6 +244,7 @@ func (cfg *etcdProcessClusterConfig) etcdServerProcessConfigs() []*etcdServerPro
name: name,
purl: purl,
acurl: curl,
murl: murl,
initialToken: cfg.initialToken,
}
}
Expand Down
7 changes: 5 additions & 2 deletions e2e/etcd_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -57,6 +58,7 @@ type etcdServerProcessConfig struct {
purl url.URL

acurl string
murl string

initialToken string
initialCluster string
Expand All @@ -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 {
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 @@ -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
Expand All @@ -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 != "" {
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 f44e6c6

Please sign in to comment.