Skip to content

Commit

Permalink
e2e: make sure ALS server is ready (envoyproxy#3816)
Browse files Browse the repository at this point in the history
Signed-off-by: zirain <[email protected]>
  • Loading branch information
zirain authored and guydc committed Jul 22, 2024
1 parent d538ca7 commit 98ef802
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
23 changes: 21 additions & 2 deletions test/e2e/tests/accesslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -390,7 +390,7 @@ func ALSLogCount(t *testing.T, suite *suite.ConformanceTestSuite) int {
}
}

return total
return total, nil
}

// QueryLogCountFromLoki queries log count from loki
Expand Down

0 comments on commit 98ef802

Please sign in to comment.