Skip to content

Commit 7c08bcb

Browse files
committed
Refactor setup steps
1 parent b4ab7a0 commit 7c08bcb

File tree

1 file changed

+104
-96
lines changed

1 file changed

+104
-96
lines changed

tests/suite/reconfig_test.go

Lines changed: 104 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import (
2727
var _ = Describe("Reconfiguration Performance Testing", Ordered, Label("reconfiguration", "nfr"), func() {
2828
// used for cleaning up resources
2929
const maxResourceCount = 150
30+
const metricExistTimeout = 2 * time.Minute
31+
const metricExistPolling = 1 * time.Second
3032

3133
var (
3234
scrapeInterval = 15 * time.Second
@@ -63,6 +65,9 @@ var _ = Describe("Reconfiguration Performance Testing", Ordered, Label("reconfig
6365
})
6466

6567
BeforeEach(func() {
68+
output, err := framework.InstallGatewayAPI(getDefaultSetupCfg().gwAPIVersion)
69+
Expect(err).ToNot(HaveOccurred(), string(output))
70+
6671
// need to redeclare this variable to reset its resource version. The framework has some bugs where
6772
// if we set and declare this as a global variable, even after deleting the namespace, when we try to
6873
// recreate it, it will error saying the resource version has already been set.
@@ -312,86 +317,47 @@ var _ = Describe("Reconfiguration Performance Testing", Ordered, Label("reconfig
312317
return stringTimeToReadyTotal, nil
313318
}
314319

315-
runTestWithMetrics := func(
316-
testName string,
317-
resourceCount int,
318-
test func(resourceCount int) error,
319-
startWithNGFSetup bool,
320-
timeToReadyStartingLogSubstring string,
321-
) {
322-
var (
323-
metricExistTimeout = 2 * time.Minute
324-
metricExistPolling = 1 * time.Second
325-
ngfPodName string
326-
startTime time.Time
327-
)
320+
deployNGFReturnsNGFPodNameAndStartTime := func() (string, time.Time) {
321+
var startTime time.Time
328322

329323
getStartTime := func() time.Time { return startTime }
330324
modifyStartTime := func() { startTime = startTime.Add(500 * time.Millisecond) }
331325

332-
output, err := framework.InstallGatewayAPI(getDefaultSetupCfg().gwAPIVersion)
333-
Expect(err).ToNot(HaveOccurred(), string(output))
334-
335-
if startWithNGFSetup {
336-
setup(getDefaultSetupCfg())
337-
338-
podNames, err := framework.GetReadyNGFPodNames(k8sClient, ngfNamespace, releaseName, timeoutConfig.GetTimeout)
339-
Expect(err).ToNot(HaveOccurred())
340-
Expect(podNames).To(HaveLen(1))
341-
ngfPodName = podNames[0]
342-
startTime = time.Now()
343-
344-
queries := []string{
345-
fmt.Sprintf(`container_memory_usage_bytes{pod="%s",container="nginx-gateway"}`, ngfPodName),
346-
fmt.Sprintf(`container_cpu_usage_seconds_total{pod="%s",container="nginx-gateway"}`, ngfPodName),
347-
// We don't need to check all nginx_gateway_fabric_* metrics, as they are collected at the same time
348-
fmt.Sprintf(`nginx_gateway_fabric_nginx_reloads_total{pod="%s"}`, ngfPodName),
349-
}
326+
setup(getDefaultSetupCfg())
327+
podNames, err := framework.GetReadyNGFPodNames(k8sClient, ngfNamespace, releaseName, timeoutConfig.GetTimeout)
328+
Expect(err).ToNot(HaveOccurred())
329+
Expect(podNames).To(HaveLen(1))
330+
ngfPodName := podNames[0]
331+
startTime = time.Now()
350332

351-
for _, q := range queries {
352-
Eventually(
353-
framework.CreateMetricExistChecker(
354-
promInstance,
355-
q,
356-
getStartTime,
357-
modifyStartTime,
358-
),
359-
).WithTimeout(metricExistTimeout).WithPolling(metricExistPolling).Should(Succeed())
360-
}
333+
queries := []string{
334+
fmt.Sprintf(`container_memory_usage_bytes{pod="%s",container="nginx-gateway"}`, ngfPodName),
335+
fmt.Sprintf(`container_cpu_usage_seconds_total{pod="%s",container="nginx-gateway"}`, ngfPodName),
336+
// We don't need to check all nginx_gateway_fabric_* metrics, as they are collected at the same time
337+
fmt.Sprintf(`nginx_gateway_fabric_nginx_reloads_total{pod="%s"}`, ngfPodName),
361338
}
362339

363-
Expect(test(resourceCount)).To(Succeed())
364-
Expect(checkResourceCreation(resourceCount)).To(Succeed())
365-
366-
if !startWithNGFSetup {
367-
setup(getDefaultSetupCfg())
368-
369-
podNames, err := framework.GetReadyNGFPodNames(k8sClient, ngfNamespace, releaseName, timeoutConfig.GetTimeout)
370-
Expect(err).ToNot(HaveOccurred())
371-
Expect(podNames).To(HaveLen(1))
372-
ngfPodName = podNames[0]
373-
startTime = time.Now()
374-
375-
// if i do a new instance of NGF each time, I might not need start time and can just do the endtime.
376-
queries := []string{
377-
fmt.Sprintf(`container_memory_usage_bytes{pod="%s",container="nginx-gateway"}`, ngfPodName),
378-
fmt.Sprintf(`container_cpu_usage_seconds_total{pod="%s",container="nginx-gateway"}`, ngfPodName),
379-
// We don't need to check all nginx_gateway_fabric_* metrics, as they are collected at the same time
380-
fmt.Sprintf(`nginx_gateway_fabric_nginx_reloads_total{pod="%s"}`, ngfPodName),
381-
}
382-
383-
for _, q := range queries {
384-
Eventually(
385-
framework.CreateMetricExistChecker(
386-
promInstance,
387-
q,
388-
getStartTime,
389-
modifyStartTime,
390-
),
391-
).WithTimeout(metricExistTimeout).WithPolling(metricExistPolling).Should(Succeed())
392-
}
340+
for _, q := range queries {
341+
Eventually(
342+
framework.CreateMetricExistChecker(
343+
promInstance,
344+
q,
345+
getStartTime,
346+
modifyStartTime,
347+
),
348+
).WithTimeout(metricExistTimeout).WithPolling(metricExistPolling).Should(Succeed())
393349
}
394350

351+
return ngfPodName, startTime
352+
}
353+
354+
collectMetrics := func(
355+
testName string,
356+
resourceCount int,
357+
timeToReadyStartingLogSubstring string,
358+
ngfPodName string,
359+
startTime time.Time,
360+
) {
395361
time.Sleep(2 * scrapeInterval)
396362

397363
endTime := time.Now()
@@ -476,70 +442,112 @@ var _ = Describe("Reconfiguration Performance Testing", Ordered, Label("reconfig
476442

477443
// Test 1 - Resources exist before start-up
478444
It("test 1 - 30 resources", func() {
445+
resourceCount := 30
479446
timeToReadyStartingLogSubstring := "Starting NGINX Gateway Fabric"
447+
test := createResourcesGWLast(resourceCount)
480448

481-
runTestWithMetrics("1",
482-
30,
483-
createResourcesGWLast,
484-
false,
449+
Expect(test).To(Succeed())
450+
Expect(checkResourceCreation(resourceCount)).To(Succeed())
451+
452+
ngfPodName, startTime := deployNGFReturnsNGFPodNameAndStartTime()
453+
454+
collectMetrics("1",
455+
resourceCount,
485456
timeToReadyStartingLogSubstring,
457+
ngfPodName,
458+
startTime,
486459
)
487460
})
488461

489462
It("test 1 - 150 resources", func() {
463+
resourceCount := 150
490464
timeToReadyStartingLogSubstring := "Starting NGINX Gateway Fabric"
465+
test := createResourcesGWLast(resourceCount)
466+
467+
Expect(test).To(Succeed())
468+
Expect(checkResourceCreation(resourceCount)).To(Succeed())
469+
470+
ngfPodName, startTime := deployNGFReturnsNGFPodNameAndStartTime()
491471

492-
runTestWithMetrics("1",
493-
150,
494-
createResourcesGWLast,
495-
false,
472+
collectMetrics("1",
473+
resourceCount,
496474
timeToReadyStartingLogSubstring,
475+
ngfPodName,
476+
startTime,
497477
)
498478
})
499479

500480
// Test 2 - Start NGF, deploy Gateway, create many resources attached to GW
501481
It("test 2 - 30 resources", func() {
482+
resourceCount := 30
502483
timeToReadyStartingLogSubstring := "Reconciling the resource\",\"controller\":\"httproute\""
484+
test := createResourcesRoutesLast(resourceCount)
503485

504-
runTestWithMetrics("2",
505-
30,
506-
createResourcesRoutesLast,
507-
true,
486+
ngfPodName, startTime := deployNGFReturnsNGFPodNameAndStartTime()
487+
488+
Expect(test).To(Succeed())
489+
Expect(checkResourceCreation(resourceCount)).To(Succeed())
490+
491+
collectMetrics("2",
492+
resourceCount,
508493
timeToReadyStartingLogSubstring,
494+
ngfPodName,
495+
startTime,
509496
)
510497
})
511498

512499
It("test 2 - 150 resources", func() {
500+
resourceCount := 150
513501
timeToReadyStartingLogSubstring := "Reconciling the resource\",\"controller\":\"httproute\""
502+
test := createResourcesRoutesLast(resourceCount)
503+
504+
ngfPodName, startTime := deployNGFReturnsNGFPodNameAndStartTime()
505+
506+
Expect(test).To(Succeed())
507+
Expect(checkResourceCreation(resourceCount)).To(Succeed())
514508

515-
runTestWithMetrics("2",
516-
150,
517-
createResourcesRoutesLast,
518-
true,
509+
collectMetrics("2",
510+
resourceCount,
519511
timeToReadyStartingLogSubstring,
512+
ngfPodName,
513+
startTime,
520514
)
521515
})
522516

523-
// Test 3: Start NGF, create many resources attached to a Gateway, deploy the Gateway
517+
// Test 3 - Start NGF, create many resources attached to a Gateway, deploy the Gateway
524518
It("test 3 - 30 resources", func() {
519+
resourceCount := 30
525520
timeToReadyStartingLogSubstring := "Reconciling the resource\",\"controller\":\"gateway\""
521+
test := createResourcesGWLast(resourceCount)
522+
523+
ngfPodName, startTime := deployNGFReturnsNGFPodNameAndStartTime()
524+
525+
Expect(test).To(Succeed())
526+
Expect(checkResourceCreation(resourceCount)).To(Succeed())
526527

527-
runTestWithMetrics("3",
528-
30,
529-
createResourcesGWLast,
530-
true,
528+
collectMetrics("3",
529+
resourceCount,
531530
timeToReadyStartingLogSubstring,
531+
ngfPodName,
532+
startTime,
532533
)
533534
})
534535

535536
It("test 3 - 150 resources", func() {
537+
resourceCount := 30
536538
timeToReadyStartingLogSubstring := "Reconciling the resource\",\"controller\":\"gateway\""
539+
test := createResourcesGWLast(resourceCount)
540+
541+
ngfPodName, startTime := deployNGFReturnsNGFPodNameAndStartTime()
542+
543+
Expect(test).To(Succeed())
544+
Expect(checkResourceCreation(resourceCount)).To(Succeed())
537545

538-
runTestWithMetrics("3",
539-
150,
540-
createResourcesGWLast,
541-
true,
546+
collectMetrics("3",
547+
resourceCount,
542548
timeToReadyStartingLogSubstring,
549+
ngfPodName,
550+
startTime,
543551
)
544552
})
545553

0 commit comments

Comments
 (0)