mirror of https://github.com/hashicorp/consul
update TestHTTPHandlers_AgentMetrics_LeaderShipMetrics to use 3 servers instead of 2 to allow quorom when leadership flails.
parent
11bcf521ae
commit
5dead1a10e
|
@ -229,6 +229,7 @@ func TestHTTPHandlers_AgentMetrics_LeaderShipMetrics(t *testing.T) {
|
||||||
t.Run("check that metric isLeader is set properly on server", func(t *testing.T) {
|
t.Run("check that metric isLeader is set properly on server", func(t *testing.T) {
|
||||||
metricsPrefix1 := getUniqueMetricsPrefix()
|
metricsPrefix1 := getUniqueMetricsPrefix()
|
||||||
metricsPrefix2 := getUniqueMetricsPrefix()
|
metricsPrefix2 := getUniqueMetricsPrefix()
|
||||||
|
metricsPrefix3 := getUniqueMetricsPrefix()
|
||||||
|
|
||||||
hcl1 := fmt.Sprintf(`
|
hcl1 := fmt.Sprintf(`
|
||||||
server = true
|
server = true
|
||||||
|
@ -248,15 +249,26 @@ func TestHTTPHandlers_AgentMetrics_LeaderShipMetrics(t *testing.T) {
|
||||||
}
|
}
|
||||||
`, metricsPrefix2)
|
`, metricsPrefix2)
|
||||||
|
|
||||||
|
hcl3 := fmt.Sprintf(`
|
||||||
|
server = true
|
||||||
|
telemetry = {
|
||||||
|
prometheus_retention_time = "25s",
|
||||||
|
disable_hostname = true
|
||||||
|
metrics_prefix = "%s"
|
||||||
|
}
|
||||||
|
`, metricsPrefix3)
|
||||||
|
|
||||||
overrides := `
|
overrides := `
|
||||||
bootstrap = false
|
bootstrap = false
|
||||||
bootstrap_expect = 2
|
bootstrap_expect = 3
|
||||||
`
|
`
|
||||||
|
|
||||||
s1 := StartTestAgent(t, TestAgent{Name: "s1", HCL: hcl1, Overrides: overrides})
|
s1 := StartTestAgent(t, TestAgent{Name: "s1", HCL: hcl1, Overrides: overrides})
|
||||||
s2 := StartTestAgent(t, TestAgent{Name: "s2", HCL: hcl2, Overrides: overrides})
|
s2 := StartTestAgent(t, TestAgent{Name: "s2", HCL: hcl2, Overrides: overrides})
|
||||||
|
s3 := StartTestAgent(t, TestAgent{Name: "s3", HCL: hcl3, Overrides: overrides})
|
||||||
defer s1.Shutdown()
|
defer s1.Shutdown()
|
||||||
defer s2.Shutdown()
|
defer s2.Shutdown()
|
||||||
|
defer s3.Shutdown()
|
||||||
|
|
||||||
// agent hasn't become a leader
|
// agent hasn't become a leader
|
||||||
retry.RunWith(retry.ThirtySeconds(), t, func(r *testretry.R) {
|
retry.RunWith(retry.ThirtySeconds(), t, func(r *testretry.R) {
|
||||||
|
@ -268,8 +280,11 @@ func TestHTTPHandlers_AgentMetrics_LeaderShipMetrics(t *testing.T) {
|
||||||
|
|
||||||
_, err := s2.JoinLAN([]string{s1.Config.SerfBindAddrLAN.String()}, nil)
|
_, err := s2.JoinLAN([]string{s1.Config.SerfBindAddrLAN.String()}, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
_, err = s3.JoinLAN([]string{s1.Config.SerfBindAddrLAN.String()}, nil)
|
||||||
|
require.NoError(t, err)
|
||||||
testrpc.WaitForLeader(t, s1.RPC, "dc1")
|
testrpc.WaitForLeader(t, s1.RPC, "dc1")
|
||||||
testrpc.WaitForLeader(t, s2.RPC, "dc1")
|
testrpc.WaitForLeader(t, s2.RPC, "dc1")
|
||||||
|
testrpc.WaitForLeader(t, s3.RPC, "dc1")
|
||||||
|
|
||||||
// Verify agent's isLeader metrics is 1
|
// Verify agent's isLeader metrics is 1
|
||||||
retry.RunWith(retry.ThirtySeconds(), t, func(r *testretry.R) {
|
retry.RunWith(retry.ThirtySeconds(), t, func(r *testretry.R) {
|
||||||
|
@ -281,7 +296,11 @@ func TestHTTPHandlers_AgentMetrics_LeaderShipMetrics(t *testing.T) {
|
||||||
recordPromMetrics(r, s2, respRec2)
|
recordPromMetrics(r, s2, respRec2)
|
||||||
found2 := strings.Contains(respRec2.Body.String(), metricsPrefix2+"_server_isLeader 1")
|
found2 := strings.Contains(respRec2.Body.String(), metricsPrefix2+"_server_isLeader 1")
|
||||||
|
|
||||||
require.True(r, found1 || found2, "leader server should have isLeader 1")
|
respRec3 := httptest.NewRecorder()
|
||||||
|
recordPromMetrics(r, s3, respRec3)
|
||||||
|
found3 := strings.Contains(respRec3.Body.String(), metricsPrefix3+"_server_isLeader 1")
|
||||||
|
|
||||||
|
require.True(r, found1 || found2 || found3, "leader server should have isLeader 1")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue