From fc89ea42ee0d60cd8f6c31496c743c1c441e8792 Mon Sep 17 00:00:00 2001 From: zirain Date: Thu, 11 Jul 2024 19:56:09 +0800 Subject: [PATCH] e2e: make sure ALS server is ready (#3816) Signed-off-by: zirain --- test/e2e/tests/accesslog.go | 23 +++++++++++++++++++++-- test/e2e/tests/utils.go | 8 ++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/test/e2e/tests/accesslog.go b/test/e2e/tests/accesslog.go index b0de4543cb7f..1fecc669c340 100644 --- a/test/e2e/tests/accesslog.go +++ b/test/e2e/tests/accesslog.go @@ -152,7 +152,22 @@ var ALSTest = suite.ConformanceTest{ routeNN := types.NamespacedName{Name: "accesslog-als", Namespace: ns} gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns} gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN) - preCount := ALSLogCount(t, suite) + + preCount := 0 + // make sure ALS server metric endpoint is ready + if err := wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute, true, + func(ctx context.Context) (bool, error) { + curCount, err := ALSLogCount(suite) + if err != nil { + t.Logf("failed to get log count from loki: %v", err) + return false, nil + } + preCount = curCount + return true, nil + }); err != nil { + t.Errorf("failed to get log count from loki: %v", err) + } + expectedResponse := httputils.ExpectedResponse{ Request: httputils.Request{ Path: "/als", @@ -170,7 +185,11 @@ var ALSTest = suite.ConformanceTest{ if err := wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute, true, func(ctx context.Context) (bool, error) { - curCount := ALSLogCount(t, suite) + curCount, err := ALSLogCount(suite) + if err != nil { + t.Logf("failed to get log count from loki: %v", err) + return false, nil + } return preCount < curCount, nil }); err != nil { t.Errorf("failed to get log count from loki: %v", err) diff --git a/test/e2e/tests/utils.go b/test/e2e/tests/utils.go index b29d2b48d0d3..4ee2dbebcf7f 100644 --- a/test/e2e/tests/utils.go +++ b/test/e2e/tests/utils.go @@ -369,18 +369,18 @@ func WaitForLoadBalancerAddress(t *testing.T, client client.Client, timeout time return ipAddr, nil } -func ALSLogCount(t *testing.T, suite *suite.ConformanceTestSuite) int { +func ALSLogCount(suite *suite.ConformanceTestSuite) (int, error) { metricPath, err := RetrieveURL(suite.Client, types.NamespacedName{ Namespace: "monitoring", Name: "envoy-als", }, 19001, "/metrics") if err != nil { - t.Fatalf("failed to get metric url: %v", err) + return -1, err } countMetric, err := RetrieveMetric(metricPath, "log_count", time.Second) if err != nil { - t.Fatalf("failed to get metric: %v", err) + return -1, err } total := 0 @@ -390,7 +390,7 @@ func ALSLogCount(t *testing.T, suite *suite.ConformanceTestSuite) int { } } - return total + return total, nil } // QueryLogCountFromLoki queries log count from loki