Skip to content

Commit

Permalink
chore(logger): make default level to INFO
Browse files Browse the repository at this point in the history
* Update riklet, rikctl and controller loggers to have INFO as default
  level
* Remove traits and utils rust files from riklet to move them into
  main.rs, to remove the number of modules

Signed-off-by: AlexandreBrg <[email protected]>
  • Loading branch information
alexandrebrg committed Apr 24, 2023
1 parent f80c3f8 commit 8273dfc
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 49 deletions.
8 changes: 6 additions & 2 deletions controller/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::thread;

use crate::database::RikDataBase;
use api::{external, ApiChannel};
use tracing::{event, Level};
use tracing::{event, metadata::LevelFilter, Level};
use tracing_subscriber::{
fmt, prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, EnvFilter,
};
Expand All @@ -19,7 +19,11 @@ use tokio::runtime::Builder;
fn logger_setup() {
tracing_subscriber::registry()
.with(fmt::layer())
.with(EnvFilter::from_default_env())
.with(
EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.from_env_lossy(),
)
.init();
}

Expand Down
5 changes: 2 additions & 3 deletions riklet/src/core.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::banner;
use crate::cli::config::{Configuration, ConfigurationError};
use crate::emitters::metrics_emitter::MetricsEmitter;
use crate::runtime::network::{GlobalRuntimeNetwork, NetworkError, RuntimeNetwork};
use crate::runtime::{DynamicRuntimeManager, Runtime, RuntimeConfigurator, RuntimeError};
use crate::structs::WorkloadDefinition;
use crate::traits::EventEmitter;
use crate::utils::banner;
use crate::structs::{EventEmitter, WorkloadDefinition};
use definition::InstanceStatus;
use proto::common::WorkerRegistration;
use proto::worker::worker_client::WorkerClient;
Expand Down
2 changes: 1 addition & 1 deletion riklet/src/emitters/metrics_emitter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::traits::EventEmitter;
use crate::structs::EventEmitter;
use futures_util::stream;
use node_metrics::metrics_manager::MetricsManager;
use proto::common::{WorkerMetric, WorkerStatus};
Expand Down
33 changes: 29 additions & 4 deletions riklet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,39 @@ mod iptables;
mod net_utils;
mod runtime;
mod structs;
mod traits;
mod utils;

use crate::core::Riklet;
use crate::utils::init_logger;
use anyhow::Result;

use tracing::error;
use tracing::{error, metadata::LevelFilter};
use tracing_subscriber::{
fmt, prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, EnvFilter,
};

pub fn banner() {
println!(
r#"
______ _____ _ __ _ _____ _____
| ___ \_ _| | / /| | | ___|_ _|
| |_/ / | | | |/ / | | | |__ | |
| / | | | \ | | | __| | |
| |\ \ _| |_| |\ \| |____| |___ | |
\_| \_|\___/\_| \_/\_____/\____/ \_/
"#
);
}

pub fn init_logger() -> Result<()> {
tracing_subscriber::registry()
.with(fmt::layer())
.with(
EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.from_env_lossy(),
)
.init();
Ok(())
}

#[tokio::main]
async fn main() -> Result<()> {
Expand Down
1 change: 1 addition & 0 deletions riklet/src/net_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub async fn set_link_up(iface_name: String) -> Result<(), rtnetlink::Error> {
}

#[tracing::instrument()]
/// For a given iface_name, tries to apply a ipv4/mask on it
pub async fn set_link_ipv4(
iface_name: String,
ipv4: Ipv4Addr,
Expand Down
19 changes: 14 additions & 5 deletions riklet/src/runtime/function_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::{
io::Write,
path::{Path, PathBuf},
};
use tracing::{debug, event, trace, Level};
use tracing::{debug, error, event, trace, Level};

use super::{network::function_network::FunctionRuntimeNetwork, Runtime, RuntimeManager};

Expand Down Expand Up @@ -97,9 +97,9 @@ impl FunctionRuntime {

#[async_trait]
impl Runtime for FunctionRuntime {
#[tracing::instrument(skip(self))]
#[tracing::instrument(skip(self), fields(id = %self.id))]
async fn up(&mut self) -> Result<()> {
event!(Level::DEBUG, "Pre-boot configuration for microVM");
debug!("Pre-boot configuration for microVM");

// Define tap name
self.network
Expand Down Expand Up @@ -131,10 +131,19 @@ impl Runtime for FunctionRuntime {
Ok(())
}

#[tracing::instrument(skip(self))]
#[tracing::instrument(skip(self), fields(id = %self.id))]
async fn down(&mut self) -> Result<()> {
debug!("Destroying function runtime vm");
let machine = self.machine.as_mut().unwrap();
let machine = match self.machine.as_mut() {
Some(machine) => Ok(machine),
None => {
error!("Trying to stop a microVM that is not running");
Err(RuntimeError::NotRunning(format!(
"microVM {} is not running",
self.id
)))
}
}?;

machine
.stop()
Expand Down
3 changes: 3 additions & 0 deletions riklet/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ pub enum RuntimeError {

#[error("Could not configure properly: {0:?}")]
FirepilotConfiguration(BuilderError),

#[error("Runtime expected to be running: {0}")]
NotRunning(String),
}

type Result<T> = std::result::Result<T, RuntimeError>;
Expand Down
8 changes: 8 additions & 0 deletions riklet/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ use serde::{Deserialize, Serialize};
use shared::utils::get_random_hash;
use tracing::{event, warn, Level};

#[async_trait::async_trait]
pub trait EventEmitter<U, T> {
async fn emit_event(
mut client: T,
event: U,
) -> std::result::Result<(), Box<dyn std::error::Error>>;
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct EnvConfig {
pub name: String,
Expand Down
7 changes: 0 additions & 7 deletions riklet/src/traits.rs

This file was deleted.

25 changes: 0 additions & 25 deletions riklet/src/utils.rs

This file was deleted.

7 changes: 6 additions & 1 deletion scheduler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use proto::controller::controller_server::ControllerServer;
use proto::worker::worker_server::WorkerServer;
use scheduler::Event;
use scheduler::{Controller, SchedulerError, Worker, WorkerRegisterChannelType};
use tracing::metadata::LevelFilter;
use tracing_subscriber::prelude::__tracing_subscriber_SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::{fmt, EnvFilter};
Expand Down Expand Up @@ -301,7 +302,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = ConfigParser::new()?;
tracing_subscriber::registry()
.with(fmt::layer())
.with(EnvFilter::from_default_env())
.with(
EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.from_env_lossy(),
)
.init();
info!("Starting up...");
let manager = Manager::run(config.workers_endpoint, config.controller_endpoint);
Expand Down
4 changes: 4 additions & 0 deletions scheduler/src/state_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,11 @@ impl StateManager {
self.action_minus_replicas(&request.workload_id, def_replicas)?;
} else {
info!("Workload is getting unscheduled");
// FIXME: We currently don't support workload deletion, we previously were putting the status
// to Destroying when deleting any instance of a workload, we don't want this behaviour.
// Destroying status for workload should only be used when deleting a workload.
// workload.status = ResourceStatus::Destroying;

// Keep workload replicas a 1 as we are going to 0 it will be deleted automatically
// by the state manager
workload.replicas = 1;
Expand Down
2 changes: 1 addition & 1 deletion scripts/tool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ sub_mkrootfs() {
--env MNT_DIR="${rootfs_dir_guest}" \
-v "${rootfs_dir_host}:/${rootfs_dir_guest}" ${origin_image} \
bash -s <<'EOF'
packages="udev systemd-sysv iproute2 nginx"
packages="udev systemd-sysv iproute2 nginx wget"
dirs="bin etc home lib lib64 opt root sbin usr var/lib/nginx"
echo "Mount rootfs on the system"
Expand Down

0 comments on commit 8273dfc

Please sign in to comment.