- removed: api-service
- removed: session-service - updated: moved health check out of consul registration - updated: get service info to pull the service from the default namespace for the service account - updated: the rest of the services to be able to handle the new database tables
This commit is contained in:
@@ -3,10 +3,8 @@ use serde_json::json;
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::net::ToSocketAddrs;
|
||||
use std::path::Path;
|
||||
use uuid::Uuid;
|
||||
use warp::Filter;
|
||||
|
||||
const VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
@@ -106,25 +104,3 @@ pub async fn deregister_service(
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn start_health_check(service_address: &str) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let health_port = env::var("HEALTH_CHECK_PORT").unwrap_or_else(|_| "8082".to_string());
|
||||
let health_check_endpoint_addr = format!("{}:{}", service_address, health_port);
|
||||
|
||||
// Start health-check endpoint
|
||||
let log = warp::log("health_check");
|
||||
let health_route = warp::path!("health")
|
||||
.map(|| warp::reply::with_status("OK", warp::http::StatusCode::OK))
|
||||
.with(log);
|
||||
|
||||
tokio::spawn(
|
||||
warp::serve(health_route).run(
|
||||
health_check_endpoint_addr
|
||||
.to_socket_addrs()?
|
||||
.next()
|
||||
.unwrap(),
|
||||
),
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
25
utils/src/health_check.rs
Normal file
25
utils/src/health_check.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
use std::env;
|
||||
use std::net::ToSocketAddrs;
|
||||
use warp::Filter;
|
||||
|
||||
pub async fn start_health_check(service_address: &str) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let health_port = env::var("HEALTH_CHECK_PORT").unwrap_or_else(|_| "8082".to_string());
|
||||
let health_check_endpoint_addr = format!("{}:{}", service_address, health_port);
|
||||
|
||||
// Start health-check endpoint
|
||||
let log = warp::log("health_check");
|
||||
let health_route = warp::path!("health")
|
||||
.map(|| warp::reply::with_status("OK", warp::http::StatusCode::OK))
|
||||
.with(log);
|
||||
|
||||
tokio::spawn(
|
||||
warp::serve(health_route).run(
|
||||
health_check_endpoint_addr
|
||||
.to_socket_addrs()?
|
||||
.next()
|
||||
.unwrap(),
|
||||
),
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -5,3 +5,4 @@ pub mod service_discovery;
|
||||
pub mod signal_handler;
|
||||
pub mod multi_service_load_balancer;
|
||||
pub mod logging;
|
||||
pub mod health_check;
|
||||
|
||||
@@ -6,6 +6,7 @@ use kube::{Client, Api};
|
||||
use k8s_openapi::api::core::v1::Service;
|
||||
use std::collections::{BTreeMap};
|
||||
use hickory_resolver::system_conf::read_system_conf;
|
||||
use tracing::debug;
|
||||
|
||||
pub async fn get_service_endpoints_by_dns(consul_url: &str, service_protocol: &str, service_name: &str) -> Result<Vec<SocketAddr>, Box<dyn std::error::Error>> {
|
||||
let mut rc = ResolverConfig::new();
|
||||
@@ -63,10 +64,12 @@ pub async fn get_service_info(
|
||||
let client = Client::try_default().await?;
|
||||
|
||||
// Create an API object for services in the specified namespace
|
||||
let services: Api<Service> = Api::namespaced(client, namespace);
|
||||
let services: Api<Service> = Api::default_namespaced(client);
|
||||
|
||||
debug!("Looking up service '{}'", service_name);
|
||||
// Get the service object
|
||||
let service = services.get(service_name).await?;
|
||||
debug!("Got service: {:?}", service);
|
||||
|
||||
// Extract metadata
|
||||
let name = service.metadata.name.unwrap_or_default();
|
||||
|
||||
Reference in New Issue
Block a user