Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat): debug logs on data plane for health service addresses #356

Merged
merged 6 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions dataplane/api-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::{

use anyhow::{Context, Result};
use aya::maps::{HashMap, MapData};
use log::info;
use log::{debug, info};
use tonic::transport::{Certificate, Identity, Server, ServerTlsConfig};

use backends::backends_server::BackendsServer;
Expand All @@ -42,23 +42,35 @@ pub async fn start(
let healthchecks = tokio::spawn(async move {
let (_, health_service) = tonic_health::server::health_reporter();
let mut server_builder = Server::builder();
server_builder

// by convention we add 1 to the API listen port and use that
// for the health check port.
let port = port + 1;
buraksekili marked this conversation as resolved.
Show resolved Hide resolved
let addr = SocketAddrV4::new(addr, port);
let server = server_builder
.add_service(health_service)
.serve(SocketAddrV4::new(addr, port + 1).into())
.serve(addr.into());

debug!("gRPC Health Checking service listens on {}", addr);
server
.await
.unwrap();
.expect("Failed to serve gRPC Health Checking service");
});

// Secure server with (optional) mTLS
let backends = tokio::spawn(async move {
let server = server::BackendService::new(backends_map, gateway_indexes_map, tcp_conns_map);

let mut server_builder = Server::builder();
server_builder = setup_tls(server_builder, &tls_config).unwrap();
server_builder

let tls_addr = SocketAddrV4::new(addr, port);
let tls_server = server_builder
.add_service(BackendsServer::new(server))
.serve(SocketAddrV4::new(addr, port).into())
.await
.unwrap();
.serve(tls_addr.into());

debug!("TLS server listens on {}", tls_addr);
tls_server.await.expect("Failed to serve TLS");
});

tokio::try_join!(healthchecks, backends)?;
Expand Down Expand Up @@ -127,6 +139,9 @@ pub fn setup_tls(mut builder: Server, tls_config: &Option<TLSConfig>) -> Result<
info!("gRPC mTLS enabled");
Ok(builder)
}
None => Ok(builder),
None => {
info!("gRPC TLS is not enabled");
buraksekili marked this conversation as resolved.
Show resolved Hide resolved
Ok(builder)
}
}
}
6 changes: 3 additions & 3 deletions xtask/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn build_dataplane(opts: &Options) -> Result<(), anyhow::Error> {
}

/// Build the controlplane
fn build_contrlplane(opts: &Options) -> Result<(), anyhow::Error> {
fn build_controlplane(opts: &Options) -> Result<(), anyhow::Error> {
buraksekili marked this conversation as resolved.
Show resolved Hide resolved
let mut args = vec!["build", "--package", "controlplane"];
if opts.release {
args.push("--release")
Expand Down Expand Up @@ -84,15 +84,15 @@ pub fn run_dataplane(opts: Options) -> Result<(), anyhow::Error> {
// spawn the command
let err = Command::new(args.first().expect("No first argument"))
.args(args.iter().skip(1))
.env("RUST_LOG", "info")
.env("RUST_LOG", "info,api_server=debug")
.exec();

// we shouldn't get here unless the command failed to spawn
Err(anyhow::Error::from(err).context(format!("Failed to run `{}`", args.join(" "))))
}

pub fn run_controlplane(opts: Options) -> Result<(), anyhow::Error> {
build_contrlplane(&opts).context("Error while building controlplane")?;
build_controlplane(&opts).context("Error while building controlplane")?;

// profile we are building (release or debug)
let profile = if opts.release { "release" } else { "debug" };
Expand Down
Loading