Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix type mismatch for descriptor func #8420

Merged
merged 21 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions changelog/v1.15.0-beta16/performance-tests-type-error.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
changelog:
- type: NON_USER_FACING
issueLink: https://github.com/solo-io/solo-projects/issues/5116
resolvesIssue: false
description: >-
Resolve a bug introduced in #8415 due to type mismatch in the translation performance test table's descriptor func
skipCI-kube-tests:true
sam-heilbron marked this conversation as resolved.
Show resolved Hide resolved
skipCI-docs-build:true
- type: NON_USER_FACING
issueLink: https://github.com/solo-io/solo-projects/issues/5116
resolvesIssue: false
description: >-
Resolve a bug introduced in #8415 due to 0-indexing names of some resources but not all
skipCI-kube-tests:true
skipCI-docs-build:true
- type: NON_USER_FACING
issueLink: https://github.com/solo-io/solo-projects/issues/4918
resolvesIssue: false
description: >-
Add a Darwin implementation of benchmark measurement to allow tests to run locally
skipCI-kube-tests:true
skipCI-docs-build:true
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ var _ = Describe("Translation - Benchmarking Tests", Serial, Label(labels.Perfor
Expect(apiSnap.Proxies).NotTo(BeEmpty())
proxy = apiSnap.Proxies[0]

desc := generateDesc(apiSnap, config, labels...)
desc := generateDesc(snapBuilder, config, labels...)

experiment := gmeasure.NewExperiment(fmt.Sprintf("Experiment - %s", desc))

Expand Down Expand Up @@ -152,7 +152,7 @@ var _ = Describe("Translation - Benchmarking Tests", Serial, Label(labels.Perfor
Expect(durations).Should(And(config.benchmarkMatchers...))
},
generateDesc, // generate descriptions for table entries with nil descriptions
Entry("basic", basicSnap, basicConfig),
Entry("basic", gloohelpers.NewInjectedSnapshotBuilder(basicSnap), basicConfig),
Entry(nil, gloohelpers.NewScaledSnapshotBuilder().WithUpstreamCount(10).WithEndpointCount(1), basicConfig, "upstream scale"),
Entry(nil, gloohelpers.NewScaledSnapshotBuilder().WithUpstreamCount(1000).WithEndpointCount(1), oneKUpstreamsConfig, "upstream scale"),
Entry(nil, gloohelpers.NewScaledSnapshotBuilder().WithUpstreamCount(1).WithEndpointCount(10), basicConfig, "endpoint scale"),
Expand All @@ -165,14 +165,18 @@ var _ = Describe("Translation - Benchmarking Tests", Serial, Label(labels.Perfor
)
})

func generateDesc(apiSnap *v1snap.ApiSnapshot, _ benchmarkConfig, labels ...string) string {
func generateDesc(b *gloohelpers.ScaledSnapshotBuilder, _ benchmarkConfig, labels ...string) string {
labelPrefix := ""
if len(labels) > 0 {
labelPrefix = fmt.Sprintf("(%s) ", strings.Join(labels, ", "))
}

if b.HasInjectedSnapshot() {
return fmt.Sprintf("%sinjected snapshot", labelPrefix)
}

// If/when additional Snapshot fields are included in testing, the description should be updated accordingly
return fmt.Sprintf("%s%d endpoint(s), %d upstream(s)", labelPrefix, len(apiSnap.Endpoints), len(apiSnap.Upstreams))
return fmt.Sprintf("%s%d endpoint(s), %d upstream(s)", labelPrefix, b.EndpointCount(), b.UpstreamCount())
}

// Test assets: Add blocks for logical groupings of tests, including:
Expand All @@ -188,8 +192,8 @@ var basicSnap = &v1snap.ApiSnapshot{
},
},
},
Endpoints: []*v1.Endpoint{gloohelpers.Endpoint(1)},
Upstreams: []*v1.Upstream{gloohelpers.Upstream(1)},
Endpoints: []*v1.Endpoint{gloohelpers.Endpoint(0)},
Upstreams: []*v1.Upstream{gloohelpers.Upstream(0)},
}

