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 initial benchmark tests for NIC #6422

Merged
merged 10 commits into from
Sep 18, 2024
95 changes: 95 additions & 0 deletions internal/configs/annotations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,98 @@ func TestParseRateLimitAnnotations(t *testing.T) {
t.Error("No Errors when parsing invalid log level")
}
}

func BenchmarkParseRewrites(b *testing.B) {
serviceName := "coffee-svc"
serviceNamePart := "serviceName=" + serviceName
rewritePath := "/beans/"
rewritePathPart := "rewrite=" + rewritePath
rewriteService := serviceNamePart + " " + rewritePathPart

b.ResetTimer()
for range b.N {
_, _, err := parseRewrites(rewriteService)
if err != nil {
b.Fatal(err)
}
}
}

func BenchmarkParseRewritesWithLeadingAndTrailingWhitespace(b *testing.B) {
serviceName := "coffee-svc"
serviceNamePart := "serviceName=" + serviceName
rewritePath := "/beans/"
rewritePathPart := "rewrite=" + rewritePath
rewriteService := "\t\n " + serviceNamePart + " " + rewritePathPart + " \t\n"

b.ResetTimer()
for range b.N {
_, _, err := parseRewrites(rewriteService)
if err != nil {
b.Fatal(err)
}
}
}

func BenchmarkParseStickyService(b *testing.B) {
serviceName := "coffee-svc"
serviceNamePart := "serviceName=" + serviceName
stickyCookie := "srv_id expires=1h domain=.example.com path=/"
stickyService := serviceNamePart + " " + stickyCookie

b.ResetTimer()
for range b.N {
_, _, err := parseStickyService(stickyService)
if err != nil {
b.Fatal(err)
}
}
}

func BenchmarkFilterMasterAnnotations(b *testing.B) {
masterAnnotations := map[string]string{
"nginx.org/rewrites": "serviceName=service1 rewrite=rewrite1",
"nginx.org/ssl-services": "service1",
"nginx.org/hsts": "True",
"nginx.org/hsts-max-age": "2700000",
"nginx.org/hsts-include-subdomains": "True",
}
b.ResetTimer()
for range b.N {
filterMasterAnnotations(masterAnnotations)
}
}

func BenchmarkFilterMinionAnnotations(b *testing.B) {
minionAnnotations := map[string]string{
"nginx.org/rewrites": "serviceName=service1 rewrite=rewrite1",
"nginx.org/ssl-services": "service1",
"nginx.org/hsts": "True",
"nginx.org/hsts-max-age": "2700000",
"nginx.org/hsts-include-subdomains": "True",
}
b.ResetTimer()
for range b.N {
filterMinionAnnotations(minionAnnotations)
}
}

func BenchmarkMergeMasterAnnotationsIntoMinion(b *testing.B) {
masterAnnotations := map[string]string{
"nginx.org/proxy-buffering": "True",
"nginx.org/proxy-buffers": "2",
"nginx.org/proxy-buffer-size": "8k",
"nginx.org/hsts": "True",
"nginx.org/hsts-max-age": "2700000",
"nginx.org/proxy-connect-timeout": "50s",
"nginx.com/jwt-token": "$cookie_auth_token",
}
minionAnnotations := map[string]string{
"nginx.org/client-max-body-size": "2m",
"nginx.org/proxy-connect-timeout": "20s",
}
b.ResetTimer()
for range b.N {
mergeMasterAnnotationsIntoMinion(minionAnnotations, masterAnnotations)
}
}
Loading