mirror of
https://git.asonix.dog/asonix/pict-rs.git
synced 2024-11-24 18:41:06 +00:00
Promote console from compile flag to runtime flag
This commit is contained in:
parent
f13f870a92
commit
2ad536db17
4 changed files with 31 additions and 33 deletions
|
@ -10,7 +10,6 @@ edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
[features]
|
[features]
|
||||||
console = ["console-subscriber"]
|
|
||||||
default = ["object-storage"]
|
default = ["object-storage"]
|
||||||
object-storage = ["reqwest", "rust-s3"]
|
object-storage = ["reqwest", "rust-s3"]
|
||||||
io-uring = [
|
io-uring = [
|
||||||
|
@ -30,7 +29,7 @@ async-trait = "0.1.51"
|
||||||
awc = { version = "3.0.0", default-features = false, features = ["rustls"] }
|
awc = { version = "3.0.0", default-features = false, features = ["rustls"] }
|
||||||
base64 = "0.13.0"
|
base64 = "0.13.0"
|
||||||
config = "0.12.0"
|
config = "0.12.0"
|
||||||
console-subscriber = { version = "0.1", optional = true }
|
console-subscriber = "0.1"
|
||||||
dashmap = "5.1.0"
|
dashmap = "5.1.0"
|
||||||
futures-util = "0.3.17"
|
futures-util = "0.3.17"
|
||||||
mime = "0.3.1"
|
mime = "0.3.1"
|
||||||
|
|
|
@ -82,7 +82,6 @@ pub(crate) struct Overrides {
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
sled_cache_capacity: Option<u64>,
|
sled_cache_capacity: Option<u64>,
|
||||||
|
|
||||||
#[cfg(feature = "console")]
|
|
||||||
#[structopt(
|
#[structopt(
|
||||||
long,
|
long,
|
||||||
help = "Specify the number of events the console subscriber is allowed to buffer"
|
help = "Specify the number of events the console subscriber is allowed to buffer"
|
||||||
|
@ -122,19 +121,11 @@ impl Overrides {
|
||||||
&& self.max_image_height.is_none()
|
&& self.max_image_height.is_none()
|
||||||
&& self.max_image_area.is_none()
|
&& self.max_image_area.is_none()
|
||||||
&& self.sled_cache_capacity.is_none()
|
&& self.sled_cache_capacity.is_none()
|
||||||
&& self.default_console_settings()
|
&& self.console_buffer_capacity.is_none()
|
||||||
&& self.api_key.is_none()
|
&& self.api_key.is_none()
|
||||||
&& self.opentelemetry_url.is_none()
|
&& self.opentelemetry_url.is_none()
|
||||||
&& self.store.is_none()
|
&& self.store.is_none()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_console_settings(&self) -> bool {
|
|
||||||
#[cfg(feature = "console")]
|
|
||||||
return self.console_buffer_capacity.is_none();
|
|
||||||
|
|
||||||
#[cfg(not(feature = "console"))]
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||||
|
@ -209,8 +200,7 @@ pub(crate) struct Config {
|
||||||
max_image_height: usize,
|
max_image_height: usize,
|
||||||
max_image_area: usize,
|
max_image_area: usize,
|
||||||
sled_cache_capacity: u64,
|
sled_cache_capacity: u64,
|
||||||
#[cfg(feature = "console")]
|
console_buffer_capacity: Option<usize>,
|
||||||
console_buffer_capacity: usize,
|
|
||||||
api_key: Option<String>,
|
api_key: Option<String>,
|
||||||
opentelemetry_url: Option<Url>,
|
opentelemetry_url: Option<Url>,
|
||||||
store: Store,
|
store: Store,
|
||||||
|
@ -226,8 +216,6 @@ pub(crate) struct Defaults {
|
||||||
max_image_height: usize,
|
max_image_height: usize,
|
||||||
max_image_area: usize,
|
max_image_area: usize,
|
||||||
sled_cache_capacity: u64,
|
sled_cache_capacity: u64,
|
||||||
#[cfg(feature = "console")]
|
|
||||||
console_buffer_capacity: usize,
|
|
||||||
store: Store,
|
store: Store,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,8 +229,6 @@ impl Defaults {
|
||||||
max_image_height: 10_000,
|
max_image_height: 10_000,
|
||||||
max_image_area: 40_000_000,
|
max_image_area: 40_000_000,
|
||||||
sled_cache_capacity: 1024 * 1024 * 64, // 16 times smaller than sled's default of 1GB
|
sled_cache_capacity: 1024 * 1024 * 64, // 16 times smaller than sled's default of 1GB
|
||||||
#[cfg(feature = "console")]
|
|
||||||
console_buffer_capacity: 1024 * 128,
|
|
||||||
store: Store::FileStore { path: None },
|
store: Store::FileStore { path: None },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -298,8 +284,7 @@ impl Config {
|
||||||
self.sled_cache_capacity
|
self.sled_cache_capacity
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "console")]
|
pub(crate) fn console_buffer_capacity(&self) -> Option<usize> {
|
||||||
pub(crate) fn console_buffer_capacity(&self) -> usize {
|
|
||||||
self.console_buffer_capacity
|
self.console_buffer_capacity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
#[cfg(feature = "console")]
|
|
||||||
use console_subscriber::ConsoleLayer;
|
use console_subscriber::ConsoleLayer;
|
||||||
use opentelemetry::{
|
use opentelemetry::{
|
||||||
sdk::{propagation::TraceContextPropagator, Resource},
|
sdk::{propagation::TraceContextPropagator, Resource},
|
||||||
|
@ -9,14 +8,15 @@ use tracing::subscriber::set_global_default;
|
||||||
use tracing_error::ErrorLayer;
|
use tracing_error::ErrorLayer;
|
||||||
use tracing_log::LogTracer;
|
use tracing_log::LogTracer;
|
||||||
use tracing_subscriber::{
|
use tracing_subscriber::{
|
||||||
filter::Targets, fmt::format::FmtSpan, layer::SubscriberExt, Layer, Registry,
|
filter::Targets, fmt::format::FmtSpan, layer::SubscriberExt, registry::LookupSpan, Layer,
|
||||||
|
Registry,
|
||||||
};
|
};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
pub(super) fn init_tracing(
|
pub(super) fn init_tracing(
|
||||||
servic_name: &'static str,
|
servic_name: &'static str,
|
||||||
opentelemetry_url: Option<&Url>,
|
opentelemetry_url: Option<&Url>,
|
||||||
#[cfg(feature = "console")] buffer_capacity: usize,
|
buffer_capacity: Option<usize>,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
LogTracer::init()?;
|
LogTracer::init()?;
|
||||||
|
|
||||||
|
@ -30,20 +30,35 @@ pub(super) fn init_tracing(
|
||||||
.with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
|
.with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
|
||||||
.with_filter(targets.clone());
|
.with_filter(targets.clone());
|
||||||
|
|
||||||
#[cfg(feature = "console")]
|
let subscriber = Registry::default()
|
||||||
|
.with(format_layer)
|
||||||
|
.with(ErrorLayer::default());
|
||||||
|
|
||||||
|
if let Some(buffer_capacity) = buffer_capacity {
|
||||||
let console_layer = ConsoleLayer::builder()
|
let console_layer = ConsoleLayer::builder()
|
||||||
.with_default_env()
|
.with_default_env()
|
||||||
.event_buffer_capacity(buffer_capacity)
|
.event_buffer_capacity(buffer_capacity)
|
||||||
.server_addr(([0, 0, 0, 0], 6669))
|
.server_addr(([0, 0, 0, 0], 6669))
|
||||||
.spawn();
|
.spawn();
|
||||||
|
|
||||||
let subscriber = Registry::default()
|
|
||||||
.with(format_layer)
|
|
||||||
.with(ErrorLayer::default());
|
|
||||||
|
|
||||||
#[cfg(feature = "console")]
|
|
||||||
let subscriber = subscriber.with(console_layer);
|
let subscriber = subscriber.with(console_layer);
|
||||||
|
|
||||||
|
with_otel(subscriber, targets, servic_name, opentelemetry_url)
|
||||||
|
} else {
|
||||||
|
with_otel(subscriber, targets, servic_name, opentelemetry_url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn with_otel<S>(
|
||||||
|
subscriber: S,
|
||||||
|
targets: Targets,
|
||||||
|
servic_name: &'static str,
|
||||||
|
opentelemetry_url: Option<&Url>,
|
||||||
|
) -> anyhow::Result<()>
|
||||||
|
where
|
||||||
|
S: SubscriberExt + Send + Sync,
|
||||||
|
for<'a> S: LookupSpan<'a>,
|
||||||
|
{
|
||||||
if let Some(url) = opentelemetry_url {
|
if let Some(url) = opentelemetry_url {
|
||||||
let tracer =
|
let tracer =
|
||||||
opentelemetry_otlp::new_pipeline()
|
opentelemetry_otlp::new_pipeline()
|
||||||
|
|
|
@ -885,7 +885,6 @@ async fn main() -> anyhow::Result<()> {
|
||||||
init_tracing(
|
init_tracing(
|
||||||
"pict-rs",
|
"pict-rs",
|
||||||
CONFIG.opentelemetry_url(),
|
CONFIG.opentelemetry_url(),
|
||||||
#[cfg(feature = "console")]
|
|
||||||
CONFIG.console_buffer_capacity(),
|
CONFIG.console_buffer_capacity(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue