From 7d0be43bd6dc3d7c8b67a6cd3fe9b8e323da97d3 Mon Sep 17 00:00:00 2001 From: Lujie Duan Date: Tue, 15 Aug 2023 15:26:20 +0000 Subject: [PATCH 1/2] Add test to check health check error message on reboot --- integration_test/ops_agent_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/integration_test/ops_agent_test.go b/integration_test/ops_agent_test.go index 7a3929bd14..06a42eed1e 100644 --- a/integration_test/ops_agent_test.go +++ b/integration_test/ops_agent_test.go @@ -4144,6 +4144,36 @@ func TestNoNvmlOtelReceiverWithoutGpu(t *testing.T) { }) } +// TestNoHealthCheckNetworkErrorAfterRestartVM +func TestNoHealthCheckNetworkErrorAfterRestartVM(t *testing.T) { + t.Parallel() + gce.RunForEachPlatform(t, func(t *testing.T, platform string) { + t.Parallel() + + ctx, logger, vm := agents.CommonSetup(t, platform) + if err := agents.SetupOpsAgent(ctx, logger.ToMainLog(), vm, ""); err != nil { + t.Fatal(err) + } + + time.Sleep(60 * time.Second) + _, err := gce.QueryLog(ctx, logger.ToMainLog(), vm, "ops-agent-health", time.Hour, `jsonPayload.message=~"[Network Check] Result: ERROR"`, 5) + if err == nil { + t.Error("expected no logs to contain health check errors") + } else if !strings.Contains(err.Error(), "not found, exhausted retries") { + t.Fatalf("unexpected error: %v", err) + } + + gce.RestartInstance(ctx, logger, vm) + time.Sleep(60 * time.Second) + _, err = gce.QueryLog(ctx, logger.ToMainLog(), vm, "ops-agent-health", time.Hour, `jsonPayload.message=~"[Network Check] Result: ERROR"`, 5) + if err == nil { + t.Error("expected no logs to contain health check errors after reboot") + } else if !strings.Contains(err.Error(), "not found, exhausted retries") { + t.Fatalf("unexpected error: %v", err) + } + }) +} + func TestMain(m *testing.M) { code := m.Run() gce.CleanupKeysOrDie() From 96bcd2933018d8a7645382e9224f65054aba4c29 Mon Sep 17 00:00:00 2001 From: Lujie Duan Date: Tue, 15 Aug 2023 18:13:14 +0000 Subject: [PATCH 2/2] Fix message pattern --- integration_test/ops_agent_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_test/ops_agent_test.go b/integration_test/ops_agent_test.go index 06a42eed1e..0dc7289366 100644 --- a/integration_test/ops_agent_test.go +++ b/integration_test/ops_agent_test.go @@ -4156,7 +4156,7 @@ func TestNoHealthCheckNetworkErrorAfterRestartVM(t *testing.T) { } time.Sleep(60 * time.Second) - _, err := gce.QueryLog(ctx, logger.ToMainLog(), vm, "ops-agent-health", time.Hour, `jsonPayload.message=~"[Network Check] Result: ERROR"`, 5) + _, err := gce.QueryLog(ctx, logger.ToMainLog(), vm, "ops-agent-health", time.Hour, `jsonPayload.message=~"\[Network Check\] Result: ERROR"`, 5) if err == nil { t.Error("expected no logs to contain health check errors") } else if !strings.Contains(err.Error(), "not found, exhausted retries") {