Skip to content

Commit

Permalink
gRPC server reflection enabled with --grpc-reflection-service command…
Browse files Browse the repository at this point in the history
… line param
  • Loading branch information
eguzki committed Dec 19, 2023
1 parent 80be414 commit f31a56b
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ services:
- --http-port
- "8080"
- -vvv
- --grpc-reflection-service
- /opt/kuadrant/limits/limits.yaml
- disk
- "/tmp/data"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ services:
- --http-port
- "8080"
- -vvvv
- --grpc-reflection-service
- /opt/kuadrant/limits/limits.yaml
- infinispan
- --cache-name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ services:
- --http-port
- "8080"
- -vvv
- --grpc-reflection-service
- /opt/kuadrant/limits/limits.yaml
- memory
expose:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ services:
- --http-port
- "8080"
- -vvv
- --grpc-reflection-service
- /opt/kuadrant/limits/limits.yaml
- redis_cached
- --ttl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ services:
- --http-port
- "8080"
- -vvv
- --grpc-reflection-service
- /opt/kuadrant/limits/limits.yaml
- redis
- rediss://:foobared@redis:6379/#insecure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ services:
- --http-port
- "8080"
- -vvv
- --grpc-reflection-service
- /opt/kuadrant/limits/limits.yaml
- redis
- redis://redis:6379
Expand Down
4 changes: 4 additions & 0 deletions limitador-server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub struct Configuration {
pub limit_name_in_labels: bool,
pub log_level: Option<LevelFilter>,
pub rate_limit_headers: RateLimitHeaders,
pub grpc_reflection_service: bool,
}

pub mod env {
Expand Down Expand Up @@ -83,6 +84,7 @@ impl Configuration {
http_port: u16,
limit_name_in_labels: bool,
rate_limit_headers: RateLimitHeaders,
grpc_reflection_service: bool,
) -> Self {
Self {
limits_file,
Expand All @@ -94,6 +96,7 @@ impl Configuration {
limit_name_in_labels,
log_level: None,
rate_limit_headers,
grpc_reflection_service,
}
}

Expand Down Expand Up @@ -121,6 +124,7 @@ impl Default for Configuration {
limit_name_in_labels: false,
log_level: None,
rate_limit_headers: RateLimitHeaders::None,
grpc_reflection_service: false,
}
}
}
Expand Down
16 changes: 11 additions & 5 deletions limitador-server/src/envoy_rls/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,24 @@ pub async fn run_envoy_rls_server(
address: String,
limiter: Arc<Limiter>,
rate_limit_headers: RateLimitHeaders,
grpc_reflection_service: bool,
) -> Result<(), transport::Error> {
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();
let reflection_service = match grpc_reflection_service {
false => None,
true => Some(
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)
.add_optional_service(reflection_service)
.serve(address.parse().unwrap())
.await
}
Expand Down
10 changes: 10 additions & 0 deletions limitador-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let envoy_rls_address = config.rlp_address();
let http_api_address = config.http_address();
let rate_limit_headers = config.rate_limit_headers.clone();
let grpc_reflection_service = config.grpc_reflection_service;

let rate_limiter: Arc<Limiter> = match Limiter::new(config).await {
Ok(limiter) => Arc::new(limiter),
Expand Down Expand Up @@ -390,6 +391,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
envoy_rls_address.to_string(),
rate_limiter.clone(),
rate_limit_headers,
grpc_reflection_service,
));

info!("HTTP server starting on {}", http_api_address);
Expand Down Expand Up @@ -515,6 +517,13 @@ fn create_config() -> (Configuration, &'static str) {
]))
.help("Enables rate limit response headers"),
)
.arg(
Arg::new("grpc_reflection_service")
.long("grpc-reflection-service")
.action(ArgAction::SetTrue)
.display_order(9)
.help("enable gRPC server reflection service"),
)
.subcommand(
Command::new("memory")
.display_order(1)
Expand Down Expand Up @@ -745,6 +754,7 @@ fn create_config() -> (Configuration, &'static str) {
matches.get_flag("limit_name_in_labels")
|| env_option_is_enabled("LIMIT_NAME_IN_PROMETHEUS_LABELS"),
rate_limit_headers,
matches.get_flag("grpc_reflection_service"),
);

config.log_level = match matches.get_count("v") {
Expand Down

0 comments on commit f31a56b

Please sign in to comment.