feat(tvix/tracing): gRPC trace context propagation
This introduces optional helper function in tvix/tracing for trace propagation and uses these helper in the `tvix-store`. The GRPCBlobService, GRPCDirectoryService and GRPCPathInfoService now accept a generic client, meaning the client can be generated with either `::new` or `::with_interceptor`. This was tested and validated by starting a `tvix-store daemon` and `tvix-store import`. Change-Id: I4b194483bf09266820104b4b56e4a135dca2b77a Reviewed-on: https://cl.tvl.fyi/c/depot/+/11863 Reviewed-by: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
This commit is contained in:
parent
2b20d8d82d
commit
639a00e2ab
18 changed files with 399 additions and 48 deletions
|
|
@ -105,9 +105,12 @@ pub async fn from_addr(
|
|||
// - In the case of unix sockets, there must be a path, but may not be a host.
|
||||
// - In the case of non-unix sockets, there must be a host, but no path.
|
||||
// Constructing the channel is handled by tvix_castore::channel::from_url.
|
||||
let client =
|
||||
PathInfoServiceClient::new(tvix_castore::tonic::channel_from_url(&url).await?);
|
||||
Box::new(GRPCPathInfoService::from_client(client))
|
||||
Box::new(GRPCPathInfoService::from_client(
|
||||
PathInfoServiceClient::with_interceptor(
|
||||
tvix_castore::tonic::channel_from_url(&url).await?,
|
||||
tvix_tracing::propagate::tonic::send_trace,
|
||||
),
|
||||
))
|
||||
}
|
||||
#[cfg(feature = "cloud")]
|
||||
"bigtable" => {
|
||||
|
|
|
|||
|
|
@ -6,31 +6,43 @@ use crate::{
|
|||
use async_stream::try_stream;
|
||||
use futures::stream::BoxStream;
|
||||
use nix_compat::nixbase32;
|
||||
use tonic::{async_trait, transport::Channel, Code};
|
||||
use tonic::{async_trait, Code};
|
||||
use tracing::{instrument, Span};
|
||||
use tracing_indicatif::span_ext::IndicatifSpanExt;
|
||||
use tvix_castore::{proto as castorepb, Error};
|
||||
|
||||
/// Connects to a (remote) tvix-store PathInfoService over gRPC.
|
||||
#[derive(Clone)]
|
||||
pub struct GRPCPathInfoService {
|
||||
pub struct GRPCPathInfoService<T>
|
||||
where
|
||||
T: Clone,
|
||||
{
|
||||
/// The internal reference to a gRPC client.
|
||||
/// Cloning it is cheap, and it internally handles concurrent requests.
|
||||
grpc_client: proto::path_info_service_client::PathInfoServiceClient<Channel>,
|
||||
grpc_client: proto::path_info_service_client::PathInfoServiceClient<T>,
|
||||
}
|
||||
|
||||
impl GRPCPathInfoService {
|
||||
impl<T> GRPCPathInfoService<T>
|
||||
where
|
||||
T: tonic::client::GrpcService<tonic::body::BoxBody> + Clone,
|
||||
{
|
||||
/// construct a [GRPCPathInfoService] from a [proto::path_info_service_client::PathInfoServiceClient].
|
||||
/// panics if called outside the context of a tokio runtime.
|
||||
pub fn from_client(
|
||||
grpc_client: proto::path_info_service_client::PathInfoServiceClient<Channel>,
|
||||
grpc_client: proto::path_info_service_client::PathInfoServiceClient<T>,
|
||||
) -> Self {
|
||||
Self { grpc_client }
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl PathInfoService for GRPCPathInfoService {
|
||||
impl<T> PathInfoService for GRPCPathInfoService<T>
|
||||
where
|
||||
T: tonic::client::GrpcService<tonic::body::BoxBody> + Send + Sync + Clone + 'static,
|
||||
T::ResponseBody: tonic::codegen::Body<Data = tonic::codegen::Bytes> + Send + 'static,
|
||||
<T::ResponseBody as tonic::codegen::Body>::Error: Into<tonic::codegen::StdError> + Send,
|
||||
T::Future: Send,
|
||||
{
|
||||
#[instrument(level = "trace", skip_all, fields(path_info.digest = nixbase32::encode(&digest)))]
|
||||
async fn get(&self, digest: [u8; 20]) -> Result<Option<PathInfo>, Error> {
|
||||
let path_info = self
|
||||
|
|
@ -107,7 +119,13 @@ impl PathInfoService for GRPCPathInfoService {
|
|||
}
|
||||
|
||||
#[async_trait]
|
||||
impl NarCalculationService for GRPCPathInfoService {
|
||||
impl<T> NarCalculationService for GRPCPathInfoService<T>
|
||||
where
|
||||
T: tonic::client::GrpcService<tonic::body::BoxBody> + Send + Sync + Clone + 'static,
|
||||
T::ResponseBody: tonic::codegen::Body<Data = tonic::codegen::Bytes> + Send + 'static,
|
||||
<T::ResponseBody as tonic::codegen::Body>::Error: Into<tonic::codegen::StdError> + Send,
|
||||
T::Future: Send,
|
||||
{
|
||||
#[instrument(level = "trace", skip_all, fields(root_node = ?root_node, indicatif.pb_show=1))]
|
||||
async fn calculate_nar(
|
||||
&self,
|
||||
|
|
|
|||
|
|
@ -16,8 +16,11 @@ use crate::{
|
|||
/// Constructs and returns a gRPC PathInfoService.
|
||||
/// We also return memory-based {Blob,Directory}Service,
|
||||
/// as the consumer of this function accepts a 3-tuple.
|
||||
pub async fn make_grpc_path_info_service_client(
|
||||
) -> (impl BlobService, impl DirectoryService, GRPCPathInfoService) {
|
||||
pub async fn make_grpc_path_info_service_client() -> (
|
||||
impl BlobService,
|
||||
impl DirectoryService,
|
||||
GRPCPathInfoService<tonic::transport::Channel>,
|
||||
) {
|
||||
let (left, right) = tokio::io::duplex(64);
|
||||
|
||||
let blob_service = blob_service();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue