Skip to content

Commit

Permalink
add false matchCondition benchmark
Browse files Browse the repository at this point in the history
Signed-off-by: Rita Zhang <[email protected]>

Kubernetes-commit: 7c5dfceff8a4de3387b48e941d098a3957de2870
  • Loading branch information
ritazh authored and k8s-publishing-bot committed Nov 13, 2023
1 parent e319da4 commit c4ab5aa
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions plugin/pkg/authorizer/webhook/webhook_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,19 @@ func BenchmarkWithOneCELExpressions(b *testing.B) {
benchmarkWebhookAuthorize(b, expressions, true)
})
}
func BenchmarkWithOneCELExpressionsFalse(b *testing.B) {
expressions := []apiserver.WebhookMatchCondition{
{
Expression: "request.user == 'alice2'",
},
}
b.Run("compile", func(b *testing.B) {
benchmarkNewWebhookAuthorizer(b, expressions, true)
})
b.Run("authorize", func(b *testing.B) {
benchmarkWebhookAuthorize(b, expressions, true)
})
}
func BenchmarkWithTwoCELExpressions(b *testing.B) {
expressions := []apiserver.WebhookMatchCondition{
{
Expand All @@ -830,13 +843,13 @@ func BenchmarkWithTwoCELExpressions(b *testing.B) {
benchmarkWebhookAuthorize(b, expressions, true)
})
}
func BenchmarkWithTwoComplexCELExpressions(b *testing.B) {
func BenchmarkWithTwoCELExpressionsFalse(b *testing.B) {
expressions := []apiserver.WebhookMatchCondition{
{
Expression: "request.user == 'alice'",
},
{
Expression: "has(request.resourceAttributes) && request.resourceAttributes.namespace == 'kittensandponies'",
Expression: "request.uid == '2'",
},
}
b.Run("compile", func(b *testing.B) {
Expand Down Expand Up @@ -880,6 +893,40 @@ func BenchmarkWithManyCELExpressions(b *testing.B) {
benchmarkWebhookAuthorize(b, expressions, true)
})
}
func BenchmarkWithManyCELExpressionsFalse(b *testing.B) {
expressions := []apiserver.WebhookMatchCondition{
{
Expression: "request.user == 'alice'",
},
{
Expression: "request.uid == '1'",
},
{
Expression: "('group1' in request.groups)",
},
{
Expression: "('key1' in request.extra)",
},
{
Expression: "!('key2' in request.extra)",
},
{
Expression: "('a' in request.extra['key1'])",
},
{
Expression: "!('z' in request.extra['key1'])",
},
{
Expression: "has(request.resourceAttributes) && request.resourceAttributes.namespace == 'kittensandponies1'",
},
}
b.Run("compile", func(b *testing.B) {
benchmarkNewWebhookAuthorizer(b, expressions, true)
})
b.Run("authorize", func(b *testing.B) {
benchmarkWebhookAuthorize(b, expressions, true)
})
}

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

0 comments on commit c4ab5aa

Please sign in to comment.