feat(tvix/store): add logging with tracing
This uses [tracing](https://github.com/tokio-rs/tracing) for logs/ tracing. Annotate all method handlers with an instrument macro, and warn! a message for them being unimplemented. Co-Authored-By: Márton Boros <martonboros@gmail.com> Change-Id: Id42a41db33782d82abfb8dc0e49a8915000e5d89 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7665 Reviewed-by: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
This commit is contained in:
parent
0bf2b0ef11
commit
319c03f634
7 changed files with 327 additions and 10 deletions
|
@ -7,6 +7,9 @@ use crate::proto::PutBlobResponse;
|
|||
use crate::proto::ReadBlobRequest;
|
||||
use crate::proto::StatBlobRequest;
|
||||
use tonic::{Request, Response, Result, Status, Streaming};
|
||||
use tracing::{instrument, warn};
|
||||
|
||||
const NOT_IMPLEMENTED_MSG: &str = "not implemented";
|
||||
|
||||
pub struct DummyBlobService {}
|
||||
|
||||
|
@ -14,21 +17,27 @@ pub struct DummyBlobService {}
|
|||
impl BlobService for DummyBlobService {
|
||||
type ReadStream = ReceiverStream<Result<BlobChunk>>;
|
||||
|
||||
#[instrument(skip(self))]
|
||||
async fn stat(&self, _request: Request<StatBlobRequest>) -> Result<Response<BlobMeta>> {
|
||||
Err(Status::unimplemented("not implemented"))
|
||||
warn!(NOT_IMPLEMENTED_MSG);
|
||||
Err(Status::unimplemented(NOT_IMPLEMENTED_MSG))
|
||||
}
|
||||
|
||||
#[instrument(skip(self))]
|
||||
async fn read(
|
||||
&self,
|
||||
_request: Request<ReadBlobRequest>,
|
||||
) -> Result<Response<Self::ReadStream>, Status> {
|
||||
Err(Status::unimplemented("not implemented"))
|
||||
warn!(NOT_IMPLEMENTED_MSG);
|
||||
Err(Status::unimplemented(NOT_IMPLEMENTED_MSG))
|
||||
}
|
||||
|
||||
#[instrument(skip(self, _request))]
|
||||
async fn put(
|
||||
&self,
|
||||
_request: Request<Streaming<BlobChunk>>,
|
||||
) -> Result<Response<PutBlobResponse>> {
|
||||
Err(Status::unimplemented("not implemented"))
|
||||
warn!(NOT_IMPLEMENTED_MSG);
|
||||
Err(Status::unimplemented(NOT_IMPLEMENTED_MSG))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,9 @@ use crate::proto::Directory;
|
|||
use crate::proto::GetDirectoryRequest;
|
||||
use crate::proto::PutDirectoryResponse;
|
||||
use tonic::{Request, Response, Result, Status, Streaming};
|
||||
use tracing::{instrument, warn};
|
||||
|
||||
const NOT_IMPLEMENTED_MSG: &str = "not implemented";
|
||||
|
||||
pub struct DummyDirectoryService {}
|
||||
|
||||
|
@ -12,17 +15,21 @@ pub struct DummyDirectoryService {}
|
|||
impl DirectoryService for DummyDirectoryService {
|
||||
type GetStream = ReceiverStream<Result<Directory>>;
|
||||
|
||||
#[instrument(skip(self))]
|
||||
async fn get(
|
||||
&self,
|
||||
_request: Request<GetDirectoryRequest>,
|
||||
) -> Result<Response<Self::GetStream>, Status> {
|
||||
Err(Status::unimplemented("not implemented"))
|
||||
warn!(NOT_IMPLEMENTED_MSG);
|
||||
Err(Status::unimplemented(NOT_IMPLEMENTED_MSG))
|
||||
}
|
||||
|
||||
#[instrument(skip(self, _request))]
|
||||
async fn put(
|
||||
&self,
|
||||
_request: Request<Streaming<Directory>>,
|
||||
) -> Result<Response<PutDirectoryResponse>> {
|
||||
Err(Status::unimplemented("not implemented"))
|
||||
warn!(NOT_IMPLEMENTED_MSG);
|
||||
Err(Status::unimplemented(NOT_IMPLEMENTED_MSG))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,23 +4,32 @@ use crate::proto::GetPathInfoRequest;
|
|||
use crate::proto::Node;
|
||||
use crate::proto::PathInfo;
|
||||
use tonic::{Request, Response, Result, Status};
|
||||
use tracing::{instrument, warn};
|
||||
|
||||
pub struct DummyPathInfoService {}
|
||||
|
||||
const NOT_IMPLEMENTED_MSG: &str = "not implemented";
|
||||
|
||||
#[tonic::async_trait]
|
||||
impl PathInfoService for DummyPathInfoService {
|
||||
#[instrument(skip(self))]
|
||||
async fn get(&self, _request: Request<GetPathInfoRequest>) -> Result<Response<PathInfo>> {
|
||||
Err(Status::unimplemented("not implemented"))
|
||||
warn!(NOT_IMPLEMENTED_MSG);
|
||||
Err(Status::unimplemented(NOT_IMPLEMENTED_MSG))
|
||||
}
|
||||
|
||||
#[instrument(skip(self))]
|
||||
async fn put(&self, _request: Request<PathInfo>) -> Result<Response<PathInfo>> {
|
||||
Err(Status::unimplemented("not implemented"))
|
||||
warn!(NOT_IMPLEMENTED_MSG);
|
||||
Err(Status::unimplemented(NOT_IMPLEMENTED_MSG))
|
||||
}
|
||||
|
||||
#[instrument(skip(self))]
|
||||
async fn calculate_nar(
|
||||
&self,
|
||||
_request: Request<Node>,
|
||||
) -> Result<Response<CalculateNarResponse>> {
|
||||
Err(Status::unimplemented("not implemented"))
|
||||
warn!(NOT_IMPLEMENTED_MSG);
|
||||
Err(Status::unimplemented(NOT_IMPLEMENTED_MSG))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ use crate::proto::FILE_DESCRIPTOR_SET;
|
|||
|
||||
use clap::Parser;
|
||||
use tonic::{transport::Server, Result};
|
||||
use tracing::{info, Level};
|
||||
|
||||
mod dummy_blob_service;
|
||||
mod dummy_directory_service;
|
||||
|
@ -23,6 +24,9 @@ mod tests;
|
|||
struct Cli {
|
||||
#[clap(long, short = 'l')]
|
||||
listen_address: Option<String>,
|
||||
|
||||
#[clap(long)]
|
||||
log_level: Option<Level>,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
|
@ -34,6 +38,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
.parse()
|
||||
.unwrap();
|
||||
|
||||
let level = cli.log_level.unwrap_or(Level::INFO);
|
||||
let subscriber = tracing_subscriber::fmt().with_max_level(level).finish();
|
||||
tracing::subscriber::set_global_default(subscriber).ok();
|
||||
|
||||
let mut server = Server::builder();
|
||||
|
||||
let blob_service = dummy_blob_service::DummyBlobService {};
|
||||
|
@ -53,7 +61,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
router = router.add_service(reflection_svc);
|
||||
}
|
||||
|
||||
println!("tvix-store listening on {}", listen_address);
|
||||
info!("tvix-store listening on {}", listen_address);
|
||||
|
||||
router.serve(listen_address).await?;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue