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

Retry connection with the backend of access logs #1100

Merged
merged 6 commits into from
Jul 17, 2024
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
6 changes: 4 additions & 2 deletions bin/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use mio::net::UnixListener;

use sozu_command_lib::{
config::{Config, ConfigError},
logging::setup_logging_with_config,
logging::{setup_logging_with_config, LogError},
};

use crate::{
Expand Down Expand Up @@ -52,14 +52,16 @@ pub enum StartError {
SetPermissions(IoError),
#[error("could not launch new worker: {0}")]
LaunchWorker(ServerError),
#[error("could not setup the logger: {0}")]
SetupLogging(LogError),
}

pub fn begin_main_process(args: &Args) -> Result<(), StartError> {
let config_file_path = get_config_file_path(args).map_err(StartError::GetConfigPath)?;

let config = Config::load_from_path(config_file_path).map_err(StartError::LoadConfig)?;

setup_logging_with_config(&config, "MAIN");
setup_logging_with_config(&config, "MAIN").map_err(StartError::SetupLogging)?;
info!("Starting up");
setup_metrics(&config).map_err(StartError::SetupMetrics)?;
write_pid_file(&config).map_err(StartError::WritePidFile)?;
Expand Down
6 changes: 5 additions & 1 deletion bin/src/ctl/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ impl CommandManager {
let config = self.config.clone();

upgrade_jobs.push(std::thread::spawn(move || {
setup_logging_with_config(&config, &format!("UPGRADE-WRK-{}", worker.id));
if let Err(e) =
setup_logging_with_config(&config, &format!("UPGRADE-WRK-{}", worker.id))
{
error!("Could not setup logging: {}", e);
}

info!("creating channel to upgrade worker {}", worker.id);
let channel = match create_channel(&config) {
Expand Down
6 changes: 4 additions & 2 deletions bin/src/ctl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use sozu_command_lib::{
certificate::CertificateError,
channel::{Channel, ChannelError},
config::{Config, ConfigError},
logging::setup_logging_with_config,
logging::{setup_logging_with_config, LogError},
proto::{
command::{Request, Response},
DisplayError,
Expand Down Expand Up @@ -53,6 +53,8 @@ pub enum CtlError {
NeedClusterDomain,
#[error("wrong response from Sōzu: {0:?}")]
WrongResponse(Response),
#[error("could not setup the logger: {0}")]
SetupLogging(LogError),
}

pub struct CommandManager {
Expand All @@ -70,7 +72,7 @@ pub fn ctl(args: cli::Args) -> Result<(), CtlError> {

// prevent logging for json responses for a clean output
if !args.json {
setup_logging_with_config(&config, "CTL");
setup_logging_with_config(&config, "CTL").map_err(CtlError::SetupLogging)?;
}

// If the command is `config check` then exit because if we are here, the configuration is valid
Expand Down
6 changes: 4 additions & 2 deletions bin/src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use tempfile::tempfile;

use sozu_command_lib::{
channel::{Channel, ChannelError},
logging::setup_logging_with_config,
logging::{setup_logging_with_config, LogError},
};

use crate::{
Expand Down Expand Up @@ -69,6 +69,8 @@ pub enum UpgradeError {
CreateHub(HubError),
#[error("could not enable cloexec after upgrade: {0}")]
EnableCloexec(ServerError),
#[error("could not setup the logger: {0}")]
SetupLogging(LogError),
}

/// unix-forks the main process
Expand Down Expand Up @@ -180,7 +182,7 @@ pub fn begin_new_main_process(

println!("Setting up logging");

setup_logging_with_config(&config, "MAIN");
setup_logging_with_config(&config, "MAIN").map_err(UpgradeError::SetupLogging)?;
util::setup_metrics(&config).map_err(UpgradeError::SetupMetrics)?;

let mut command_hub =
Expand Down
7 changes: 5 additions & 2 deletions bin/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use tempfile::tempfile;
use sozu_command_lib::{
channel::{Channel, ChannelError},
config::Config,
logging::{setup_logging, AccessLogFormat},
logging::{setup_logging, AccessLogFormat, LogError},
proto::command::{ServerConfig, WorkerRequest, WorkerResponse},
ready::Ready,
request::{read_initial_state_from_file, RequestError},
Expand Down Expand Up @@ -74,6 +74,8 @@ pub enum WorkerError {
state: String,
channel_err: ChannelError,
},
#[error("could not setup the logger: {0}")]
SetupLogging(LogError),
}

/// called within a worker process, this starts the actual proxy
Expand Down Expand Up @@ -117,7 +119,8 @@ pub fn begin_worker_process(
Some(worker_config.log_colored),
&worker_config.log_level,
&worker_id,
);
)
.map_err(WorkerError::SetupLogging)?;

trace!(
"Creating worker {} with config: {:#?}",
Expand Down
4 changes: 3 additions & 1 deletion command/examples/bench_logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ fn main() {
eprintln!(
"n={n}, pre_generate={pre_generate}, target={target}, colored={colored}, filter={filter}"
);
setup_logging(&target, colored, None, None, None, &filter, "WRK-01");
if let Err(e) = setup_logging(&target, colored, None, None, None, &filter, "BENCH") {
println!("Could not setup logging: {}", e);
}

let mut pre_generated_log_iterator;
let mut log_iterator = std::iter::repeat(())
Expand Down
3 changes: 3 additions & 0 deletions command/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ pub const MAX_LOOP_ITERATIONS: usize = 100000;
/// with little influence on performance. Defaults to 4.
pub const DEFAULT_SEND_TLS_13_TICKETS: u64 = 4;

/// for both logs and access logs
pub const DEFAULT_LOG_TARGET: &str = "stdout";

#[derive(Debug)]
pub enum IncompatibilityKind {
PublicAddress,
Expand Down
Loading
Loading