forked from Deuxfleurs/garage
Compare commits
1 commit
main
...
feat/traci
Author | SHA1 | Date | |
---|---|---|---|
26b5c6477f |
7 changed files with 54 additions and 31 deletions
12
Cargo.lock
generated
12
Cargo.lock
generated
|
@ -1355,6 +1355,7 @@ dependencies = [
|
|||
"tokio",
|
||||
"toml",
|
||||
"tracing",
|
||||
"tracing-journald",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
|
@ -4406,6 +4407,17 @@ dependencies = [
|
|||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-journald"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba316a74e8fc3c3896a850dba2375928a9fa171b085ecddfc7c054d39970f3fd"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"tracing-core",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-log"
|
||||
version = "0.2.0"
|
||||
|
|
|
@ -79,6 +79,7 @@ pretty_env_logger = "0.5"
|
|||
structopt = { version = "0.3", default-features = false }
|
||||
syslog-tracing = "0.3"
|
||||
tracing = "0.1"
|
||||
tracing-journald = "0.3"
|
||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||
|
||||
heed = { version = "0.11", default-features = false, features = ["lmdb"] }
|
||||
|
|
|
@ -16,7 +16,6 @@ data_dir = "/var/lib/garage/data"
|
|||
metadata_fsync = true
|
||||
data_fsync = false
|
||||
disable_scrub = false
|
||||
use_local_tz = false
|
||||
metadata_auto_snapshot_interval = "6h"
|
||||
|
||||
db_engine = "lmdb"
|
||||
|
@ -100,7 +99,6 @@ Top-level configuration options:
|
|||
[`data_fsync`](#data_fsync),
|
||||
[`db_engine`](#db_engine),
|
||||
[`disable_scrub`](#disable_scrub),
|
||||
[`use_local_tz`](#use_local_tz),
|
||||
[`lmdb_map_size`](#lmdb_map_size),
|
||||
[`metadata_auto_snapshot_interval`](#metadata_auto_snapshot_interval),
|
||||
[`metadata_dir`](#metadata_dir),
|
||||
|
@ -429,13 +427,6 @@ you should delete it from the data directory and then call `garage repair
|
|||
blocks` on the node to ensure that it re-obtains a copy from another node on
|
||||
the network.
|
||||
|
||||
#### `use_local_tz` {#use_local_tz}
|
||||
|
||||
By default, Garage runs the lifecycle worker every day at midnight in UTC. Set the
|
||||
`use_local_tz` configuration value to `true` if you want Garage to run the
|
||||
lifecycle worker at midnight in your local timezone. If you have multiple nodes,
|
||||
you should also ensure that each node has the same timezone configuration.
|
||||
|
||||
#### `block_size` {#block_size}
|
||||
|
||||
Garage splits stored objects in consecutive chunks of size `block_size`
|
||||
|
|
|
@ -60,6 +60,7 @@ opentelemetry-prometheus = { workspace = true, optional = true }
|
|||
opentelemetry-otlp = { workspace = true, optional = true }
|
||||
prometheus = { workspace = true, optional = true }
|
||||
syslog-tracing = { workspace = true, optional = true }
|
||||
tracing-journald = { workspace = true, optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
aws-config.workspace = true
|
||||
|
@ -100,6 +101,8 @@ metrics = [ "garage_api/metrics", "opentelemetry-prometheus", "prometheus" ]
|
|||
telemetry-otlp = [ "opentelemetry-otlp" ]
|
||||
# Logging to syslog
|
||||
syslog = [ "syslog-tracing" ]
|
||||
# Logging to journald
|
||||
journald = [ "tracing-journald" ]
|
||||
|
||||
# NOTE: bundled-libs and system-libs should be treat as mutually exclusive;
|
||||
# exactly one of them should be enabled.
|
||||
|
|
|
@ -208,6 +208,36 @@ fn init_logging(opt: &Opt) {
|
|||
}
|
||||
}
|
||||
|
||||
if std::env::var("GARAGE_LOG_TO_JOURNALD")
|
||||
.map(|x| x == "1" || x == "true")
|
||||
.unwrap_or(false)
|
||||
{
|
||||
#[cfg(feature = "journald")]
|
||||
{
|
||||
use tracing_subscriber::layer::SubscriberExt;
|
||||
use tracing_subscriber::util::SubscriberInitExt;
|
||||
|
||||
let registry = tracing_subscriber::registry()
|
||||
.with(tracing_subscriber::fmt::layer().with_writer(std::io::sink))
|
||||
.with(env_filter);
|
||||
match tracing_journald::layer() {
|
||||
Ok(layer) => {
|
||||
registry.with(layer).init();
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Couldn't connect to journald: {}.", e);
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
#[cfg(not(feature = "journald"))]
|
||||
{
|
||||
eprintln!("Journald support is not enabled in this build.");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
tracing_subscriber::fmt()
|
||||
.with_writer(std::io::stderr)
|
||||
.with_env_filter(env_filter)
|
||||
|
|
|
@ -70,7 +70,7 @@ pub fn register_bg_vars(
|
|||
|
||||
impl LifecycleWorker {
|
||||
pub fn new(garage: Arc<Garage>, persister: PersisterShared<LifecycleWorkerPersisted>) -> Self {
|
||||
let today = today(garage.config.use_local_tz);
|
||||
let today = today();
|
||||
let last_completed = persister.get_with(|x| {
|
||||
x.last_completed
|
||||
.as_deref()
|
||||
|
@ -205,9 +205,8 @@ impl Worker for LifecycleWorker {
|
|||
async fn wait_for_work(&mut self) -> WorkerState {
|
||||
match &self.state {
|
||||
State::Completed(d) => {
|
||||
let use_local_tz = self.garage.config.use_local_tz;
|
||||
let next_day = d.succ_opt().expect("no next day");
|
||||
let next_start = midnight_ts(next_day, use_local_tz);
|
||||
let next_start = midnight_ts(next_day);
|
||||
loop {
|
||||
let now = now_msec();
|
||||
if now < next_start {
|
||||
|
@ -219,7 +218,7 @@ impl Worker for LifecycleWorker {
|
|||
break;
|
||||
}
|
||||
}
|
||||
self.state = State::start(std::cmp::max(next_day, today(use_local_tz)));
|
||||
self.state = State::start(std::cmp::max(next_day, today()));
|
||||
}
|
||||
State::Running { .. } => (),
|
||||
}
|
||||
|
@ -386,16 +385,10 @@ fn check_size_filter(version_data: &ObjectVersionData, filter: &LifecycleFilter)
|
|||
true
|
||||
}
|
||||
|
||||
fn midnight_ts(date: NaiveDate, use_local_tz: bool) -> u64 {
|
||||
let midnight = date.and_hms_opt(0, 0, 0).expect("midnight does not exist");
|
||||
if use_local_tz {
|
||||
return midnight
|
||||
.and_local_timezone(Local)
|
||||
.single()
|
||||
.expect("bad local midnight")
|
||||
.timestamp_millis() as u64;
|
||||
}
|
||||
midnight.timestamp_millis() as u64
|
||||
fn midnight_ts(date: NaiveDate) -> u64 {
|
||||
date.and_hms_opt(0, 0, 0)
|
||||
.expect("midnight does not exist")
|
||||
.timestamp_millis() as u64
|
||||
}
|
||||
|
||||
fn next_date(ts: u64) -> NaiveDate {
|
||||
|
@ -406,9 +399,6 @@ fn next_date(ts: u64) -> NaiveDate {
|
|||
.expect("no next day")
|
||||
}
|
||||
|
||||
fn today(use_local_tz: bool) -> NaiveDate {
|
||||
if use_local_tz {
|
||||
return Local::now().naive_local().date();
|
||||
}
|
||||
fn today() -> NaiveDate {
|
||||
Utc::now().naive_utc().date()
|
||||
}
|
||||
|
|
|
@ -27,10 +27,6 @@ pub struct Config {
|
|||
#[serde(default)]
|
||||
pub disable_scrub: bool,
|
||||
|
||||
/// Use local timezone
|
||||
#[serde(default)]
|
||||
pub use_local_tz: bool,
|
||||
|
||||
/// Automatic snapshot interval for metadata
|
||||
#[serde(default)]
|
||||
pub metadata_auto_snapshot_interval: Option<String>,
|
||||
|
|
Loading…
Reference in a new issue