From 249830ec34e6e9014a30426d27d6c739251cd34d Mon Sep 17 00:00:00 2001 From: Jakub Jarosz Date: Fri, 13 Sep 2024 16:02:51 +0100 Subject: [PATCH] Add initial benchmark tests --- internal/configs/annotations_test.go | 95 ++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/internal/configs/annotations_test.go b/internal/configs/annotations_test.go index b2216ccd62..9926af5663 100644 --- a/internal/configs/annotations_test.go +++ b/internal/configs/annotations_test.go @@ -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) + } +}