var basicConfig = benchmarkConfig{
Expand Down
13 changes: 13 additions & 0 deletions test/helpers/benchmark.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package helpers

import "time"

// Result represents the result of measuring a function's execution time.
type Result struct {
// Time spent in user mode
Utime time.Duration
// Time spent in kernel mode
Stime time.Duration
// Time spent in user mode + kernel mode
Total time.Duration
}
17 changes: 17 additions & 0 deletions test/helpers/benchmark_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package helpers
nfuden marked this conversation as resolved.
Show resolved Hide resolved

import (
"time"
)

// MeasureIgnore0ns as implemented here for Mac/Darwin is meant to be used in performance tests when developing locally
// It is a less-precise method for measuring than the Linux implementation, and targets should be derived based on
// performance when running on the Linux GHA runner we use for Nightly tests
func MeasureIgnore0ns(f func()) (Result, bool, error) {
before := time.Now()
f()
elapsed := time.Since(before)
return Result{
Total: elapsed,
}, false, nil
}
34 changes: 31 additions & 3 deletions test/helpers/scaled_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
// contains a builder for each sub-resource type which is responsible for building instances of that resource
// Additional fields should be added as needed
type ScaledSnapshotBuilder struct {
injectedSnap *gloosnapshot.ApiSnapshot
sam-heilbron marked this conversation as resolved.
Show resolved Hide resolved

epCount int
usCount int

Expand All @@ -34,6 +36,14 @@ func NewScaledSnapshotBuilder() *ScaledSnapshotBuilder {
}
}

// NewInjectedSnapshotBuilder takes a snapshot object to be returned directly by Build()
// All other settings on a builder with an InjectedSnapshot will be ignored
func NewInjectedSnapshotBuilder(snap *gloosnapshot.ApiSnapshot) *ScaledSnapshotBuilder {
return &ScaledSnapshotBuilder{
injectedSnap: snap,
}
}

func (b *ScaledSnapshotBuilder) WithUpstreamCount(n int) *ScaledSnapshotBuilder {
b.usCount = n
return b
Expand All @@ -54,9 +64,27 @@ func (b *ScaledSnapshotBuilder) WithEndpointBuilder(eb *EndpointBuilder) *Scaled
return b
}

/* Getter funcs to be used by the description generator */

func (b *ScaledSnapshotBuilder) HasInjectedSnapshot() bool {
sam-heilbron marked this conversation as resolved.
Show resolved Hide resolved
return b.injectedSnap != nil
}

func (b *ScaledSnapshotBuilder) UpstreamCount() int {
return b.usCount
}

func (b *ScaledSnapshotBuilder) EndpointCount() int {
return b.epCount
}

// Build generates a snapshot populated with the specified number of each resource for the builder, using the
// sub-resource builders to build each sub-resource
func (b *ScaledSnapshotBuilder) Build() *gloosnapshot.ApiSnapshot {
if b.injectedSnap != nil {
return b.injectedSnap
}

endpointList := make(v1.EndpointList, b.epCount)
for i := 0; i < b.epCount; i++ {
endpointList[i] = b.epBuilder.Build(i)
Expand Down Expand Up @@ -142,7 +170,7 @@ func route(i int) *v1.Route {
func routes(n int) []*v1.Route {
routes := make([]*v1.Route, n)
for i := 0; i < n; i++ {
routes[i] = route(i + 1) // names are 1-indexed
routes[i] = route(i)
}
return routes
}
Expand Down Expand Up @@ -182,8 +210,8 @@ func tcpListener() *v1.Listener {
Single: &v1.Destination{
DestinationType: &v1.Destination_Upstream{
Upstream: &core.ResourceRef{
Name: upMeta(1).GetName(),
Namespace: upMeta(1).GetNamespace(),
Name: upMeta(0).GetName(),
Namespace: upMeta(0).GetNamespace(),
},
},
},
Expand Down
20 changes: 20 additions & 0 deletions test/helpers/scaled_snapshots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package helpers_test
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
v1 "github.com/solo-io/gloo/projects/gloo/pkg/api/v1"
"github.com/solo-io/gloo/projects/gloo/pkg/api/v1/gloosnapshot"
"github.com/solo-io/gloo/test/helpers"
"github.com/solo-io/solo-kit/pkg/api/v1/resources/core"
)

var _ = Describe("ScaledSnapshotBuilder", func() {
Expand Down Expand Up @@ -54,3 +57,20 @@ var _ = Describe("ScaledSnapshotBuilder", func() {
})
})
})

var _ = Describe("InjectedSnapshotBuilder", func() {
It("returns the injected snapshot regardless of other settings", func() {
inSnap := &gloosnapshot.ApiSnapshot{
Upstreams: []*v1.Upstream{
{
Metadata: &core.Metadata{
Name: "injected-name",
Namespace: "injected-namespace",
},
},
},
}
outSnap := helpers.NewInjectedSnapshotBuilder(inSnap).WithUpstreamCount(10).Build()
Expect(outSnap).To(Equal(inSnap))
})
})