Skip to content

Commit 136f212

Browse files
authored
Add initial benchmark tests for NIC (#6422)
1 parent c2f6cf1 commit 136f212

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

internal/configs/annotations_test.go

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,98 @@ func TestParseRateLimitAnnotations(t *testing.T) {
215215
t.Error("No Errors when parsing invalid log level")
216216
}
217217
}
218+
219+
func BenchmarkParseRewrites(b *testing.B) {
220+
serviceName := "coffee-svc"
221+
serviceNamePart := "serviceName=" + serviceName
222+
rewritePath := "/beans/"
223+
rewritePathPart := "rewrite=" + rewritePath
224+
rewriteService := serviceNamePart + " " + rewritePathPart
225+
226+
b.ResetTimer()
227+
for range b.N {
228+
_, _, err := parseRewrites(rewriteService)
229+
if err != nil {
230+
b.Fatal(err)
231+
}
232+
}
233+
}
234+
235+
func BenchmarkParseRewritesWithLeadingAndTrailingWhitespace(b *testing.B) {
236+
serviceName := "coffee-svc"
237+
serviceNamePart := "serviceName=" + serviceName
238+
rewritePath := "/beans/"
239+
rewritePathPart := "rewrite=" + rewritePath
240+
rewriteService := "\t\n " + serviceNamePart + " " + rewritePathPart + " \t\n"
241+
242+
b.ResetTimer()
243+
for range b.N {
244+
_, _, err := parseRewrites(rewriteService)
245+
if err != nil {
246+
b.Fatal(err)
247+
}
248+
}
249+
}
250+
251+
func BenchmarkParseStickyService(b *testing.B) {
252+
serviceName := "coffee-svc"
253+
serviceNamePart := "serviceName=" + serviceName
254+
stickyCookie := "srv_id expires=1h domain=.example.com path=/"
255+
stickyService := serviceNamePart + " " + stickyCookie
256+
257+
b.ResetTimer()
258+
for range b.N {
259+
_, _, err := parseStickyService(stickyService)
260+
if err != nil {
261+
b.Fatal(err)
262+
}
263+
}
264+
}
265+
266+
func BenchmarkFilterMasterAnnotations(b *testing.B) {
267+
masterAnnotations := map[string]string{
268+
"nginx.org/rewrites": "serviceName=service1 rewrite=rewrite1",
269+
"nginx.org/ssl-services": "service1",
270+
"nginx.org/hsts": "True",
271+
"nginx.org/hsts-max-age": "2700000",
272+
"nginx.org/hsts-include-subdomains": "True",
273+
}
274+
b.ResetTimer()
275+
for range b.N {
276+
filterMasterAnnotations(masterAnnotations)
277+
}
278+
}
279+
280+
func BenchmarkFilterMinionAnnotations(b *testing.B) {
281+
minionAnnotations := map[string]string{
282+
"nginx.org/rewrites": "serviceName=service1 rewrite=rewrite1",
283+
"nginx.org/ssl-services": "service1",
284+
"nginx.org/hsts": "True",
285+
"nginx.org/hsts-max-age": "2700000",
286+
"nginx.org/hsts-include-subdomains": "True",
287+
}
288+
b.ResetTimer()
289+
for range b.N {
290+
filterMinionAnnotations(minionAnnotations)
291+
}
292+
}
293+
294+
func BenchmarkMergeMasterAnnotationsIntoMinion(b *testing.B) {
295+
masterAnnotations := map[string]string{
296+
"nginx.org/proxy-buffering": "True",
297+
"nginx.org/proxy-buffers": "2",
298+
"nginx.org/proxy-buffer-size": "8k",
299+
"nginx.org/hsts": "True",
300+
"nginx.org/hsts-max-age": "2700000",
301+
"nginx.org/proxy-connect-timeout": "50s",
302+
"nginx.com/jwt-token": "$cookie_auth_token",
303+
}
304+
minionAnnotations := map[string]string{
305+
"nginx.org/client-max-body-size": "2m",
306+
"nginx.org/proxy-connect-timeout": "20s",
307+
}
308+
b.ResetTimer()
309+
for range b.N {
310+
mergeMasterAnnotationsIntoMinion(minionAnnotations, masterAnnotations)
311+
}
312+
}

0 commit comments

Comments
 (0)