Allow configuring console buffer capacity
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
Aode (Lion) 2022-03-21 21:55:25 -05:00
parent bd26c60cd5
commit 62615be371
6 changed files with 44 additions and 15 deletions

2
Cargo.lock generated
View file

@ -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",

View file

@ -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 <asonix@asonix.dog>"]
license = "AGPL-3.0"
readme = "README.md"

View file

@ -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 <addr> The address and port the server binds to.
-a, --addr <addr> The address and port the server binds to.
--api-key <api-key>
An optional string to be checked on requests to privileged endpoints
-c, --config-file <config-file> Path to the pict-rs configuration file
-c, --config-file <config-file> Path to the pict-rs configuration file
--console-buffer-capacity <console-buffer-capacity>
Specify the number of events the console subscriber is allowed to buffer
-f, --filters <filters>...
An optional list of filters to permit, supports 'identity', 'thumbnail', 'resize', 'crop', and 'blur'
-i, --image-format <image-format>
An optional image format to convert all uploaded files into, supports 'jpg', 'png', and 'webp'
-m, --max-file-size <max-file-size> Specify the maximum allowed uploaded file size (in Megabytes)
--max-image-area <max-image-area> Specify the maximum area in pixels allowed in an image
--max-image-height <max-image-height> Specify the maximum width in pixels allowed on an image
--max-image-width <max-image-width> Specify the maximum width in pixels allowed on an image
--migrate-file <migrate-file> Path to a file defining a store migration
-m, --max-file-size <max-file-size>
Specify the maximum allowed uploaded file size (in Megabytes)
--max-image-area <max-image-area> Specify the maximum area in pixels allowed in an image
--max-image-height <max-image-height> Specify the maximum width in pixels allowed on an image
--max-image-width <max-image-width> Specify the maximum width in pixels allowed on an image
--migrate-file <migrate-file> Path to a file defining a store migration
-o, --opentelemetry-url <opentelemetry-url>
Enable OpenTelemetry Tracing exports to the given OpenTelemetry collector
-p, --path <path> The path to the data directory, e.g. data/
--sled-cache-capacity <sled-cache-capacity> Specify the number of bytes sled is allowed to use for it's cache
-p, --path <path> The path to the data directory, e.g. data/
--sled-cache-capacity <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
```
```

View file

@ -82,6 +82,13 @@ pub(crate) struct Overrides {
#[serde(skip_serializing_if = "Option::is_none")]
sled_cache_capacity: Option<u64>,
#[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<usize>,
#[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<String>,
opentelemetry_url: Option<Url>,
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<Format> {
self.image_format
}

View file

@ -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();

View file

@ -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()?;