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

Add a hermetic e2e test with fake backend pods #29

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
151 changes: 0 additions & 151 deletions pkg/ext-proc/benchmark/benchmark.go

This file was deleted.

97 changes: 97 additions & 0 deletions pkg/ext-proc/test/benchmark/benchmark.go
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from pkg/ext-proc/benchmark/benchmark.go, no new code

Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package main

import (
"flag"
"fmt"
"os"
"time"

"github.com/bojand/ghz/printer"
"github.com/bojand/ghz/runner"
"github.com/jhump/protoreflect/desc"
"google.golang.org/protobuf/proto"
klog "k8s.io/klog/v2"

"ext-proc/backend"
"ext-proc/test"
)

var (
svrAddr = flag.String("server_address", "localhost:9002", "Address of the ext proc server")
totalRequests = flag.Int("total_requests", 100000, "number of requests to be sent for load test")
// Flags when running a local ext proc server.
numFakePods = flag.Int("num_fake_pods", 200, "number of fake pods when running a local ext proc server")
numModelsPerPod = flag.Int("num_models_per_pod", 5, "number of fake models per pod when running a local ext proc server")
localServer = flag.Bool("local_server", true, "whether to start a local ext proc server")
refreshPodsInterval = flag.Duration("refreshPodsInterval", 10*time.Second, "interval to refresh pods")
refreshMetricsInterval = flag.Duration("refreshMetricsInterval", 50*time.Millisecond, "interval to refresh metrics")
)

const (
port = 9002
)

func main() {
klog.InitFlags(nil)
flag.Parse()

if *localServer {
test.StartExtProc(port, *refreshPodsInterval, *refreshMetricsInterval, fakePods())
time.Sleep(time.Second) // wait until server is up
klog.Info("Server started")
}

report, err := runner.Run(
"envoy.service.ext_proc.v3.ExternalProcessor.Process",
*svrAddr,
runner.WithInsecure(true),
runner.WithBinaryDataFunc(generateRequest),
runner.WithTotalRequests(uint(*totalRequests)),
)
if err != nil {
klog.Fatal(err)
}

printer := printer.ReportPrinter{
Out: os.Stdout,
Report: report,
}

printer.Print("summary")
}

func generateRequest(mtd *desc.MethodDescriptor, callData *runner.CallData) []byte {
numModels := *numFakePods * (*numModelsPerPod)
req := test.GenerateRequest(modelName(int(callData.RequestNumber) % numModels))
data, err := proto.Marshal(req)
if err != nil {
klog.Fatal("marshaling error: ", err)
}
return data
}

func fakePods() []*backend.PodMetrics {
pms := make([]*backend.PodMetrics, 0, *numFakePods)
for i := 0; i < *numFakePods; i++ {
metrics := fakeMetrics(i)
pod := test.FakePod(i)
pms = append(pms, &backend.PodMetrics{Pod: pod, Metrics: metrics})
}

return pms
}

// fakeMetrics adds numModelsPerPod number of adapters to the pod metrics.
func fakeMetrics(podNumber int) backend.Metrics {
metrics := backend.Metrics{
ActiveModels: make(map[string]int),
}
for i := 0; i < *numModelsPerPod; i++ {
metrics.ActiveModels[modelName(podNumber*(*numModelsPerPod)+i)] = 0
}
return metrics
}

func modelName(i int) string {
return fmt.Sprintf("adapter-%v", i)
}
Loading