mirror of
https://git.asonix.dog/asonix/pict-rs
synced 2024-12-22 19:31:35 +00:00
Add metrics to object storage requests
This commit is contained in:
parent
7df6f3906e
commit
49d3037358
1 changed files with 22 additions and 4 deletions
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
bytes_stream::BytesStream, error_code::ErrorCode, repo::ArcRepo, store::Store,
|
bytes_stream::BytesStream, error_code::ErrorCode, future::WithMetrics, repo::ArcRepo,
|
||||||
stream::LocalBoxStream,
|
store::Store, stream::LocalBoxStream,
|
||||||
};
|
};
|
||||||
use actix_rt::task::JoinError;
|
use actix_rt::task::JoinError;
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
|
@ -189,6 +189,7 @@ impl Store for ObjectStore {
|
||||||
.head_bucket_request()
|
.head_bucket_request()
|
||||||
.await?
|
.await?
|
||||||
.send()
|
.send()
|
||||||
|
.with_metrics("pict-rs.object-storage.head-bucket-request")
|
||||||
.await
|
.await
|
||||||
.map_err(ObjectError::from)?;
|
.map_err(ObjectError::from)?;
|
||||||
|
|
||||||
|
@ -230,6 +231,7 @@ impl Store for ObjectStore {
|
||||||
let response = req
|
let response = req
|
||||||
.body(Body::wrap_stream(first_chunk))
|
.body(Body::wrap_stream(first_chunk))
|
||||||
.send()
|
.send()
|
||||||
|
.with_metrics("pict-rs.object-store.put-object-request")
|
||||||
.await
|
.await
|
||||||
.map_err(ObjectError::from)?;
|
.map_err(ObjectError::from)?;
|
||||||
|
|
||||||
|
@ -243,7 +245,11 @@ impl Store for ObjectStore {
|
||||||
let mut first_chunk = Some(first_chunk);
|
let mut first_chunk = Some(first_chunk);
|
||||||
|
|
||||||
let (req, object_id) = self.create_multipart_request(content_type).await?;
|
let (req, object_id) = self.create_multipart_request(content_type).await?;
|
||||||
let response = req.send().await.map_err(ObjectError::from)?;
|
let response = req
|
||||||
|
.send()
|
||||||
|
.with_metrics("pict-rs.object-store.create-multipart-request")
|
||||||
|
.await
|
||||||
|
.map_err(ObjectError::from)?;
|
||||||
|
|
||||||
if !response.status().is_success() {
|
if !response.status().is_success() {
|
||||||
return Err(status_error(response).await);
|
return Err(status_error(response).await);
|
||||||
|
@ -287,6 +293,7 @@ impl Store for ObjectStore {
|
||||||
.await?
|
.await?
|
||||||
.body(Body::wrap_stream(buf))
|
.body(Body::wrap_stream(buf))
|
||||||
.send()
|
.send()
|
||||||
|
.with_metrics("pict-rs.object-storage.create-upload-part-request")
|
||||||
.await
|
.await
|
||||||
.map_err(ObjectError::from)?;
|
.map_err(ObjectError::from)?;
|
||||||
|
|
||||||
|
@ -342,6 +349,7 @@ impl Store for ObjectStore {
|
||||||
if let Err(e) = res {
|
if let Err(e) = res {
|
||||||
self.create_abort_multipart_request(&object_id, upload_id)
|
self.create_abort_multipart_request(&object_id, upload_id)
|
||||||
.send()
|
.send()
|
||||||
|
.with_metrics("pict-rs.object-storage.abort-multipart-request")
|
||||||
.await
|
.await
|
||||||
.map_err(ObjectError::from)?;
|
.map_err(ObjectError::from)?;
|
||||||
return Err(e);
|
return Err(e);
|
||||||
|
@ -358,7 +366,12 @@ impl Store for ObjectStore {
|
||||||
) -> Result<Arc<str>, StoreError> {
|
) -> Result<Arc<str>, StoreError> {
|
||||||
let (req, object_id) = self.put_object_request(bytes.len(), content_type).await?;
|
let (req, object_id) = self.put_object_request(bytes.len(), content_type).await?;
|
||||||
|
|
||||||
let response = req.body(bytes).send().await.map_err(ObjectError::from)?;
|
let response = req
|
||||||
|
.body(bytes)
|
||||||
|
.send()
|
||||||
|
.with_metrics("pict-rs.object-storage.put-object-request")
|
||||||
|
.await
|
||||||
|
.map_err(ObjectError::from)?;
|
||||||
|
|
||||||
if !response.status().is_success() {
|
if !response.status().is_success() {
|
||||||
return Err(status_error(response).await);
|
return Err(status_error(response).await);
|
||||||
|
@ -384,6 +397,7 @@ impl Store for ObjectStore {
|
||||||
let response = self
|
let response = self
|
||||||
.get_object_request(identifier, from_start, len)
|
.get_object_request(identifier, from_start, len)
|
||||||
.send()
|
.send()
|
||||||
|
.with_metrics("pict-rs.object-storage.get-object-request")
|
||||||
.await
|
.await
|
||||||
.map_err(ObjectError::from)?;
|
.map_err(ObjectError::from)?;
|
||||||
|
|
||||||
|
@ -409,6 +423,7 @@ impl Store for ObjectStore {
|
||||||
let response = self
|
let response = self
|
||||||
.get_object_request(identifier, None, None)
|
.get_object_request(identifier, None, None)
|
||||||
.send()
|
.send()
|
||||||
|
.with_metrics("pict-rs.object-storage.get-object-request")
|
||||||
.await
|
.await
|
||||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, ObjectError::from(e)))?;
|
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, ObjectError::from(e)))?;
|
||||||
|
|
||||||
|
@ -435,6 +450,7 @@ impl Store for ObjectStore {
|
||||||
let response = self
|
let response = self
|
||||||
.head_object_request(identifier)
|
.head_object_request(identifier)
|
||||||
.send()
|
.send()
|
||||||
|
.with_metrics("pict-rs.object-storage.head-object-request")
|
||||||
.await
|
.await
|
||||||
.map_err(ObjectError::from)?;
|
.map_err(ObjectError::from)?;
|
||||||
|
|
||||||
|
@ -459,6 +475,7 @@ impl Store for ObjectStore {
|
||||||
let response = self
|
let response = self
|
||||||
.delete_object_request(identifier)
|
.delete_object_request(identifier)
|
||||||
.send()
|
.send()
|
||||||
|
.with_metrics("pict-rs.object-storage.delete-object-request")
|
||||||
.await
|
.await
|
||||||
.map_err(ObjectError::from)?;
|
.map_err(ObjectError::from)?;
|
||||||
|
|
||||||
|
@ -614,6 +631,7 @@ impl ObjectStore {
|
||||||
req.header(CONTENT_LENGTH, body.len())
|
req.header(CONTENT_LENGTH, body.len())
|
||||||
.body(body)
|
.body(body)
|
||||||
.send()
|
.send()
|
||||||
|
.with_metrics("pict-rs.object-storage.complete-multipart-request")
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue