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

fix: fix manager log rotation #1806

Closed
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
3 changes: 2 additions & 1 deletion packages/infra/client/logs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{os::fd::AsRawFd, path::PathBuf};

use anyhow::*;
use chrono::{Datelike, Duration, TimeZone, Utc};
use chrono::{Datelike, Duration, TimeDelta, TimeZone, Utc};
use tokio::fs;

pub struct Logs {
Expand Down Expand Up @@ -40,6 +40,7 @@ impl Logs {
if self.next_rotation - now > Duration::seconds(5) {
tokio::time::sleep(
(self.next_rotation - now - Duration::seconds(5))
.max(TimeDelta::default())
.to_std()
.expect("bad duration"),
)
Expand Down
18 changes: 16 additions & 2 deletions packages/infra/client/manager/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ fn main() -> Result<()> {
init_tracing();

let init = { Runtime::new()?.block_on(init())? };
let mut first = true;

// Retry loop
loop {
let runtime = Builder::new_multi_thread().enable_all().build()?;

match runtime.block_on(run(init.clone())) {
match runtime.block_on(run(init.clone(), first)) {
Ok(_) => return Ok(()),
Err(err) => {
// Only restart if its a `RuntimeError`
Expand All @@ -58,6 +59,8 @@ fn main() -> Result<()> {
}
}

first = false;

std::thread::sleep(Duration::from_secs(2));
}
}
Expand Down Expand Up @@ -173,7 +176,18 @@ async fn init() -> Result<Init> {
})
}

async fn run(init: Init) -> Result<()> {
async fn run(init: Init, first: bool) -> Result<()> {
// We have to redirect logs here as well because the entire tokio runtime gets destroyed after a runtime
// error
if !first && init.config.client.logs.redirect_logs() {
pegboard_logs::Logs::new(
init.config.client.data_dir().join("logs"),
init.config.client.logs.retention(),
)
.start()
.await?;
}

// Start metrics server
let metrics_thread = tokio::spawn(metrics::run_standalone(init.config.client.metrics.port()));

Expand Down