From 62615be3711e5b6a8ed7f0b0555e80e491287632 Mon Sep 17 00:00:00 2001 From: "Aode (Lion)" Date: Mon, 21 Mar 2022 21:55:25 -0500 Subject: [PATCH] Allow configuring console buffer capacity --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 29 ++++++++++++++++++----------- src/config.rs | 16 ++++++++++++++++ src/init_tracing.rs | 3 ++- src/main.rs | 7 ++++++- 6 files changed, 44 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8a67eda..0b367ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1580,7 +1580,7 @@ dependencies = [ [[package]] name = "pict-rs" -version = "0.3.0-rc.5" +version = "0.3.0-rc.6" dependencies = [ "actix-form-data", "actix-rt", diff --git a/Cargo.toml b/Cargo.toml index 5d683ce..66abe89 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "pict-rs" description = "A simple image hosting service" -version = "0.3.0-rc.5" +version = "0.3.0-rc.6" authors = ["asonix "] license = "AGPL-3.0" readme = "README.md" diff --git a/README.md b/README.md index 034dbf7..c06787a 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ _a simple image hosting service_ ## Usage ### Running ``` -pict-rs 0.3.0-rc.5 +pict-rs 0.3.0-rc.6 USAGE: pict-rs [FLAGS] [OPTIONS] [SUBCOMMAND] @@ -20,32 +20,39 @@ FLAGS: -V, --version Prints version information OPTIONS: - -a, --addr The address and port the server binds to. + -a, --addr The address and port the server binds to. --api-key An optional string to be checked on requests to privileged endpoints - -c, --config-file Path to the pict-rs configuration file + -c, --config-file Path to the pict-rs configuration file + --console-buffer-capacity + Specify the number of events the console subscriber is allowed to buffer + -f, --filters ... An optional list of filters to permit, supports 'identity', 'thumbnail', 'resize', 'crop', and 'blur' -i, --image-format An optional image format to convert all uploaded files into, supports 'jpg', 'png', and 'webp' - -m, --max-file-size Specify the maximum allowed uploaded file size (in Megabytes) - --max-image-area Specify the maximum area in pixels allowed in an image - --max-image-height Specify the maximum width in pixels allowed on an image - --max-image-width Specify the maximum width in pixels allowed on an image - --migrate-file Path to a file defining a store migration + -m, --max-file-size + Specify the maximum allowed uploaded file size (in Megabytes) + + --max-image-area Specify the maximum area in pixels allowed in an image + --max-image-height Specify the maximum width in pixels allowed on an image + --max-image-width Specify the maximum width in pixels allowed on an image + --migrate-file Path to a file defining a store migration -o, --opentelemetry-url Enable OpenTelemetry Tracing exports to the given OpenTelemetry collector - -p, --path The path to the data directory, e.g. data/ - --sled-cache-capacity Specify the number of bytes sled is allowed to use for it's cache + -p, --path The path to the data directory, e.g. data/ + --sled-cache-capacity + Specify the number of bytes sled is allowed to use for it's cache + SUBCOMMANDS: file-store help Prints this message or the help of the given subcommand(s) - s3-store + s3-store ``` ``` diff --git a/src/config.rs b/src/config.rs index ecbe427..5f58098 100644 --- a/src/config.rs +++ b/src/config.rs @@ -82,6 +82,13 @@ pub(crate) struct Overrides { #[serde(skip_serializing_if = "Option::is_none")] sled_cache_capacity: Option, + #[structopt( + long, + help = "Specify the number of events the console subscriber is allowed to buffer" + )] + #[serde(skip_serializing_if = "Option::is_none")] + console_buffer_capacity: Option, + #[structopt( long, help = "An optional string to be checked on requests to privileged endpoints" @@ -114,6 +121,7 @@ impl Overrides { && self.max_image_height.is_none() && self.max_image_area.is_none() && self.sled_cache_capacity.is_none() + && self.console_buffer_capacity.is_none() && self.api_key.is_none() && self.opentelemetry_url.is_none() && self.store.is_none() @@ -192,6 +200,7 @@ pub(crate) struct Config { max_image_height: usize, max_image_area: usize, sled_cache_capacity: u64, + console_buffer_capacity: usize, api_key: Option, opentelemetry_url: Option, store: Store, @@ -207,6 +216,7 @@ pub(crate) struct Defaults { max_image_height: usize, max_image_area: usize, sled_cache_capacity: u64, + console_buffer_capacity: usize, store: Store, } @@ -220,6 +230,7 @@ impl Defaults { max_image_height: 10_000, max_image_area: 40_000_000, sled_cache_capacity: 1024 * 1024 * 64, // 16 times smaller than sled's default of 1GB + console_buffer_capacity: 1024 * 128, store: Store::FileStore { path: None }, } } @@ -275,6 +286,11 @@ impl Config { self.sled_cache_capacity } + #[cfg(feature = "console")] + pub(crate) fn console_buffer_capacity(&self) -> usize { + self.console_buffer_capacity + } + pub(crate) fn format(&self) -> Option { self.image_format } diff --git a/src/init_tracing.rs b/src/init_tracing.rs index 587cc59..e4cd2d5 100644 --- a/src/init_tracing.rs +++ b/src/init_tracing.rs @@ -16,6 +16,7 @@ use url::Url; pub(super) fn init_tracing( servic_name: &'static str, opentelemetry_url: Option<&Url>, + #[cfg(feature = "console")] buffer_capacity: usize, ) -> anyhow::Result<()> { LogTracer::init()?; @@ -32,7 +33,7 @@ pub(super) fn init_tracing( #[cfg(feature = "console")] let console_layer = ConsoleLayer::builder() .with_default_env() - .event_buffer_capacity(1024 * 1024) + .event_buffer_capacity(buffer_capacity) .server_addr(([0, 0, 0, 0], 6669)) .spawn(); diff --git a/src/main.rs b/src/main.rs index 8bda459..bce5b6a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -882,7 +882,12 @@ where #[actix_rt::main] async fn main() -> anyhow::Result<()> { - init_tracing("pict-rs", CONFIG.opentelemetry_url())?; + init_tracing( + "pict-rs", + CONFIG.opentelemetry_url(), + #[cfg(feature = "console")] + CONFIG.console_buffer_capacity(), + )?; let db = LatestDb::exists(CONFIG.data_dir(), CONFIG.sled_cache_capacity()).migrate()?;