Added autounmount on stop. Added prom metrics to server 9090 /metrics
This commit is contained in:
@@ -3,6 +3,7 @@ use tokio_stream::Stream;
|
||||
use tonic::{Request, Response, Status};
|
||||
|
||||
use crate::vfs::VirtualFileSystem;
|
||||
use crate::metrics::{self, RequestTimer};
|
||||
use furumi_common::proto::{
|
||||
remote_file_system_server::RemoteFileSystem, AttrResponse, DirEntry, FileChunk,
|
||||
PathRequest, ReadRequest,
|
||||
@@ -25,12 +26,20 @@ impl<V: VirtualFileSystem> RemoteFileSystem for RemoteFileSystemImpl<V> {
|
||||
&self,
|
||||
request: Request<PathRequest>,
|
||||
) -> Result<Response<AttrResponse>, Status> {
|
||||
let timer = RequestTimer::new("GetAttr");
|
||||
let req = request.into_inner();
|
||||
let safe_path = sanitize_path(&req.path)?;
|
||||
|
||||
match self.vfs.get_attr(&safe_path).await {
|
||||
Ok(attr) => Ok(Response::new(attr)),
|
||||
Err(e) => Err(Status::internal(e.to_string())),
|
||||
Ok(attr) => {
|
||||
timer.finish_ok();
|
||||
Ok(Response::new(attr))
|
||||
}
|
||||
Err(e) => {
|
||||
metrics::FILE_OPEN_ERRORS_TOTAL.inc();
|
||||
timer.finish_err();
|
||||
Err(Status::internal(e.to_string()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,11 +53,14 @@ impl<V: VirtualFileSystem> RemoteFileSystem for RemoteFileSystemImpl<V> {
|
||||
&self,
|
||||
request: Request<PathRequest>,
|
||||
) -> Result<Response<Self::ReadDirStream>, Status> {
|
||||
let timer = RequestTimer::new("ReadDir");
|
||||
let req = request.into_inner();
|
||||
let safe_path = sanitize_path(&req.path)?;
|
||||
|
||||
match self.vfs.read_dir(&safe_path).await {
|
||||
Ok(mut rx) => {
|
||||
timer.finish_ok();
|
||||
metrics::ACTIVE_STREAMS.inc();
|
||||
let stream = async_stream::try_stream! {
|
||||
while let Some(result) = rx.recv().await {
|
||||
match result {
|
||||
@@ -56,10 +68,14 @@ impl<V: VirtualFileSystem> RemoteFileSystem for RemoteFileSystemImpl<V> {
|
||||
Err(e) => Err(Status::internal(e.to_string()))?,
|
||||
}
|
||||
}
|
||||
metrics::ACTIVE_STREAMS.dec();
|
||||
};
|
||||
Ok(Response::new(Box::pin(stream) as Self::ReadDirStream))
|
||||
}
|
||||
Err(e) => Err(Status::internal(e.to_string())),
|
||||
Err(e) => {
|
||||
timer.finish_err();
|
||||
Err(Status::internal(e.to_string()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,6 +89,7 @@ impl<V: VirtualFileSystem> RemoteFileSystem for RemoteFileSystemImpl<V> {
|
||||
&self,
|
||||
request: Request<ReadRequest>,
|
||||
) -> Result<Response<Self::ReadFileStream>, Status> {
|
||||
let timer = RequestTimer::new("ReadFile");
|
||||
let req = request.into_inner();
|
||||
let safe_path = sanitize_path(&req.path)?;
|
||||
|
||||
@@ -85,17 +102,31 @@ impl<V: VirtualFileSystem> RemoteFileSystem for RemoteFileSystemImpl<V> {
|
||||
|
||||
match self.vfs.read_file(sanitized_req).await {
|
||||
Ok(mut rx) => {
|
||||
timer.finish_ok();
|
||||
metrics::ACTIVE_STREAMS.inc();
|
||||
let stream = async_stream::try_stream! {
|
||||
while let Some(result) = rx.recv().await {
|
||||
match result {
|
||||
Ok(chunk) => yield chunk,
|
||||
Err(e) => Err(Status::internal(e.to_string()))?,
|
||||
Ok(chunk) => {
|
||||
metrics::BYTES_READ_TOTAL.inc_by(chunk.data.len() as f64);
|
||||
yield chunk;
|
||||
}
|
||||
Err(e) => {
|
||||
metrics::FILE_OPEN_ERRORS_TOTAL.inc();
|
||||
Err(Status::internal(e.to_string()))?;
|
||||
}
|
||||
}
|
||||
}
|
||||
metrics::ACTIVE_STREAMS.dec();
|
||||
};
|
||||
Ok(Response::new(Box::pin(stream) as Self::ReadFileStream))
|
||||
}
|
||||
Err(e) => Err(Status::internal(e.to_string())),
|
||||
Err(e) => {
|
||||
metrics::FILE_OPEN_ERRORS_TOTAL.inc();
|
||||
timer.finish_err();
|
||||
Err(Status::internal(e.to_string()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user