Skip to content

Commit

Permalink
Retry tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris S. Kim committed Oct 5, 2023
1 parent ad26494 commit d157d93
Showing 1 changed file with 30 additions and 39 deletions.
69 changes: 30 additions & 39 deletions agent/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/hashicorp/consul/agent/rpc/middleware"
"github.com/hashicorp/consul/lib/retry"
"github.com/hashicorp/consul/sdk/testutil"
testretry "github.com/hashicorp/consul/sdk/testutil/retry"
"github.com/hashicorp/consul/testrpc"
"github.com/hashicorp/consul/tlsutil"
)
Expand All @@ -30,8 +31,7 @@ func skipIfShortTesting(t *testing.T) {
}
}

func recordPromMetrics(t *testing.T, a *TestAgent, respRec *httptest.ResponseRecorder) {
t.Helper()
func recordPromMetrics(t require.TestingT, a *TestAgent, respRec *httptest.ResponseRecorder) {
req, err := http.NewRequest("GET", "/v1/agent/metrics?format=prometheus", nil)
require.NoError(t, err, "Failed to generate new http request.")

Expand Down Expand Up @@ -483,28 +483,24 @@ func TestHTTPHandlers_AgentMetrics_WAL_Prometheus(t *testing.T) {
defer a.Shutdown()
testrpc.WaitForLeader(t, a.RPC, "dc1")

respRec := httptest.NewRecorder()
recordPromMetrics(t, a, respRec)
testretry.Run(t, func(r *testretry.R) {
respRec := httptest.NewRecorder()
recordPromMetrics(r, a, respRec)

out := respRec.Body.String()
require.Contains(r, out, "agent_5_raft_wal_head_truncations")
require.Contains(r, out, "agent_5_raft_wal_last_segment_age_seconds")
require.Contains(r, out, "agent_5_raft_wal_log_appends")
require.Contains(r, out, "agent_5_raft_wal_log_entries_read")
require.Contains(r, out, "agent_5_raft_wal_log_entries_written")
require.Contains(r, out, "agent_5_raft_wal_log_entry_bytes_read")
require.Contains(r, out, "agent_5_raft_wal_log_entry_bytes_written")
require.Contains(r, out, "agent_5_raft_wal_segment_rotations")
require.Contains(r, out, "agent_5_raft_wal_stable_gets")
require.Contains(r, out, "agent_5_raft_wal_stable_sets")
require.Contains(r, out, "agent_5_raft_wal_tail_truncations")
})

out := respRec.Body.String()
defer func() {
if t.Failed() {
t.Log("--- Failed output START ---")
t.Log(out)
t.Log("--- Failed output END ---")
}
}()
require.Contains(t, out, "agent_5_raft_wal_head_truncations")
require.Contains(t, out, "agent_5_raft_wal_last_segment_age_seconds")
require.Contains(t, out, "agent_5_raft_wal_log_appends")
require.Contains(t, out, "agent_5_raft_wal_log_entries_read")
require.Contains(t, out, "agent_5_raft_wal_log_entries_written")
require.Contains(t, out, "agent_5_raft_wal_log_entry_bytes_read")
require.Contains(t, out, "agent_5_raft_wal_log_entry_bytes_written")
require.Contains(t, out, "agent_5_raft_wal_segment_rotations")
require.Contains(t, out, "agent_5_raft_wal_stable_gets")
require.Contains(t, out, "agent_5_raft_wal_stable_sets")
require.Contains(t, out, "agent_5_raft_wal_tail_truncations")
})

t.Run("server without WAL enabled emits no WAL metrics", func(t *testing.T) {
Expand Down Expand Up @@ -590,22 +586,17 @@ func TestHTTPHandlers_AgentMetrics_LogVerifier_Prometheus(t *testing.T) {
defer a.Shutdown()
testrpc.WaitForLeader(t, a.RPC, "dc1")

respRec := httptest.NewRecorder()
recordPromMetrics(t, a, respRec)

out := respRec.Body.String()
defer func() {
if t.Failed() {
t.Log("--- Failed output START ---")
t.Log(out)
t.Log("--- Failed output END ---")
}
}()
require.Contains(t, out, "agent_5_raft_logstore_verifier_checkpoints_written")
require.Contains(t, out, "agent_5_raft_logstore_verifier_dropped_reports")
require.Contains(t, out, "agent_5_raft_logstore_verifier_ranges_verified")
require.Contains(t, out, "agent_5_raft_logstore_verifier_read_checksum_failures")
require.Contains(t, out, "agent_5_raft_logstore_verifier_write_checksum_failures")
testretry.Run(t, func(r *testretry.R) {
respRec := httptest.NewRecorder()
recordPromMetrics(r, a, respRec)

out := respRec.Body.String()
require.Contains(r, out, "agent_5_raft_logstore_verifier_checkpoints_written")
require.Contains(r, out, "agent_5_raft_logstore_verifier_dropped_reports")
require.Contains(r, out, "agent_5_raft_logstore_verifier_ranges_verified")
require.Contains(r, out, "agent_5_raft_logstore_verifier_read_checksum_failures")
require.Contains(r, out, "agent_5_raft_logstore_verifier_write_checksum_failures")
})
})

t.Run("server with verifier disabled emits no extra metrics", func(t *testing.T) {
Expand Down

0 comments on commit d157d93

Please sign in to comment.