mirror of
https://git.asonix.dog/asonix/pict-rs
synced 2024-12-22 11:21:24 +00:00
Further clean tracing logs
This commit is contained in:
parent
5a0b598ff7
commit
24f09408fb
6 changed files with 48 additions and 23 deletions
23
Cargo.lock
generated
23
Cargo.lock
generated
|
@ -40,7 +40,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "actix-form-data"
|
||||
version = "0.5.0-alpha.0"
|
||||
source = "git+https://git.asonix.dog/Aardwolf/actix-form-data#2a69e0a4a3767ba177688adb247560c2e9f9c06c"
|
||||
source = "git+https://git.asonix.dog/Aardwolf/actix-form-data#eefb669e0d16f89114da9acdf4ff9c5d8cc76b00"
|
||||
dependencies = [
|
||||
"actix-http",
|
||||
"actix-multipart",
|
||||
|
@ -48,10 +48,11 @@ dependencies = [
|
|||
"actix-web",
|
||||
"bytes",
|
||||
"futures",
|
||||
"log",
|
||||
"mime",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"tracing-futures",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1386,6 +1387,7 @@ dependencies = [
|
|||
"tracing",
|
||||
"tracing-futures",
|
||||
"tracing-subscriber",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1697,18 +1699,18 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
|||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.111"
|
||||
version = "1.0.112"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9124df5b40cbd380080b2cc6ab894c040a3070d995f5c9dc77e18c34a8ae37d"
|
||||
checksum = "736aac72d1eafe8e5962d1d1c3d99b0df526015ba40915cb3c49d042e92ec243"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.111"
|
||||
version = "1.0.112"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f2c3ac8e6ca1e9c80b8be1023940162bf81ae3cffbb1809474152f2ce1eb250"
|
||||
checksum = "bf0343ce212ac0d3d6afd9391ac8e9c9efe06b533c8d33f660f6390cc4093f57"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -2314,6 +2316,15 @@ dependencies = [
|
|||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9fde2f6a4bea1d6e007c4ad38c6839fa71cbb63b6dbf5b595aa38dc9b1093c11"
|
||||
dependencies = [
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "vec_map"
|
||||
version = "0.8.2"
|
||||
|
|
|
@ -33,3 +33,4 @@ thiserror = "1.0"
|
|||
tracing = "0.1.15"
|
||||
tracing-futures = "0.2.4"
|
||||
tracing-subscriber = { version = "0.2.5", features = ["fmt", "tracing-log"] }
|
||||
uuid = { version = "0.8", features = ["v4"] }
|
||||
|
|
24
src/main.rs
24
src/main.rs
|
@ -87,7 +87,7 @@ fn from_ext(ext: std::ffi::OsString) -> mime::Mime {
|
|||
}
|
||||
|
||||
/// Handle responding to succesful uploads
|
||||
#[instrument(skip(manager))]
|
||||
#[instrument(skip(value, manager))]
|
||||
async fn upload(
|
||||
value: Value,
|
||||
manager: web::Data<UploadManager>,
|
||||
|
@ -163,7 +163,7 @@ async fn delete(
|
|||
}
|
||||
|
||||
/// Serve files
|
||||
#[instrument(skip(manager))]
|
||||
#[instrument(skip(manager, whitelist))]
|
||||
async fn serve(
|
||||
segments: web::Path<String>,
|
||||
manager: web::Data<UploadManager>,
|
||||
|
@ -300,15 +300,20 @@ async fn main() -> Result<(), anyhow::Error> {
|
|||
.transform_error(|e| UploadError::from(e).into())
|
||||
.field(
|
||||
"images",
|
||||
Field::array(Field::file(move |_, _, stream| {
|
||||
Field::array(Field::file(move |filename, _, stream| {
|
||||
let manager = manager2.clone();
|
||||
|
||||
async move {
|
||||
manager.upload(stream).await.map(|alias| {
|
||||
let span = tracing::info_span!("file-upload", ?filename);
|
||||
let entered = span.enter();
|
||||
|
||||
let res = manager.upload(stream).await.map(|alias| {
|
||||
let mut path = PathBuf::new();
|
||||
path.push(alias);
|
||||
Some(path)
|
||||
})
|
||||
});
|
||||
drop(entered);
|
||||
res
|
||||
}
|
||||
})),
|
||||
);
|
||||
|
@ -328,14 +333,19 @@ async fn main() -> Result<(), anyhow::Error> {
|
|||
let manager = manager2.clone();
|
||||
|
||||
async move {
|
||||
manager
|
||||
let span = tracing::info_span!("file-import", ?filename);
|
||||
let entered = span.enter();
|
||||
|
||||
let res = manager
|
||||
.import(filename, content_type, validate_imports, stream)
|
||||
.await
|
||||
.map(|alias| {
|
||||
let mut path = PathBuf::new();
|
||||
path.push(alias);
|
||||
Some(path)
|
||||
})
|
||||
});
|
||||
drop(entered);
|
||||
res
|
||||
}
|
||||
})),
|
||||
);
|
||||
|
|
|
@ -2,6 +2,7 @@ use actix_web::dev::{Service, Transform};
|
|||
use futures::future::{ok, Ready};
|
||||
use std::task::{Context, Poll};
|
||||
use tracing_futures::{Instrument, Instrumented};
|
||||
use uuid::Uuid;
|
||||
|
||||
pub(crate) struct Tracing;
|
||||
|
||||
|
@ -41,8 +42,10 @@ where
|
|||
}
|
||||
|
||||
fn call(&mut self, req: S::Request) -> Self::Future {
|
||||
let uuid = Uuid::new_v4();
|
||||
|
||||
self.inner
|
||||
.call(req)
|
||||
.instrument(tracing::info_span!("request"))
|
||||
.instrument(tracing::info_span!("request", ?uuid))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -132,7 +132,7 @@ impl UploadManager {
|
|||
}
|
||||
|
||||
/// Delete the alias, and the file & variants if no more aliases exist
|
||||
#[instrument(skip(self))]
|
||||
#[instrument(skip(self, alias, token))]
|
||||
pub(crate) async fn delete(&self, alias: String, token: String) -> Result<(), UploadError> {
|
||||
use sled::Transactional;
|
||||
let db = self.inner.db.clone();
|
||||
|
@ -439,7 +439,7 @@ impl UploadManager {
|
|||
}
|
||||
|
||||
// check for an already-uploaded image with this hash, returning the path to the target file
|
||||
#[instrument(skip(self))]
|
||||
#[instrument(skip(self, hash, content_type))]
|
||||
async fn check_duplicate(
|
||||
&self,
|
||||
hash: Hash,
|
||||
|
@ -479,7 +479,7 @@ impl UploadManager {
|
|||
}
|
||||
|
||||
// generate a short filename that isn't already in-use
|
||||
#[instrument(skip(self))]
|
||||
#[instrument(skip(self, content_type))]
|
||||
async fn next_file(&self, content_type: mime::Mime) -> Result<String, UploadError> {
|
||||
let image_dir = self.image_dir();
|
||||
use rand::distributions::{Alphanumeric, Distribution};
|
||||
|
@ -508,7 +508,7 @@ impl UploadManager {
|
|||
}
|
||||
}
|
||||
|
||||
#[instrument(skip(self))]
|
||||
#[instrument(skip(self, hash, alias))]
|
||||
async fn add_existing_alias(&self, hash: &Hash, alias: &str) -> Result<(), UploadError> {
|
||||
self.save_alias(hash, alias).await??;
|
||||
|
||||
|
@ -520,7 +520,7 @@ impl UploadManager {
|
|||
// Add an alias to an existing file
|
||||
//
|
||||
// This will help if multiple 'users' upload the same file, and one of them wants to delete it
|
||||
#[instrument(skip(self))]
|
||||
#[instrument(skip(self, hash, content_type))]
|
||||
async fn add_alias(
|
||||
&self,
|
||||
hash: &Hash,
|
||||
|
@ -536,7 +536,7 @@ impl UploadManager {
|
|||
// Add a pre-defined alias to an existin file
|
||||
//
|
||||
// DANGER: this can cause BAD BAD BAD conflicts if the same alias is used for multiple files
|
||||
#[instrument(skip(self))]
|
||||
#[instrument(skip(self, hash))]
|
||||
async fn store_alias(&self, hash: &Hash, alias: &str) -> Result<(), UploadError> {
|
||||
let alias = alias.to_string();
|
||||
loop {
|
||||
|
@ -569,7 +569,7 @@ impl UploadManager {
|
|||
}
|
||||
|
||||
// Generate an alias to the file
|
||||
#[instrument(skip(self))]
|
||||
#[instrument(skip(self, hash, content_type))]
|
||||
async fn next_alias(
|
||||
&self,
|
||||
hash: &Hash,
|
||||
|
@ -595,7 +595,7 @@ impl UploadManager {
|
|||
}
|
||||
|
||||
// Save an alias to the database
|
||||
#[instrument(skip(self))]
|
||||
#[instrument(skip(self, hash))]
|
||||
async fn save_alias(
|
||||
&self,
|
||||
hash: &Hash,
|
||||
|
|
|
@ -15,7 +15,7 @@ pub(crate) enum GifError {
|
|||
}
|
||||
|
||||
// import & export image using the image crate
|
||||
#[instrument(skip(bytes))]
|
||||
#[instrument(skip(bytes, prescribed_format))]
|
||||
pub(crate) async fn validate_image(
|
||||
bytes: Bytes,
|
||||
prescribed_format: Option<Format>,
|
||||
|
|
Loading…
Reference in a new issue