Skip to content

Commit 7c5dfce

Browse files
committed
add false matchCondition benchmark
Signed-off-by: Rita Zhang <[email protected]>
1 parent 11cdb8f commit 7c5dfce

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

staging/src/k8s.io/apiserver/plugin/pkg/authorizer/webhook/webhook_v1_test.go

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,19 @@ func BenchmarkWithOneCELExpressions(b *testing.B) {
814814
benchmarkWebhookAuthorize(b, expressions, true)
815815
})
816816
}
817+
func BenchmarkWithOneCELExpressionsFalse(b *testing.B) {
818+
expressions := []apiserver.WebhookMatchCondition{
819+
{
820+
Expression: "request.user == 'alice2'",
821+
},
822+
}
823+
b.Run("compile", func(b *testing.B) {
824+
benchmarkNewWebhookAuthorizer(b, expressions, true)
825+
})
826+
b.Run("authorize", func(b *testing.B) {
827+
benchmarkWebhookAuthorize(b, expressions, true)
828+
})
829+
}
817830
func BenchmarkWithTwoCELExpressions(b *testing.B) {
818831
expressions := []apiserver.WebhookMatchCondition{
819832
{
@@ -830,13 +843,13 @@ func BenchmarkWithTwoCELExpressions(b *testing.B) {
830843
benchmarkWebhookAuthorize(b, expressions, true)
831844
})
832845
}
833-
func BenchmarkWithTwoComplexCELExpressions(b *testing.B) {
846+
func BenchmarkWithTwoCELExpressionsFalse(b *testing.B) {
834847
expressions := []apiserver.WebhookMatchCondition{
835848
{
836849
Expression: "request.user == 'alice'",
837850
},
838851
{
839-
Expression: "has(request.resourceAttributes) && request.resourceAttributes.namespace == 'kittensandponies'",
852+
Expression: "request.uid == '2'",
840853
},
841854
}
842855
b.Run("compile", func(b *testing.B) {
@@ -880,6 +893,40 @@ func BenchmarkWithManyCELExpressions(b *testing.B) {
880893
benchmarkWebhookAuthorize(b, expressions, true)
881894
})
882895
}
896+
func BenchmarkWithManyCELExpressionsFalse(b *testing.B) {
897+
expressions := []apiserver.WebhookMatchCondition{
898+
{
899+
Expression: "request.user == 'alice'",
900+
},
901+
{
902+
Expression: "request.uid == '1'",
903+
},
904+
{
905+
Expression: "('group1' in request.groups)",
906+
},
907+
{
908+
Expression: "('key1' in request.extra)",
909+
},
910+
{
911+
Expression: "!('key2' in request.extra)",
912+
},
913+
{
914+
Expression: "('a' in request.extra['key1'])",
915+
},
916+
{
917+
Expression: "!('z' in request.extra['key1'])",
918+
},
919+
{
920+
Expression: "has(request.resourceAttributes) && request.resourceAttributes.namespace == 'kittensandponies1'",
921+
},
922+
}
923+
b.Run("compile", func(b *testing.B) {
924+
benchmarkNewWebhookAuthorizer(b, expressions, true)
925+
})
926+
b.Run("authorize", func(b *testing.B) {
927+
benchmarkWebhookAuthorize(b, expressions, true)
928+
})
929+
}
883930

884931
func benchmarkNewWebhookAuthorizer(b *testing.B, expressions []apiserver.WebhookMatchCondition, featureEnabled bool) {
885932
service := new(mockV1Service)

0 commit comments

Comments
 (0)