Uses a lazily constructed map container for "ip", "path", and "token".
| 436 | |
| 437 | // Uses a lazily constructed map container for "ip", "path", and "token". |
| 438 | void BM_PolicySymbolicMap(benchmark::State& state) { |
| 439 | google::protobuf::Arena arena; |
| 440 | ASSERT_OK_AND_ASSIGN(ParsedExpr parsed_expr, Parse(R"cel( |
| 441 | !(request.ip in ["10.0.1.4", "10.0.1.5", "10.0.1.6"]) && |
| 442 | ((request.path.startsWith("v1") && request.token in ["v1", "v2", "admin"]) || |
| 443 | (request.path.startsWith("v2") && request.token in ["v2", "admin"]) || |
| 444 | (request.path.startsWith("/admin") && request.token == "admin" && |
| 445 | request.ip in ["10.0.1.1", "10.0.1.2", "10.0.1.3"]) |
| 446 | ))cel")); |
| 447 | |
| 448 | RuntimeOptions options = GetOptions(); |
| 449 | |
| 450 | auto runtime = StandardRuntimeOrDie(options); |
| 451 | |
| 452 | SourceInfo source_info; |
| 453 | ASSERT_OK_AND_ASSIGN(auto cel_expr, ProtobufRuntimeAdapter::CreateProgram( |
| 454 | *runtime, parsed_expr)); |
| 455 | |
| 456 | Activation activation; |
| 457 | CustomMapValue map_value(google::protobuf::Arena::Create<RequestMapImpl>(&arena), |
| 458 | &arena); |
| 459 | |
| 460 | activation.InsertOrAssignValue("request", std::move(map_value)); |
| 461 | |
| 462 | for (auto _ : state) { |
| 463 | ASSERT_OK_AND_ASSIGN(cel::Value result, |
| 464 | cel_expr->Evaluate(&arena, activation)); |
| 465 | ASSERT_TRUE(InstanceOf<BoolValue>(result) && |
| 466 | Cast<BoolValue>(result).NativeValue()); |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | BENCHMARK(BM_PolicySymbolicMap); |
| 471 | |
| 472 | // Uses a protobuf container for "ip", "path", and "token". |
| 473 | void BM_PolicySymbolicProto(benchmark::State& state) { |
| 474 | google::protobuf::Arena arena; |
| 475 | ASSERT_OK_AND_ASSIGN(ParsedExpr parsed_expr, Parse(R"cel( |
| 476 | !(request.ip in ["10.0.1.4", "10.0.1.5", "10.0.1.6"]) && |
| 477 | ((request.path.startsWith("v1") && request.token in ["v1", "v2", "admin"]) || |
| 478 | (request.path.startsWith("v2") && request.token in ["v2", "admin"]) || |
| 479 | (request.path.startsWith("/admin") && request.token == "admin" && |
| 480 | request.ip in ["10.0.1.1", "10.0.1.2", "10.0.1.3"]) |
| 481 | ))cel")); |
| 482 | |
| 483 | RuntimeOptions options = GetOptions(); |
| 484 | |
| 485 | auto runtime = StandardRuntimeOrDie(options); |
| 486 | |
| 487 | SourceInfo source_info; |
| 488 | ASSERT_OK_AND_ASSIGN(auto cel_expr, ProtobufRuntimeAdapter::CreateProgram( |
| 489 | *runtime, parsed_expr)); |
| 490 | |
| 491 | Activation activation; |
| 492 | RequestContext request; |
| 493 | request.set_ip(kIP); |
| 494 | request.set_path(kPath); |
| 495 | request.set_token(kToken); |
no outgoing calls
no test coverage detected