Skip to content

Commit 418dd6e

Browse files
author
hejianpeng
committed
e2e: improve accesslog tests
Signed-off-by: hejianpeng <[email protected]>
1 parent 278e02f commit 418dd6e

File tree

3 files changed

+34
-32
lines changed

3 files changed

+34
-32
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: gateway.networking.k8s.io/v1beta1
22
kind: HTTPRoute
33
metadata:
4-
name: http-infra-backend-v1
4+
name: accesslog-file
55
namespace: gateway-conformance-infra
66
spec:
77
parentRefs:
@@ -10,7 +10,7 @@ spec:
1010
- matches:
1111
- path:
1212
type: PathPrefix
13-
value: /
13+
value: /file
1414
backendRefs:
1515
- name: infra-backend-v1
1616
port: 8080
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: gateway.networking.k8s.io/v1beta1
2+
kind: HTTPRoute
3+
metadata:
4+
name: accesslog-otel
5+
namespace: gateway-conformance-infra
6+
spec:
7+
parentRefs:
8+
- name: same-namespace
9+
rules:
10+
- matches:
11+
- path:
12+
type: PathPrefix
13+
value: /otel
14+
backendRefs:
15+
- name: infra-backend-v2
16+
port: 8080

test/e2e/tests/accesslog.go

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,25 @@ func init() {
3535
var FileAccessLogTest = suite.ConformanceTest{
3636
ShortName: "FileAccessLog",
3737
Description: "Make sure file access log is working",
38-
Manifests: []string{"testdata/accesslog.yaml"},
38+
Manifests: []string{"testdata/accesslog-file.yaml"},
3939
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
4040
t.Run("Stdout", func(t *testing.T) {
4141
ns := "gateway-conformance-infra"
42-
routeNN := types.NamespacedName{Name: "http-infra-backend-v1", Namespace: ns}
42+
routeNN := types.NamespacedName{Name: "accesslog-file", Namespace: ns}
4343
gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns}
4444
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)
4545

46-
// make sure listener is ready
47-
httputils.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, httputils.ExpectedResponse{
46+
expectedResponse := httputils.ExpectedResponse{
4847
Request: httputils.Request{
49-
Path: "/",
48+
Path: "/file",
5049
},
5150
Response: httputils.Response{
5251
StatusCode: 200,
5352
},
5453
Namespace: ns,
55-
})
54+
}
55+
// make sure listener is ready
56+
httputils.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, expectedResponse)
5657

5758
labels := map[string]string{
5859
"job": "fluentbit",
@@ -90,15 +91,7 @@ var FileAccessLogTest = suite.ConformanceTest{
9091
return false, nil
9192
}
9293

93-
httputils.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, httputils.ExpectedResponse{
94-
Request: httputils.Request{
95-
Path: "/",
96-
},
97-
Response: httputils.Response{
98-
StatusCode: 200,
99-
},
100-
Namespace: ns,
101-
})
94+
httputils.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, expectedResponse)
10295

10396
// it will take some time for fluent-bit to collect the log and send to loki
10497
// let's wait for a while
@@ -133,24 +126,25 @@ var FileAccessLogTest = suite.ConformanceTest{
133126
var OpenTelemetryTest = suite.ConformanceTest{
134127
ShortName: "OpenTelemetryAccessLog",
135128
Description: "Make sure OpenTelemetry access log is working",
136-
Manifests: []string{"testdata/accesslog.yaml"},
129+
Manifests: []string{"testdata/accesslog-otel.yaml"},
137130
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
138131
t.Run("OTel", func(t *testing.T) {
139132
ns := "gateway-conformance-infra"
140-
routeNN := types.NamespacedName{Name: "http-infra-backend-v1", Namespace: ns}
133+
routeNN := types.NamespacedName{Name: "accesslog-otel", Namespace: ns}
141134
gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns}
142135
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)
143136

144-
// make sure listener is ready
145-
httputils.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, httputils.ExpectedResponse{
137+
expectedResponse := httputils.ExpectedResponse{
146138
Request: httputils.Request{
147-
Path: "/",
139+
Path: "/otel",
148140
},
149141
Response: httputils.Response{
150142
StatusCode: 200,
151143
},
152144
Namespace: ns,
153-
})
145+
}
146+
// make sure listener is ready
147+
httputils.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, expectedResponse)
154148

155149
labels := map[string]string{
156150
"k8s_namespace_name": "envoy-gateway-system",
@@ -167,15 +161,7 @@ var OpenTelemetryTest = suite.ConformanceTest{
167161
return false, nil
168162
}
169163

170-
httputils.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, httputils.ExpectedResponse{
171-
Request: httputils.Request{
172-
Path: "/",
173-
},
174-
Response: httputils.Response{
175-
StatusCode: 200,
176-
},
177-
Namespace: ns,
178-
})
164+
httputils.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, expectedResponse)
179165

180166
if err := wait.PollUntilContextTimeout(ctx, 500*time.Millisecond, 10*time.Second, true, func(_ context.Context) (bool, error) {
181167
count, err := QueryLogCountFromLoki(t, suite.Client, types.NamespacedName{

0 commit comments

Comments
 (0)