Skip to content

Commit 3b3687d

Browse files
committed
Add functional tests for tracing
Verify end to end tracing by creating a collector and sending trace data to it. Test cases: 1. one policy attached to one route 2. one policy attached to multiple routes
1 parent 6a9290a commit 3b3687d

20 files changed

+596
-100
lines changed

.github/workflows/functional.yml

+7
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,10 @@ jobs:
119119
ngf_tag=${{ steps.ngf-meta.outputs.version }}
120120
make test${{ inputs.image == 'plus' && '-with-plus' || ''}} PREFIX=${ngf_prefix} TAG=${ngf_tag} GINKGO_LABEL=telemetry
121121
working-directory: ./tests
122+
123+
- name: Run functional tests
124+
run: |
125+
ngf_prefix=ghcr.io/nginxinc/nginx-gateway-fabric
126+
ngf_tag=${{ steps.ngf-meta.outputs.version }}
127+
make test${{ inputs.image == 'plus' && '-with-plus' || ''}} PREFIX=${ngf_prefix} TAG=${ngf_tag}
128+
working-directory: ./tests

tests/framework/request.go

+38-2
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@ import (
55
"context"
66
"crypto/tls"
77
"fmt"
8+
"log"
89
"net"
910
"net/http"
1011
"strings"
1112
"time"
13+
14+
"k8s.io/apimachinery/pkg/util/wait"
1215
)
1316

