Skip to content

Commit

Permalink
feat: add health check for manager addr (dragonflyoss#783)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi authored Oct 16, 2024
1 parent 34f3071 commit 828b925
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
3 changes: 3 additions & 0 deletions dragonfly-client-config/src/dfdaemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ impl UploadClient {
let ca_cert = fs::read(&ca_cert_path).await?;
let ca_cert = TonicCertificate::from_pem(ca_cert);

// TODO(gaius): Use trust_anchor to skip the verify of hostname.
return Ok(Some(
ClientTlsConfig::new()
.domain_name(domain_name)
Expand Down Expand Up @@ -593,6 +594,7 @@ impl Manager {
let ca_cert = fs::read(&ca_cert_path).await?;
let ca_cert = TonicCertificate::from_pem(ca_cert);

// TODO(gaius): Use trust_anchor to skip the verify of hostname.
return Ok(Some(
ClientTlsConfig::new()
.domain_name(domain_name)
Expand Down Expand Up @@ -675,6 +677,7 @@ impl Scheduler {
let ca_cert = fs::read(&ca_cert_path).await?;
let ca_cert = TonicCertificate::from_pem(ca_cert);

// TODO(gaius): Use trust_anchor to skip the verify of hostname.
return Ok(Some(
ClientTlsConfig::new()
.domain_name(domain_name)
Expand Down
19 changes: 16 additions & 3 deletions dragonfly-client/src/grpc/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

use crate::grpc::health::HealthClient;
use dragonfly_api::manager::v2::{
manager_client::ManagerClient as ManagerGRPCClient, DeleteSeedPeerRequest,
ListSchedulersRequest, ListSchedulersResponse, SeedPeer, UpdateSeedPeerRequest,
Expand All @@ -25,6 +26,7 @@ use dragonfly_client_core::{
};
use std::sync::Arc;
use tonic::transport::Channel;
use tonic_health::pb::health_check_response::ServingStatus;
use tracing::{error, instrument, warn};
use url::Url;

Expand All @@ -48,11 +50,22 @@ impl ManagerClient {
})?
.to_string();

let channel = match config
let client_tls_config = config
.manager
.load_client_tls_config(domain_name.as_str())
.await?
{
.await?;

let health_client = HealthClient::new(addr.as_str(), client_tls_config.clone()).await?;
match health_client.check().await {
Ok(resp) => {
if resp.status != ServingStatus::Serving as i32 {
return Err(Error::AvailableManagerNotFound);
}
}
Err(err) => return Err(err),
}

let channel = match client_tls_config {
Some(client_tls_config) => Channel::from_shared(addr.clone())
.map_err(|_| Error::InvalidURI(addr.clone()))?
.tls_config(client_tls_config)?
Expand Down

0 comments on commit 828b925

Please sign in to comment.