diff --git a/Cargo.lock b/Cargo.lock index 9593b9cc..da8a178e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1577,6 +1577,7 @@ dependencies = [ "tokio", "tonic", "tonic-build", + "tonic-reflection", "url", ] @@ -3027,6 +3028,19 @@ dependencies = [ "syn 2.0.32", ] +[[package]] +name = "tonic-reflection" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fa37c513df1339d197f4ba21d28c918b9ef1ac1768265f11ecb6b7f1cba1b76" +dependencies = [ + "prost", + "prost-types", + "tokio", + "tokio-stream", + "tonic", +] + [[package]] name = "tower" version = "0.4.13" diff --git a/limitador-server/Cargo.toml b/limitador-server/Cargo.toml index 011a2cd7..404718f4 100644 --- a/limitador-server/Cargo.toml +++ b/limitador-server/Cargo.toml @@ -22,6 +22,7 @@ limitador = { path = "../limitador", features = ['lenient_conditions'] } tokio = { version = "1", features = ["full"] } thiserror = "1" tonic = "0.10" +tonic-reflection = "0.10.2" prost = "0.12" prost-types = "0.12" serde_yaml = "0.9" diff --git a/limitador-server/build.rs b/limitador-server/build.rs index 0a816902..780efae2 100644 --- a/limitador-server/build.rs +++ b/limitador-server/build.rs @@ -1,4 +1,6 @@ +use std::env; use std::error::Error; +use std::path::PathBuf; use std::process::Command; fn main() -> Result<(), Box> { @@ -9,14 +11,18 @@ fn main() -> Result<(), Box> { } fn generate_protobuf() -> Result<(), Box> { - tonic_build::configure().build_server(true).compile( - &["envoy/service/ratelimit/v3/rls.proto"], - &[ - "vendor/protobufs/data-plane-api", - "vendor/protobufs/protoc-gen-validate", - "vendor/protobufs/xds", - ], - )?; + let original_out_dir = PathBuf::from(env::var("OUT_DIR")?); + tonic_build::configure() + .build_server(true) + .file_descriptor_set_path(original_out_dir.join("rls.bin")) + .compile( + &["envoy/service/ratelimit/v3/rls.proto"], + &[ + "vendor/protobufs/data-plane-api", + "vendor/protobufs/protoc-gen-validate", + "vendor/protobufs/xds", + ], + )?; Ok(()) } diff --git a/limitador-server/docs/sandbox.md b/limitador-server/docs/sandbox.md index f42dcfd8..8679f2ef 100644 --- a/limitador-server/docs/sandbox.md +++ b/limitador-server/docs/sandbox.md @@ -27,10 +27,83 @@ Check out `make help` for all the targets. ### Limitador's admin HTTP endpoint +Limits + ```bash curl -i http://127.0.0.1:18080/limits/test_namespace ``` +Counters + +```bash +curl -i http://127.0.0.1:18080/counters/test_namespace +``` + +Metrics + +```bash +curl -i http://127.0.0.1:18080/metrics +``` + +### Limitador's GRPC RateLimitService endpoint + +Get `grpcurl`. You need [Go SDK](https://golang.org/doc/install) installed. + +Golang version >= 1.18 (from [fullstorydev/grpcurl](https://github.com/fullstorydev/grpcurl/blob/v1.8.9/go.mod#L3)) + +```bash +make grpcurl +``` + +Inspect `RateLimitService` GRPC service + +```bash +bin/grpcurl -plaintext 127.0.0.1:18081 describe envoy.service.ratelimit.v3.RateLimitService +``` + +Make a custom request + +```bash +bin/grpcurl -plaintext -d @ 127.0.0.1:18081 envoy.service.ratelimit.v3.RateLimitService.ShouldRateLimit <, @@ -202,8 +206,14 @@ pub async fn run_envoy_rls_server( let rate_limiter = MyRateLimiter::new(limiter, rate_limit_headers); let svc = RateLimitServiceServer::new(rate_limiter); + let reflection_service = tonic_reflection::server::Builder::configure() + .register_encoded_file_descriptor_set(rls_proto::RLS_DESCRIPTOR_SET) + .build() + .unwrap(); + Server::builder() .add_service(svc) + .add_service(reflection_service) .serve(address.parse().unwrap()) .await }