1417
// Get sends a GET request to the specified url.
1518
// It resolves to the specified address instead of using DNS.
1619
// The status and body of the response is returned, or an error.
17-
func Get(url, address string, timeout time.Duration) (int, string, error) {
20+
func Get(url, address string, requestTimeout time.Duration) (int, string, error) {
1821
dialer := &net.Dialer{}
1922

2023
http.DefaultTransport.(*http.Transport).DialContext = func(
@@ -27,7 +30,7 @@ func Get(url, address string, timeout time.Duration) (int, string, error) {
2730
return dialer.DialContext(ctx, network, fmt.Sprintf("%s:%s", address, port))
2831
}
2932

30-
ctx, cancel := context.WithTimeout(context.Background(), timeout)
33+
ctx, cancel := context.WithTimeout(context.Background(), requestTimeout)
3134
defer cancel()
3235

3336
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
@@ -60,3 +63,36 @@ func Get(url, address string, timeout time.Duration) (int, string, error) {
6063

6164
return resp.StatusCode, body.String(), nil
6265
}
66+
67+
// GetWithRetry retries the Get function until it succeeds or the context times out.
68+
func GetWithRetry(
69+
ctx context.Context,
70+
url,
71+
address string,
72+
requestTimeout time.Duration,
73+
) (int, string, error) {
74+
var statusCode int
75+
var body string
76+
77+
err := wait.PollUntilContextCancel(
78+
ctx,
79+
500*time.Millisecond,
80+
true, /* poll immediately */
81+
func(ctx context.Context) (bool, error) {
82+
var getErr error
83+
statusCode, body, getErr = Get(url, address, requestTimeout)
84+
if getErr != nil {
85+
return false, getErr
86+
}
87+
88+
if statusCode != 200 {
89+
log.Printf("got %d code instead of expected 200\n", statusCode)
90+
return false, nil
91+
}
92+
93+
return true, nil
94+
},
95+
)
96+
97+
return statusCode, body, err
98+
}

tests/go.mod

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com./nginxinc/nginx-gateway-fabric/tests
33
go 1.22.2
44

55
require (
6+
github.com./nginxinc/nginx-gateway-fabric v0.1.0-rc.1.0.20240520213534-10bae0bc9f00
67
github.com./onsi/ginkgo/v2 v2.17.3
78
github.com./onsi/gomega v1.33.1
89
github.com./prometheus/client_golang v1.19.1
@@ -67,7 +68,7 @@ require (
6768
golang.org/x/time v0.5.0 // indirect
6869
golang.org/x/tools v0.20.0 // indirect
6970
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
70-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
71+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
7172
google.golang.org/grpc v1.63.2 // indirect
7273
google.golang.org/protobuf v1.33.0 // indirect
7374
gopkg.in/inf.v0 v0.9.1 // indirect

tests/go.sum

+6-4
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ github.com./mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+
8686
github.com./mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
8787
github.com./mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus=
8888
github.com./mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
89+
github.com./nginxinc/nginx-gateway-fabric v0.1.0-rc.1.0.20240520213534-10bae0bc9f00 h1:Q8HhAjmq6KADTmXHAhh5p1pg+QXrca9ayjVvxQpTYng=
90+
github.com./nginxinc/nginx-gateway-fabric v0.1.0-rc.1.0.20240520213534-10bae0bc9f00/go.mod h1:eG/LWjOU50RDukuBhRMGihLgpW/vcOLnhwEZql+31d4=
8991
github.com./onsi/ginkgo/v2 v2.17.3 h1:oJcvKpIb7/8uLpDDtnQuf18xVnwKp8DTD7DQ6gTd/MU=
9092
github.com./onsi/ginkgo/v2 v2.17.3/go.mod h1:nP2DPOQoNsQmsVyv5rDA8JkXQoCs6goXIvr/PRJ1eCc=
9193
github.com./onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk=
@@ -122,8 +124,8 @@ go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
122124
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
123125
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
124126
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
125-
go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
126-
go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
127+
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
128+
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
127129
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
128130
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
129131
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
@@ -176,8 +178,8 @@ gomodules.xyz/jsonpatch/v2 v2.4.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuB
176178
gonum.org/v1/gonum v0.0.0-20181121035319-3f7ecaa7e8ca h1:PupagGYwj8+I4ubCxcmcBRk3VlUWtTg5huQpZR9flmE=
177179
gonum.org/v1/gonum v0.0.0-20181121035319-3f7ecaa7e8ca/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo=
178180
gonum.org/v1/netlib v0.0.0-20181029234149-ec6d1f5cefe6/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw=
179-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de h1:cZGRis4/ot9uVm639a+rHCUaG0JJHEsdyzSQTMX+suY=
180-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:H4O17MA/PE9BsGx3w+a+W2VOLLD1Qf7oJneAoU6WktY=
181+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda h1:LI5DOvAxUPMv/50agcLLoo+AdWc1irS9Rzz4vPuD1V4=
182+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY=
181183
google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM=
182184
google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA=
183185
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=

tests/suite/dataplane_perf_test.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,8 @@ var _ = Describe("Dataplane performance", Ordered, Label("nfr", "performance"),
2323
"dp-perf/gateway.yaml",
2424
"dp-perf/cafe-routes.yaml",
2525
}
26-
ns := &core.Namespace{
27-
ObjectMeta: metav1.ObjectMeta{
28-
Name: "dp-perf",
29-
},
30-
}
26+
27+
var ns core.Namespace
3128

3229
var addr string
3330
targetURL := "http://cafe.example.com"
@@ -56,7 +53,13 @@ var _ = Describe("Dataplane performance", Ordered, Label("nfr", "performance"),
5653
}
5754

5855
BeforeAll(func() {
59-
Expect(resourceManager.Apply([]client.Object{ns})).To(Succeed())
56+
ns = core.Namespace{
57+
ObjectMeta: metav1.ObjectMeta{
58+
Name: "dp-perf",
59+
},
60+
}
61+
62+
Expect(resourceManager.Apply([]client.Object{&ns})).To(Succeed())
6063
Expect(resourceManager.ApplyFromFiles(files, ns.Name)).To(Succeed())
6164
Expect(resourceManager.WaitForAppsToBeReady(ns.Name)).To(Succeed())
6265

tests/suite/graceful_recovery_test.go

+13-11
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@ var _ = Describe("Graceful Recovery test", Ordered, Label("nfr", "graceful-recov
3636
"graceful-recovery/cafe-routes.yaml",
3737
}
3838

39-
ns := &core.Namespace{
40-
ObjectMeta: metav1.ObjectMeta{
41-
Name: "graceful-recovery",
42-
},
43-
}
39+
var ns core.Namespace
4440

4541
teaURL := "https://cafe.example.com/tea"
4642
coffeeURL := "http://cafe.example.com/coffee"
@@ -63,7 +59,13 @@ var _ = Describe("Graceful Recovery test", Ordered, Label("nfr", "graceful-recov
6359
})
6460

6561
BeforeEach(func() {
66-
Expect(resourceManager.Apply([]client.Object{ns})).To(Succeed())
62+
ns = core.Namespace{
63+
ObjectMeta: metav1.ObjectMeta{
64+
Name: "graceful-recovery",
65+
},
66+
}
67+
68+
Expect(resourceManager.Apply([]client.Object{&ns})).To(Succeed())
6769
Expect(resourceManager.ApplyFromFiles(files, ns.Name)).To(Succeed())
6870
Expect(resourceManager.WaitForAppsToBeReady(ns.Name)).To(Succeed())
6971

@@ -82,13 +84,13 @@ var _ = Describe("Graceful Recovery test", Ordered, Label("nfr", "graceful-recov
8284
})
8385

8486
It("recovers when NGF container is restarted", func() {
85-
runRecoveryTest(teaURL, coffeeURL, ngfPodName, ngfContainerName, files, ns)
87+
runRecoveryTest(teaURL, coffeeURL, ngfPodName, ngfContainerName, files, &ns)
8688
})
8789

8890
It("recovers when nginx container is restarted", func() {
8991
// FIXME(bjee19) remove Skip() when https://github.com./nginxinc/nginx-gateway-fabric/issues/1108 is completed.
9092
Skip("Test currently fails due to this issue: https://github.com./nginxinc/nginx-gateway-fabric/issues/1108")
91-
runRecoveryTest(teaURL, coffeeURL, ngfPodName, nginxContainerName, files, ns)
93+
runRecoveryTest(teaURL, coffeeURL, ngfPodName, nginxContainerName, files, &ns)
9294
})
9395
})
9496

@@ -206,10 +208,10 @@ func checkForWorkingTraffic(teaURL, coffeeURL string) error {
206208
}
207209

208210
func checkForFailingTraffic(teaURL, coffeeURL string) error {
209-
if err := expectRequestToFail(teaURL, address, "URI: /tea"); err != nil {
211+
if err := expectRequestToFail(teaURL, address); err != nil {
210212
return err
211213
}
212-
if err := expectRequestToFail(coffeeURL, address, "URI: /coffee"); err != nil {
214+
if err := expectRequestToFail(coffeeURL, address); err != nil {
213215
return err
214216
}
215217
return nil
@@ -228,7 +230,7 @@ func expectRequestToSucceed(appURL, address string, responseBodyMessage string)
228230
return err
229231
}
230232

231-
func expectRequestToFail(appURL, address string, responseBodyMessage string) error {
233+
func expectRequestToFail(appURL, address string) error {
232234
status, body, err := framework.Get(appURL, address, timeoutConfig.RequestTimeout)
233235
if status != 0 {
234236
return errors.New("expected http status to be 0")

tests/suite/longevity_test.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,18 @@ var _ = Describe("Longevity", Label("longevity-setup", "longevity-teardown"), fu
3131
"longevity/prom.yaml",
3232
}
3333

34-
ns = &core.Namespace{
35-
ObjectMeta: metav1.ObjectMeta{
36-
Name: "longevity",
37-
},
38-
}
34+
ns core.Namespace
3935

4036
labelFilter = GinkgoLabelFilter()
4137
)
4238

4339
BeforeEach(func() {
40+
ns = core.Namespace{
41+
ObjectMeta: metav1.ObjectMeta{
42+
Name: "longevity",
43+
},
44+
}
45+
4446
if !strings.Contains(labelFilter, "longevity") {
4547
Skip("skipping longevity test unless 'longevity' label is explicitly defined when running")
4648
}
@@ -51,7 +53,7 @@ var _ = Describe("Longevity", Label("longevity-setup", "longevity-teardown"), fu
5153
Skip("'longevity-setup' label not specified; skipping...")
5254
}
5355

54-
Expect(resourceManager.Apply([]client.Object{ns})).To(Succeed())
56+
Expect(resourceManager.Apply([]client.Object{&ns})).To(Succeed())
5557
Expect(resourceManager.ApplyFromFiles(files, ns.Name)).To(Succeed())
5658
Expect(resourceManager.ApplyFromFiles(promFile, ngfNamespace)).To(Succeed())
5759
Expect(resourceManager.WaitForAppsToBeReady(ns.Name)).To(Succeed())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: hello
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
app: hello
10+
template:
11+
metadata:
12+
labels:
13+
app: hello
14+
spec:
15+
containers:
16+
- name: hello
17+
image: nginxdemos/nginx-hello:plain-text
18+
ports:
19+
- containerPort: 8080
20+
---
21+
apiVersion: v1
22+
kind: Service
23+
metadata:
24+
name: hello
25+
spec:
26+
ports:
27+
- port: 80
28+
targetPort: 8080
29+
protocol: TCP
30+
name: http
31+
selector:
32+
app: hello
33+
---
34+
apiVersion: apps/v1
35+
kind: Deployment
36+
metadata:
37+
name: world
38+
spec:
39+
replicas: 1
40+
selector:
41+
matchLabels:
42+
app: world
43+
template:
44+
metadata:
45+
labels:
46+
app: world
47+
spec:
48+
containers:
49+
- name: world
50+
image: nginxdemos/nginx-hello:plain-text
51+
ports:
52+
- containerPort: 8080
53+
---
54+
apiVersion: v1
55+
kind: Service
56+
metadata:
57+
name: world
58+
spec:
59+
ports:
60+
- port: 80
61+
targetPort: 8080
62+
protocol: TCP
63+
name: http
64+
selector:
65+
app: world
66+
---
67+
apiVersion: apps/v1
68+
kind: Deployment
69+
metadata:
70+
name: hello-world
71+
spec:
72+
replicas: 1
73+
selector:
74+
matchLabels:
75+
app: hello-world
76+
template:
77+
metadata:
78+
labels:
79+
app: hello-world
80+
spec:
81+
containers:
82+
- name: hello-world
83+
image: nginxdemos/nginx-hello:plain-text
84+
ports:
85+
- containerPort: 8080
86+
---
87+
apiVersion: v1
88+
kind: Service
89+
metadata:
90+
name: hello-world
91+
spec:
92+
ports:
93+
- port: 80
94+
targetPort: 8080
95+
protocol: TCP
96+
name: http
97+
selector:
98+
app: hello-world

tests/suite/manifests/hello/gateway.yaml renamed to tests/suite/manifests/hello-world/gateway.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ spec:
88
- name: http
99
port: 80
1010
protocol: HTTP
11-
hostname: "*.example.com"
11+
hostname: foo.example.com

0 commit comments

Comments
 (0)