mirror of
https://github.com/faas-rs/faasd-in-rust.git
synced 2025-06-08 15:56:48 +00:00
fix(log):replace all println! with log
This commit is contained in:
parent
a671480b6f
commit
8c4107a8b4
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -848,6 +848,8 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"actix-web",
|
||||
"dotenv",
|
||||
"env_logger",
|
||||
"log",
|
||||
"my-workspace-hack",
|
||||
"provider",
|
||||
"serde 1.0.217",
|
||||
|
@ -12,3 +12,5 @@ serde_json = "1.0"
|
||||
my-workspace-hack = { version = "0.1", path = "../my-workspace-hack" }
|
||||
provider = { path = "../provider" }
|
||||
dotenv = "0.15"
|
||||
env_logger = "0.10"
|
||||
log = "0.4.27"
|
||||
|
@ -1,16 +1,17 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use actix_web::{App, HttpServer, web};
|
||||
use service::Service;
|
||||
use provider::{
|
||||
handlers::{delete::delete_handler, deploy::deploy_handler, invoke_resolver::InvokeResolver},
|
||||
proxy::proxy_handler::proxy_handler,
|
||||
types::config::FaaSConfig,
|
||||
};
|
||||
use service::Service;
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
dotenv::dotenv().ok();
|
||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||
let service = Arc::new(
|
||||
Service::new("/run/containerd/containerd.sock")
|
||||
.await
|
||||
@ -20,7 +21,7 @@ async fn main() -> std::io::Result<()> {
|
||||
let resolver = Some(InvokeResolver::new(service.clone()).await);
|
||||
let faas_config = FaaSConfig::new();
|
||||
|
||||
println!("I'm running!");
|
||||
log::info!("I'm running!");
|
||||
|
||||
let server = HttpServer::new(move || {
|
||||
App::new()
|
||||
@ -34,7 +35,7 @@ async fn main() -> std::io::Result<()> {
|
||||
})
|
||||
.bind("0.0.0.0:8090")?;
|
||||
|
||||
println!("0.0.0.0:8090");
|
||||
log::info!("Running on 0.0.0.0:8090...");
|
||||
|
||||
server.run().await
|
||||
}
|
||||
@ -49,9 +50,9 @@ mod tests {
|
||||
let bin = std::env::var("CNI_BIN_DIR").unwrap_or_else(|_| "Not set".to_string());
|
||||
let conf = std::env::var("CNI_CONF_DIR").unwrap_or_else(|_| "Not set".to_string());
|
||||
let tool = std::env::var("CNI_TOOL").unwrap_or_else(|_| "Not set".to_string());
|
||||
println!("CNI_BIN_DIR: {bin}");
|
||||
println!("CNI_CONF_DIR: {conf}");
|
||||
println!("CNI_TOOL: {tool}");
|
||||
log::debug!("CNI_BIN_DIR: {bin}");
|
||||
log::debug!("CNI_CONF_DIR: {conf}");
|
||||
log::debug!("CNI_TOOL: {tool}");
|
||||
// for (key, value) in &result {
|
||||
// println!("{}={}", key, value);
|
||||
// }
|
||||
|
@ -28,7 +28,7 @@ service = { path = "../service" }
|
||||
cni = { path = "../cni" }
|
||||
async-trait = "0.1"
|
||||
lazy_static = "1.4.0"
|
||||
log = "0.4"
|
||||
log = "0.4.27"
|
||||
my-workspace-hack = { version = "0.1", path = "../my-workspace-hack" }
|
||||
url = "2.4"
|
||||
derive_more = { version = "2", features = ["full"] }
|
||||
|
@ -42,10 +42,11 @@ async fn delete(
|
||||
}
|
||||
let function = get_function(service, function_name, namespace).await?;
|
||||
if function.replicas != 0 {
|
||||
println!(" delete_cni_network ing {:?}", function.replicas);
|
||||
log::info!("function.replicas: {:?}", function.replicas);
|
||||
cni::delete_cni_network(namespace, function_name);
|
||||
log::info!("delete_cni_network ok");
|
||||
} else {
|
||||
println!(" function.replicas {:?}", function.replicas);
|
||||
log::info!("function.replicas: {:?}", function.replicas);
|
||||
}
|
||||
service
|
||||
.remove_container(function_name, namespace)
|
||||
|
@ -50,7 +50,7 @@ async fn deploy(service: &Arc<Service>, config: &FunctionDeployment) -> Result<(
|
||||
// namespace
|
||||
// ))));
|
||||
// }
|
||||
println!(
|
||||
log::info!(
|
||||
"Namespace '{}' validated.",
|
||||
config.namespace.clone().unwrap()
|
||||
);
|
||||
@ -71,16 +71,18 @@ async fn deploy(service: &Arc<Service>, config: &FunctionDeployment) -> Result<(
|
||||
ImageManager::prepare_image(client, &config.image, &namespace, true)
|
||||
.await
|
||||
.map_err(CustomError::from)?;
|
||||
println!("Image '{}' validated", &config.image);
|
||||
log::info!("Image '{}' validated ,", &config.image);
|
||||
|
||||
service
|
||||
.create_container(&config.image, &config.service, &namespace)
|
||||
.await
|
||||
.map_err(|e| CustomError::OtherError(format!("failed to create container:{}", e)))?;
|
||||
|
||||
println!(
|
||||
log::info!(
|
||||
"Container {} created using image {} in namespace {}",
|
||||
&config.service, &config.image, namespace
|
||||
&config.service,
|
||||
&config.image,
|
||||
namespace
|
||||
);
|
||||
|
||||
service
|
||||
@ -92,7 +94,7 @@ async fn deploy(service: &Arc<Service>, config: &FunctionDeployment) -> Result<(
|
||||
&config.service, e
|
||||
))
|
||||
})?;
|
||||
println!(
|
||||
log::info!(
|
||||
"Task for container {} was created successfully",
|
||||
&config.service
|
||||
);
|
||||
|
@ -64,7 +64,7 @@ pub async fn get_function(
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Failed to get task: {}", e);
|
||||
log::error!("Failed to get task: {}", e);
|
||||
replicas = 0;
|
||||
}
|
||||
}
|
||||
|
@ -33,11 +33,9 @@ impl InvokeResolver {
|
||||
return Err(ErrorInternalServerError("Failed to get function"));
|
||||
}
|
||||
};
|
||||
log::info!("Function:{:?}", function);
|
||||
|
||||
//容器启动后的port?
|
||||
let address = function.address.clone();
|
||||
println!("function: {:?}", function);
|
||||
|
||||
let urlstr = format!("http://{}", address);
|
||||
match Url::parse(&urlstr) {
|
||||
Ok(url) => Ok(url),
|
||||
|
@ -4,7 +4,7 @@ use derive_more::Display;
|
||||
use service::image_manager::ImageError;
|
||||
|
||||
pub fn map_service_error(e: Box<dyn std::error::Error>) -> Error {
|
||||
eprintln!("Service error: {}", e);
|
||||
log::error!("Service error: {}", e);
|
||||
actix_web::error::ErrorInternalServerError(format!("Operationfailed: {}", e))
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ pub async fn proxy_handler(
|
||||
.expect("empty proxy handler resolver, cannot be nil");
|
||||
|
||||
let proxy_client = new_proxy_client_from_config(config.as_ref()).await;
|
||||
println!("proxy_client : {:?}", proxy_client);
|
||||
log::info!("proxy_client : {:?}", proxy_client);
|
||||
|
||||
match *req.method() {
|
||||
Method::POST
|
||||
|
@ -1,3 +1,2 @@
|
||||
pub mod config;
|
||||
pub mod function_deployment;
|
||||
|
||||
|
@ -146,11 +146,11 @@ impl Service {
|
||||
};
|
||||
let mut cc = self.client.containers();
|
||||
|
||||
let responce = cc
|
||||
let response = cc
|
||||
.list(with_namespace!(request, namespace))
|
||||
.await?
|
||||
.into_inner();
|
||||
let container = responce
|
||||
let container = response
|
||||
.containers
|
||||
.iter()
|
||||
.find(|container| container.id == cid);
|
||||
@ -161,15 +161,15 @@ impl Service {
|
||||
let request = ListTasksRequest {
|
||||
filter: format!("container=={}", cid),
|
||||
};
|
||||
let responce = tc
|
||||
let response = tc
|
||||
.list(with_namespace!(request, namespace))
|
||||
.await?
|
||||
.into_inner();
|
||||
println!("Tasks: {:?}", responce.tasks);
|
||||
log::info!("Tasks: {:?}", response.tasks);
|
||||
drop(tc);
|
||||
|
||||
if let Some(task) = responce.tasks.iter().find(|task| task.id == container.id) {
|
||||
println!("Task found: {}, Status: {}", task.id, task.status);
|
||||
if let Some(task) = response.tasks.iter().find(|task| task.id == container.id) {
|
||||
log::info!("Task found: {}, Status: {}", task.id, task.status);
|
||||
// TASK_UNKNOWN (0) — 未知状态
|
||||
// TASK_CREATED (1) — 任务已创建
|
||||
// TASK_RUNNING (2) — 任务正在运行
|
||||
@ -192,7 +192,7 @@ impl Service {
|
||||
//todo 这里删除cni?
|
||||
self.remove_netns_ip(cid).await;
|
||||
|
||||
println!("Container: {:?} deleted", cc);
|
||||
log::info!("Container: {:?} deleted", cc);
|
||||
} else {
|
||||
todo!("Container not found");
|
||||
}
|
||||
@ -227,17 +227,17 @@ impl Service {
|
||||
.into_inner()
|
||||
.mounts;
|
||||
|
||||
println!("mounts ok");
|
||||
log::info!("mounts ok");
|
||||
drop(sc);
|
||||
println!("drop sc ok");
|
||||
log::info!("drop sc ok");
|
||||
let _ = cni::init_net_work();
|
||||
println!("init_net_work ok");
|
||||
log::info!("init_net_work ok");
|
||||
let (ip, path) = cni::create_cni_network(cid.to_string(), ns.to_string())?;
|
||||
let ports = ImageManager::get_runtime_config(img_name).unwrap().ports;
|
||||
let network_config = NetworkConfig::new(path, ip, ports);
|
||||
println!("create_cni_network ok");
|
||||
log::info!("create_cni_network ok");
|
||||
self.save_network_config(cid, network_config.clone()).await;
|
||||
println!("save_netns_ip ok, netconfig: {:?}", network_config);
|
||||
log::info!("save_netns_ip ok, netconfig: {:?}", network_config);
|
||||
let mut tc = self.client.tasks();
|
||||
let req = CreateTaskRequest {
|
||||
container_id: cid.to_string(),
|
||||
@ -255,7 +255,7 @@ impl Service {
|
||||
..Default::default()
|
||||
};
|
||||
let _resp = self.client.tasks().start(with_namespace!(req, ns)).await?;
|
||||
println!("Task: {:?} started", cid);
|
||||
log::info!("Task: {:?} started", cid);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -299,7 +299,7 @@ impl Service {
|
||||
Ok::<(), Err>(())
|
||||
})
|
||||
.await;
|
||||
println!(" after wait");
|
||||
log::info!("after wait");
|
||||
|
||||
let kill_request = KillRequest {
|
||||
container_id: cid.to_string(),
|
||||
@ -324,17 +324,17 @@ impl Service {
|
||||
// println!("Task: {:?} deleted", cid);
|
||||
match c.delete(with_namespace!(req, namespace)).await {
|
||||
Ok(_) => {
|
||||
println!("Task: {:?} deleted", cid);
|
||||
log::info!("Task: {:?} deleted", cid);
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Failed to delete task: {}", e);
|
||||
log::error!("Failed to delete task: {}", e);
|
||||
Err(e.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
eprintln!("Wait task failed: {}", e);
|
||||
log::error!("Wait task failed: {}", e);
|
||||
Err(e)
|
||||
}
|
||||
Err(_) => {
|
||||
@ -346,11 +346,11 @@ impl Service {
|
||||
};
|
||||
match c.kill(with_namespace!(kill_request, namespace)).await {
|
||||
Ok(_) => {
|
||||
println!("Task: {:?} force killed", cid);
|
||||
log::info!("Task: {:?} force killed", cid);
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Failed to force kill task: {}", e);
|
||||
log::error!("Failed to force kill task: {}", e);
|
||||
Err(e.into())
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user