-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Performance test snapshot generation (#8415)
* switch to builder paradigm * sub-resource builders * unit test resource builders * cleanup * codegen * changelog * fix sniPattern enum * builder filestructure * zero-indexed names * export builder types * Build in test body * fmt * fix type names
- Loading branch information
Showing
7 changed files
with
249 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
changelog: | ||
- type: NON_USER_FACING | ||
issueLink: https://github.com/solo-io/solo-projects/issues/5116 | ||
resolvesIssue: true | ||
description: >- | ||
Generate scaled snapshots for performance tests via Builder paradigm for improved usability and extensibility | ||
skipCI-kube-tests:true | ||
skipCI-docs-build:true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package helpers | ||
|
||
import v1 "github.com/solo-io/gloo/projects/gloo/pkg/api/v1" | ||
|
||
// EndpointBuilder contains options for building Endpoints to be included in scaled Snapshots | ||
// there are no options currently configurable for the endpointBuilder | ||
type EndpointBuilder struct{} | ||
|
||
func NewEndpointBuilder() *EndpointBuilder { | ||
return &EndpointBuilder{} | ||
} | ||
|
||
func (b *EndpointBuilder) Build(i int) *v1.Endpoint { | ||
return Endpoint(i) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package helpers_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/solo-io/gloo/test/helpers" | ||
) | ||
|
||
var _ = Describe("ScaledSnapshotBuilder", func() { | ||
When("with endpoints", func() { | ||
It("generates a snapshot with the expected number of endpoints", func() { | ||
snap := helpers.NewScaledSnapshotBuilder().WithEndpointCount(10).Build() | ||
Expect(snap.Endpoints).To(HaveLen(10)) | ||
Expect(snap.Upstreams).To(HaveLen(0)) | ||
}) | ||
}) | ||
|
||
When("with upstreams", func() { | ||
It("generates a snapshot with the expected number of upstreams", func() { | ||
snap := helpers.NewScaledSnapshotBuilder().WithUpstreamCount(10).Build() | ||
Expect(snap.Endpoints).To(HaveLen(0)) | ||
Expect(snap.Upstreams).To(HaveLen(10)) | ||
}) | ||
}) | ||
|
||
When("with upstream builder", func() { | ||
When("with consistent SNI", func() { | ||
It("generates a snapshot with upstreams that all have the same SNI", func() { | ||
snap := helpers.NewScaledSnapshotBuilder().WithUpstreamCount(10). | ||
WithUpstreamBuilder(helpers.NewUpstreamBuilder().WithConsistentSni()).Build() | ||
Expect(snap.Upstreams).To(HaveLen(10)) | ||
Expect(snap.Upstreams[0].SslConfig).NotTo(BeNil()) | ||
firstSNI := snap.Upstreams[0].SslConfig.Sni | ||
for i := 1; i < len(snap.Upstreams); i++ { | ||
Expect(snap.Upstreams[i].SslConfig).NotTo(BeNil()) | ||
Expect(snap.Upstreams[i].SslConfig.Sni).To(Equal(firstSNI)) | ||
} | ||
}) | ||
}) | ||
|
||
When("with unique SNI", func() { | ||
It("generates a snapshot with upstreams that all have unique SNI", func() { | ||
snap := helpers.NewScaledSnapshotBuilder().WithUpstreamCount(10). | ||
WithUpstreamBuilder(helpers.NewUpstreamBuilder().WithUniqueSni()).Build() | ||
Expect(snap.Upstreams).To(HaveLen(10)) | ||
foundSNI := map[string]bool{} | ||
for i := 0; i < len(snap.Upstreams); i++ { | ||
Expect(snap.Upstreams[i].SslConfig).NotTo(BeNil()) | ||
_, ok := foundSNI[snap.Upstreams[i].SslConfig.Sni] | ||
Expect(ok).To(BeFalse()) | ||
foundSNI[snap.Upstreams[i].SslConfig.Sni] = true | ||
} | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package helpers | ||
|
||
import ( | ||
"fmt" | ||
|
||
v1 "github.com/solo-io/gloo/projects/gloo/pkg/api/v1" | ||
"github.com/solo-io/gloo/projects/gloo/pkg/api/v1/ssl" | ||
) | ||
|
||
// UpstreamBuilder contains options for building Upstreams to be included in scaled Snapshots | ||
type UpstreamBuilder struct { | ||
sniPattern sniPattern | ||
} | ||
|
||
type sniPattern int | ||
|
||
const ( | ||
noSni sniPattern = iota | ||
uniqueSni | ||
consistentSni | ||
) | ||
|
||
func NewUpstreamBuilder() *UpstreamBuilder { | ||
return &UpstreamBuilder{} | ||
} | ||
|
||
func (b *UpstreamBuilder) WithUniqueSni() *UpstreamBuilder { | ||
b.sniPattern = uniqueSni | ||
return b | ||
} | ||
|
||
func (b *UpstreamBuilder) WithConsistentSni() *UpstreamBuilder { | ||
b.sniPattern = consistentSni | ||
return b | ||
} | ||
|
||
func (b *UpstreamBuilder) Build(i int) *v1.Upstream { | ||
up := Upstream(i) | ||
|
||
switch b.sniPattern { | ||
case uniqueSni: | ||
up.SslConfig = &ssl.UpstreamSslConfig{ | ||
Sni: fmt.Sprintf("unique-domain-%d", i), | ||
} | ||
case consistentSni: | ||
up.SslConfig = &ssl.UpstreamSslConfig{ | ||
Sni: "consistent-domain", | ||
} | ||
} | ||
|
||
return up | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package helpers_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/solo-io/gloo/test/helpers" | ||
) | ||
|
||
var _ = Describe("UpstreamBuilder", func() { | ||
When("using the base builder", func() { | ||
It("generates an upstream without SslConfig", func() { | ||
up := helpers.NewUpstreamBuilder().Build(1) | ||
Expect(up.SslConfig).To(BeNil()) | ||
}) | ||
}) | ||
|
||
When("with consistent SNI", func() { | ||
It("generates an upstream with the same SNI for any i", func() { | ||
up1 := helpers.NewUpstreamBuilder().WithConsistentSni().Build(1) | ||
Expect(up1.SslConfig).NotTo(BeNil()) | ||
up2 := helpers.NewUpstreamBuilder().WithConsistentSni().Build(2) | ||
Expect(up2.SslConfig).NotTo(BeNil()) | ||
|
||
Expect(up1.SslConfig.Sni).To(Equal(up2.SslConfig.Sni)) | ||
}) | ||
}) | ||
|
||
When("with unique SNI", func() { | ||
It("generates an upstream with unique SNI for a given i", func() { | ||
up1 := helpers.NewUpstreamBuilder().WithUniqueSni().Build(1) | ||
Expect(up1.SslConfig).NotTo(BeNil()) | ||
up2 := helpers.NewUpstreamBuilder().WithUniqueSni().Build(2) | ||
Expect(up2.SslConfig).NotTo(BeNil()) | ||
|
||
Expect(up1.SslConfig.Sni).NotTo(Equal(up2.SslConfig.Sni)) | ||
}) | ||
}) | ||
|
||
}) |