Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e2e: make sure ALS server is ready #3816

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading