From 418dd6e26ce11d7c69edb38457f856d4e92012a9 Mon Sep 17 00:00:00 2001 From: hejianpeng Date: Tue, 27 Jun 2023 14:18:09 +0800 Subject: [PATCH] e2e: improve accesslog tests Signed-off-by: hejianpeng --- .../{accesslog.yaml => accesslog-file.yaml} | 4 +- test/e2e/testdata/accesslog-otel.yaml | 16 +++++++ test/e2e/tests/accesslog.go | 46 +++++++------------ 3 files changed, 34 insertions(+), 32 deletions(-) rename test/e2e/testdata/{accesslog.yaml => accesslog-file.yaml} (85%) create mode 100644 test/e2e/testdata/accesslog-otel.yaml diff --git a/test/e2e/testdata/accesslog.yaml b/test/e2e/testdata/accesslog-file.yaml similarity index 85% rename from test/e2e/testdata/accesslog.yaml rename to test/e2e/testdata/accesslog-file.yaml index aafce06fcf..18d164fc60 100644 --- a/test/e2e/testdata/accesslog.yaml +++ b/test/e2e/testdata/accesslog-file.yaml @@ -1,7 +1,7 @@ apiVersion: gateway.networking.k8s.io/v1beta1 kind: HTTPRoute metadata: - name: http-infra-backend-v1 + name: accesslog-file namespace: gateway-conformance-infra spec: parentRefs: @@ -10,7 +10,7 @@ spec: - matches: - path: type: PathPrefix - value: / + value: /file backendRefs: - name: infra-backend-v1 port: 8080 diff --git a/test/e2e/testdata/accesslog-otel.yaml b/test/e2e/testdata/accesslog-otel.yaml new file mode 100644 index 0000000000..8f9e492408 --- /dev/null +++ b/test/e2e/testdata/accesslog-otel.yaml @@ -0,0 +1,16 @@ +apiVersion: gateway.networking.k8s.io/v1beta1 +kind: HTTPRoute +metadata: + name: accesslog-otel + namespace: gateway-conformance-infra +spec: + parentRefs: + - name: same-namespace + rules: + - matches: + - path: + type: PathPrefix + value: /otel + backendRefs: + - name: infra-backend-v2 + port: 8080 diff --git a/test/e2e/tests/accesslog.go b/test/e2e/tests/accesslog.go index 4e51cd48b2..9efe5f0d61 100644 --- a/test/e2e/tests/accesslog.go +++ b/test/e2e/tests/accesslog.go @@ -35,24 +35,25 @@ func init() { var FileAccessLogTest = suite.ConformanceTest{ ShortName: "FileAccessLog", Description: "Make sure file access log is working", - Manifests: []string{"testdata/accesslog.yaml"}, + Manifests: []string{"testdata/accesslog-file.yaml"}, Test: func(t *testing.T, suite *suite.ConformanceTestSuite) { t.Run("Stdout", func(t *testing.T) { ns := "gateway-conformance-infra" - routeNN := types.NamespacedName{Name: "http-infra-backend-v1", Namespace: ns} + routeNN := types.NamespacedName{Name: "accesslog-file", Namespace: ns} gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns} gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN) - // make sure listener is ready - httputils.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, httputils.ExpectedResponse{ + expectedResponse := httputils.ExpectedResponse{ Request: httputils.Request{ - Path: "/", + Path: "/file", }, Response: httputils.Response{ StatusCode: 200, }, Namespace: ns, - }) + } + // make sure listener is ready + httputils.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, expectedResponse) labels := map[string]string{ "job": "fluentbit", @@ -90,15 +91,7 @@ var FileAccessLogTest = suite.ConformanceTest{ return false, nil } - httputils.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, httputils.ExpectedResponse{ - Request: httputils.Request{ - Path: "/", - }, - Response: httputils.Response{ - StatusCode: 200, - }, - Namespace: ns, - }) + httputils.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, expectedResponse) // it will take some time for fluent-bit to collect the log and send to loki // let's wait for a while @@ -133,24 +126,25 @@ var FileAccessLogTest = suite.ConformanceTest{ var OpenTelemetryTest = suite.ConformanceTest{ ShortName: "OpenTelemetryAccessLog", Description: "Make sure OpenTelemetry access log is working", - Manifests: []string{"testdata/accesslog.yaml"}, + Manifests: []string{"testdata/accesslog-otel.yaml"}, Test: func(t *testing.T, suite *suite.ConformanceTestSuite) { t.Run("OTel", func(t *testing.T) { ns := "gateway-conformance-infra" - routeNN := types.NamespacedName{Name: "http-infra-backend-v1", Namespace: ns} + routeNN := types.NamespacedName{Name: "accesslog-otel", Namespace: ns} gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns} gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN) - // make sure listener is ready - httputils.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, httputils.ExpectedResponse{ + expectedResponse := httputils.ExpectedResponse{ Request: httputils.Request{ - Path: "/", + Path: "/otel", }, Response: httputils.Response{ StatusCode: 200, }, Namespace: ns, - }) + } + // make sure listener is ready + httputils.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, expectedResponse) labels := map[string]string{ "k8s_namespace_name": "envoy-gateway-system", @@ -167,15 +161,7 @@ var OpenTelemetryTest = suite.ConformanceTest{ return false, nil } - httputils.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, httputils.ExpectedResponse{ - Request: httputils.Request{ - Path: "/", - }, - Response: httputils.Response{ - StatusCode: 200, - }, - Namespace: ns, - }) + httputils.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, expectedResponse) if err := wait.PollUntilContextTimeout(ctx, 500*time.Millisecond, 10*time.Second, true, func(_ context.Context) (bool, error) { count, err := QueryLogCountFromLoki(t, suite.Client, types.NamespacedName{