Skip to content

Commit

Permalink
feat(logger): Add tlog for better test logging (#3913)
Browse files Browse the repository at this point in the history
Add tlog.Logf() logger

Signed-off-by: Manoramsharma <img_2020037@iiitm.ac.in>
  • Loading branch information
Manoramsharma authored Jul 21, 2024
1 parent 7c080fe commit a2e9bb5
Show file tree
Hide file tree
Showing 19 changed files with 92 additions and 75 deletions.
7 changes: 4 additions & 3 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
"sigs.k8s.io/gateway-api/conformance/utils/flags"
"sigs.k8s.io/gateway-api/conformance/utils/suite"
"sigs.k8s.io/gateway-api/conformance/utils/tlog"
"sigs.k8s.io/gateway-api/pkg/features"

"github.com/envoyproxy/gateway/test/e2e/tests"
Expand All @@ -28,10 +29,10 @@ func TestE2E(t *testing.T) {
c := kubetest.NewClient(t)

if flags.RunTest != nil && *flags.RunTest != "" {
t.Logf("Running E2E test %s with %s GatewayClass\n cleanup: %t\n debug: %t",
tlog.Logf(t, "Running E2E test %s with %s GatewayClass\n cleanup: %t\n debug: %t",
*flags.RunTest, *flags.GatewayClassName, *flags.CleanupBaseResources, *flags.ShowDebug)
} else {
t.Logf("Running E2E tests with %s GatewayClass\n cleanup: %t\n debug: %t",
tlog.Logf(t, "Running E2E tests with %s GatewayClass\n cleanup: %t\n debug: %t",
*flags.GatewayClassName, *flags.CleanupBaseResources, *flags.ShowDebug)
}

Expand All @@ -54,7 +55,7 @@ func TestE2E(t *testing.T) {
}

cSuite.Setup(t, tests.ConformanceTests)
t.Logf("Running %d E2E tests", len(tests.ConformanceTests))
tlog.Logf(t, "Running %d E2E tests", len(tests.ConformanceTests))
err = cSuite.Run(t, tests.ConformanceTests)
if err != nil {
t.Fatalf("Failed to run E2E tests: %v", err)
Expand Down
7 changes: 4 additions & 3 deletions test/e2e/merge_gateways/merge_gateways_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"sigs.k8s.io/gateway-api/conformance/utils/flags"
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
"sigs.k8s.io/gateway-api/conformance/utils/suite"
"sigs.k8s.io/gateway-api/conformance/utils/tlog"
"sigs.k8s.io/gateway-api/pkg/features"

"github.com/envoyproxy/gateway/test/e2e"
Expand All @@ -30,10 +31,10 @@ func TestMergeGateways(t *testing.T) {
c := kubetest.NewClient(t)

if flags.RunTest != nil && *flags.RunTest != "" {
t.Logf("Running E2E test %s with %s GatewayClass\n cleanup: %t\n debug: %t",
tlog.Logf(t, "Running E2E test %s with %s GatewayClass\n cleanup: %t\n debug: %t",
*flags.RunTest, *flags.GatewayClassName, *flags.CleanupBaseResources, *flags.ShowDebug)
} else {
t.Logf("Running E2E tests with %s GatewayClass\n cleanup: %t\n debug: %t",
tlog.Logf(t, "Running E2E tests with %s GatewayClass\n cleanup: %t\n debug: %t",
*flags.GatewayClassName, *flags.CleanupBaseResources, *flags.ShowDebug)
}

Expand All @@ -58,7 +59,7 @@ func TestMergeGateways(t *testing.T) {
cSuite.Applier.GatewayClass = *flags.GatewayClassName
cSuite.ControllerName = kubernetes.GWCMustHaveAcceptedConditionTrue(t, cSuite.Client, cSuite.TimeoutConfig, cSuite.GatewayClassName)

t.Logf("Running %d MergeGateways tests", len(tests.MergeGatewaysTests))
tlog.Logf(t, "Running %d MergeGateways tests", len(tests.MergeGatewaysTests))
err = cSuite.Run(t, tests.MergeGatewaysTests)
if err != nil {
t.Fatalf("Failed to run MergeGateways tests: %v", err)
Expand Down
9 changes: 5 additions & 4 deletions test/e2e/multiple_gc/multiple_gc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"sigs.k8s.io/gateway-api/conformance/utils/flags"
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
"sigs.k8s.io/gateway-api/conformance/utils/suite"
"sigs.k8s.io/gateway-api/conformance/utils/tlog"
"sigs.k8s.io/gateway-api/pkg/features"

"github.com/envoyproxy/gateway/test/e2e"
Expand All @@ -30,10 +31,10 @@ func TestMultipleGC(t *testing.T) {
c := kubetest.NewClient(t)

if flags.RunTest != nil && *flags.RunTest != "" {
t.Logf("Running E2E test %s with %s GatewayClass\n cleanup: %t\n debug: %t",
tlog.Logf(t, "Running E2E test %s with %s GatewayClass\n cleanup: %t\n debug: %t",
*flags.RunTest, *flags.GatewayClassName, *flags.CleanupBaseResources, *flags.ShowDebug)
} else {
t.Logf("Running E2E tests with %s GatewayClass\n cleanup: %t\n debug: %t",
tlog.Logf(t, "Running E2E tests with %s GatewayClass\n cleanup: %t\n debug: %t",
*flags.GatewayClassName, *flags.CleanupBaseResources, *flags.ShowDebug)
}

Expand Down Expand Up @@ -61,7 +62,7 @@ func TestMultipleGC(t *testing.T) {
internetGatewaySuite.Applier.GatewayClass = internetGatewaySuiteGatewayClassName
internetGatewaySuite.ControllerName = kubernetes.GWCMustHaveAcceptedConditionTrue(t, internetGatewaySuite.Client, internetGatewaySuite.TimeoutConfig, internetGatewaySuite.GatewayClassName)

t.Logf("Running %d MultipleGC tests", len(tests.MultipleGCTests[internetGatewaySuiteGatewayClassName]))
tlog.Logf(t, "Running %d MultipleGC tests", len(tests.MultipleGCTests[internetGatewaySuiteGatewayClassName]))

err = internetGatewaySuite.Run(t, tests.MultipleGCTests[internetGatewaySuiteGatewayClassName])
if err != nil {
Expand Down Expand Up @@ -93,7 +94,7 @@ func TestMultipleGC(t *testing.T) {
privateGatewaySuite.Applier.GatewayClass = privateGatewaySuiteGatewayClassName
privateGatewaySuite.ControllerName = kubernetes.GWCMustHaveAcceptedConditionTrue(t, privateGatewaySuite.Client, privateGatewaySuite.TimeoutConfig, privateGatewaySuite.GatewayClassName)

t.Logf("Running %d MultipleGC tests", len(tests.MultipleGCTests[privateGatewaySuiteGatewayClassName]))
tlog.Logf(t, "Running %d MultipleGC tests", len(tests.MultipleGCTests[privateGatewaySuiteGatewayClassName]))
err = privateGatewaySuite.Run(t, tests.MultipleGCTests[privateGatewaySuiteGatewayClassName])
if err != nil {
t.Fatalf("Failed to run PrivateGC tests: %v", err)
Expand Down
11 changes: 6 additions & 5 deletions test/e2e/tests/accesslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
httputils "sigs.k8s.io/gateway-api/conformance/utils/http"
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
"sigs.k8s.io/gateway-api/conformance/utils/suite"
"sigs.k8s.io/gateway-api/conformance/utils/tlog"
)

func init() {
Expand Down Expand Up @@ -159,7 +160,7 @@ var ALSTest = suite.ConformanceTest{
func(ctx context.Context) (bool, error) {
curCount, err := ALSLogCount(suite)
if err != nil {
t.Logf("failed to get log count from loki: %v", err)
tlog.Logf(t, "failed to get log count from loki: %v", err)
return false, nil
}
preCount = curCount
Expand Down Expand Up @@ -187,7 +188,7 @@ var ALSTest = suite.ConformanceTest{
func(ctx context.Context) (bool, error) {
curCount, err := ALSLogCount(suite)
if err != nil {
t.Logf("failed to get log count from loki: %v", err)
tlog.Logf(t, "failed to get log count from loki: %v", err)
return false, nil
}
return preCount < curCount, nil
Expand All @@ -206,7 +207,7 @@ func runLogTest(t *testing.T, suite *suite.ConformanceTestSuite, gwAddr string,
// query log count from loki
preCount, err := QueryLogCountFromLoki(t, suite.Client, expectedLabels, expectedMatch)
if err != nil {
t.Logf("failed to get log count from loki: %v", err)
tlog.Logf(t, "failed to get log count from loki: %v", err)
return false, nil
}

Expand All @@ -217,7 +218,7 @@ func runLogTest(t *testing.T, suite *suite.ConformanceTestSuite, gwAddr string,
if err := wait.PollUntilContextTimeout(ctx, 500*time.Millisecond, 15*time.Second, true, func(_ context.Context) (bool, error) {
count, err := QueryLogCountFromLoki(t, suite.Client, expectedLabels, expectedMatch)
if err != nil {
t.Logf("failed to get log count from loki: %v", err)
tlog.Logf(t, "failed to get log count from loki: %v", err)
return false, nil
}

Expand All @@ -226,7 +227,7 @@ func runLogTest(t *testing.T, suite *suite.ConformanceTestSuite, gwAddr string,
return true, nil
}

t.Logf("preCount=%d, count=%d", preCount, count)
tlog.Logf(t, "preCount=%d, count=%d", preCount, count)
return false, nil
}); err != nil {
return false, nil
Expand Down
5 changes: 3 additions & 2 deletions test/e2e/tests/backend_health_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"sigs.k8s.io/gateway-api/conformance/utils/http"
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
"sigs.k8s.io/gateway-api/conformance/utils/suite"
"sigs.k8s.io/gateway-api/conformance/utils/tlog"

"github.com/envoyproxy/gateway/internal/gatewayapi"
"github.com/envoyproxy/gateway/test/utils/prometheus"
Expand Down Expand Up @@ -77,7 +78,7 @@ var BackendHealthCheckActiveHTTPTest = suite.ConformanceTest{
// wait until Prometheus sync stats
return false
}
t.Logf("cluster pass health check: success stats query count: %v", v)
tlog.Logf(t, "cluster pass health check: success stats query count: %v", v)

if v == 0 {
t.Error("success is not the same as expected")
Expand All @@ -100,7 +101,7 @@ var BackendHealthCheckActiveHTTPTest = suite.ConformanceTest{
// wait until Prometheus sync stats
return false
}
t.Logf("cluster fail health check: failure stats query count: %v", v)
tlog.Logf(t, "cluster fail health check: failure stats query count: %v", v)

if v == 0 {
t.Error("failure is not same as expected")
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/tests/client_timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
httputils "sigs.k8s.io/gateway-api/conformance/utils/http"
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
"sigs.k8s.io/gateway-api/conformance/utils/suite"
"sigs.k8s.io/gateway-api/conformance/utils/tlog"
)

func init() {
Expand Down Expand Up @@ -58,7 +59,7 @@ var ClientTimeoutTest = suite.ConformanceTest{
if http.StatusGatewayTimeout == resp.StatusCode {
return true
} else {
t.Logf("response status code: %d, (after %v) ", resp.StatusCode, elapsed)
tlog.Logf(t, "response status code: %d, (after %v) ", resp.StatusCode, elapsed)
return false
}
})
Expand Down
7 changes: 4 additions & 3 deletions test/e2e/tests/connection_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"sigs.k8s.io/gateway-api/conformance/utils/http"
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
"sigs.k8s.io/gateway-api/conformance/utils/suite"
"sigs.k8s.io/gateway-api/conformance/utils/tlog"

"github.com/envoyproxy/gateway/internal/gatewayapi"
"github.com/envoyproxy/gateway/test/utils/prometheus"
Expand Down Expand Up @@ -63,7 +64,7 @@ var ConnectionLimitTest = suite.ConformanceTest{
func(_ context.Context) (done bool, err error) {
_, err = net.DialTimeout("tcp", gwAddr, 100*time.Millisecond)
if err != nil {
t.Logf("failed to open connection: %v", err)
tlog.Logf(t, "failed to open connection: %v", err)
return false, nil
}
t.Log("opened connection 1")
Expand All @@ -75,7 +76,7 @@ var ConnectionLimitTest = suite.ConformanceTest{
// Open the remaining 5 connections
for i := 1; i < 6; i++ {
conn, err := net.Dial("tcp", gwAddr)
t.Logf("opened connection %d", i+1)
tlog.Logf(t, "opened connection %d", i+1)
if err != nil {
t.Errorf("failed to open connection: %v", err)
} else {
Expand All @@ -98,7 +99,7 @@ var ConnectionLimitTest = suite.ConformanceTest{
// wait until Prometheus sync stats
return false
}
t.Logf("connection_limit stats query count: %v", v)
tlog.Logf(t, "connection_limit stats query count: %v", v)

// connection interruptions or other connection errors may occur
// we just need to determine whether there is a connection limit stats
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/tests/controlplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"sigs.k8s.io/gateway-api/conformance/utils/suite"
"sigs.k8s.io/gateway-api/conformance/utils/tlog"
)

func init() {
Expand Down Expand Up @@ -64,7 +65,7 @@ var ControlPlaneMetricTest = suite.ConformanceTest{
if err := wait.PollUntilContextTimeout(context.TODO(), time.Second, 2*time.Minute, true,
func(_ context.Context) (done bool, err error) {
if err := ScrapeMetrics(t, suite.Client, nn, 19001, "/metrics"); err != nil {
t.Logf("failed to get metric: %v", err)
tlog.Logf(t, "failed to get metric: %v", err)
return false, nil
}
return true, nil
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/tests/eg_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func cleanUpResources(c client.Client, t *testing.T) {
}

for _, o := range list.Items {
t.Logf("deleting %s: %s/%s", o.GetObjectKind(), o.GetNamespace(), o.GetName())
tlog.Logf(t, "deleting %s: %s/%s", o.GetObjectKind(), o.GetNamespace(), o.GetName())
if err := c.Delete(context.Background(), &o); err != nil {
if !kerrors.IsNotFound(err) {
t.Fatalf("error deleting %s: %s/%s : %v", o.GetObjectKind(), o.GetNamespace(), o.GetName(), err)
Expand All @@ -192,7 +192,7 @@ func cleanUpResources(c client.Client, t *testing.T) {
}

if len(list.Items) > 0 {
t.Logf("Waiting for deletion of %d %s", len(list.Items), gvk.String())
tlog.Logf(t, "Waiting for deletion of %d %s", len(list.Items), gvk.String())
return false, nil
}

Expand Down
5 changes: 3 additions & 2 deletions test/e2e/tests/load_balancing.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
"sigs.k8s.io/gateway-api/conformance/utils/roundtripper"
"sigs.k8s.io/gateway-api/conformance/utils/suite"
"sigs.k8s.io/gateway-api/conformance/utils/tlog"

"github.com/envoyproxy/gateway/internal/gatewayapi"
)
Expand Down Expand Up @@ -364,7 +365,7 @@ var ConsistentHashCookieLoadBalancingTest = suite.ConformanceTest{
return true, nil
}

t.Logf("Cookie have not been generated yet")
tlog.Logf(t, "Cookie have not been generated yet")
return false, nil
})
require.NoError(t, waitErr)
Expand All @@ -387,7 +388,7 @@ func WaitDeployment(t *testing.T, cli client.Client, name types.NamespacedName,
return true, nil
}

t.Logf("Deployment not yet accepted: %s", name.String())
tlog.Logf(t, "Deployment not yet accepted: %s", name.String())
return false, nil
})

Expand Down
5 changes: 3 additions & 2 deletions test/e2e/tests/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
httputils "sigs.k8s.io/gateway-api/conformance/utils/http"
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
"sigs.k8s.io/gateway-api/conformance/utils/suite"
"sigs.k8s.io/gateway-api/conformance/utils/tlog"
)

func init() {
Expand Down Expand Up @@ -54,7 +55,7 @@ var MetricTest = suite.ConformanceTest{
Namespace: "envoy-gateway-system",
Name: "same-namespace-gw-metrics",
}, 19001, "/stats/prometheus"); err != nil {
t.Logf("failed to get metric: %v", err)
tlog.Logf(t, "failed to get metric: %v", err)
return false, nil
}
return true, nil
Expand Down Expand Up @@ -88,7 +89,7 @@ var MetricTest = suite.ConformanceTest{
Namespace: "monitoring",
Name: "otel-collecot-prometheus",
}, 19001, "/metrics"); err != nil {
t.Logf("failed to get metric: %v", err)
tlog.Logf(t, "failed to get metric: %v", err)
return false, nil
}
return true, nil
Expand Down
5 changes: 3 additions & 2 deletions test/e2e/tests/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
gwhttp "sigs.k8s.io/gateway-api/conformance/utils/http"
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
"sigs.k8s.io/gateway-api/conformance/utils/suite"
"sigs.k8s.io/gateway-api/conformance/utils/tlog"

"github.com/envoyproxy/gateway/internal/gatewayapi"
)
Expand Down Expand Up @@ -80,7 +81,7 @@ var OIDCTest = suite.ConformanceTest{

if err := wait.PollUntilContextTimeout(context.TODO(), time.Second, 5*time.Minute, true,
func(_ context.Context) (done bool, err error) {
t.Logf("sending request to %s", testURL)
tlog.Logf(t, "sending request to %s", testURL)

// Send a request to the http route with OIDC configured.
// It will be redirected to the keycloak login page
Expand All @@ -90,7 +91,7 @@ var OIDCTest = suite.ConformanceTest{

// Parse the response body to get the URL where the login page would post the user-entered credentials
if err := client.ParseLoginForm(res.Body, keyCloakLoginFormID); err != nil {
t.Logf("failed to parse login form: %v", err)
tlog.Logf(t, "failed to parse login form: %v", err)
return false, nil
}

Expand Down
5 changes: 3 additions & 2 deletions test/e2e/tests/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"sigs.k8s.io/gateway-api/conformance/utils/http"
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
"sigs.k8s.io/gateway-api/conformance/utils/suite"
"sigs.k8s.io/gateway-api/conformance/utils/tlog"

"github.com/envoyproxy/gateway/test/utils/prometheus"
)
Expand Down Expand Up @@ -60,7 +61,7 @@ var RetryTest = suite.ConformanceTest{
if err == nil {
before = v
}
t.Logf("query count %s before: %v", promQL, before)
tlog.Logf(t, "query count %s before: %v", promQL, before)

req := http.MakeRequest(t, &expectedResponse, gwAddr, "HTTP", "http")
cReq, cResp, err := suite.RoundTripper.CaptureRoundTrip(req)
Expand All @@ -81,7 +82,7 @@ var RetryTest = suite.ConformanceTest{
if err != nil {
return false
}
t.Logf("query count %s after: %v", promQL, v)
tlog.Logf(t, "query count %s after: %v", promQL, v)

delta := int64(v - before)
// numRetries is 5, so delta mod 5 equals 0
Expand Down
5 changes: 3 additions & 2 deletions test/e2e/tests/tcp_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"sigs.k8s.io/gateway-api/conformance/utils/http"
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
"sigs.k8s.io/gateway-api/conformance/utils/suite"
"sigs.k8s.io/gateway-api/conformance/utils/tlog"
)

func init() {
Expand Down Expand Up @@ -85,7 +86,7 @@ func GatewayAndTCPRoutesMustBeAccepted(t *testing.T, c client.Client, timeoutCon
tcpRoute := &gwapiv1a2.TCPRoute{}
err := c.Get(context.Background(), routeNNs[0], tcpRoute)
if err != nil {
t.Logf("error fetching TCPRoute: %v", err)
tlog.Logf(t, "error fetching TCPRoute: %v", err)
}

gwAddr, err := WaitForGatewayAddress(t, c, timeoutConfig, gw.NamespacedName, string(*tcpRoute.Spec.ParentRefs[0].SectionName))
Expand Down Expand Up @@ -134,7 +135,7 @@ func WaitForGatewayAddress(t *testing.T, client client.Client, timeoutConfig con
gw := &gwapiv1.Gateway{}
err := client.Get(ctx, gwName, gw)
if err != nil {
t.Logf("error fetching Gateway: %v", err)
tlog.Logf(t, "error fetching Gateway: %v", err)
return false, fmt.Errorf("error fetching Gateway: %w", err)
}

Expand Down
Loading

0 comments on commit a2e9bb5

Please sign in to comment.