Skip to content

Commit

Permalink
feat: upgrade to tonic 0.9 (#1016)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Apr 18, 2023
1 parent ee3efe0 commit 482d951
Show file tree
Hide file tree
Showing 10 changed files with 294 additions and 49 deletions.
2 changes: 1 addition & 1 deletion examples/external-otlp-tonic-tokio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ opentelemetry = {path = "../../opentelemetry", features = ["rt-tokio", "metrics"
opentelemetry-otlp = {path = "../../opentelemetry-otlp", features = ["tonic", "tls", "tls-roots"]}
serde_json = "1.0"
tokio = {version = "1.0", features = ["full"]}
tonic = {version = "0.8.0", features = ["tls"]}
tonic = {version = "0.9.0", features = ["tls"]}
url = "2.2.0"
2 changes: 1 addition & 1 deletion opentelemetry-jaeger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ tokio = { version = "1.0", features = ["net", "sync"], optional = true }
wasm-bindgen = { version = "0.2", optional = true }
wasm-bindgen-futures = { version = "0.4.18", optional = true }

tonic = { version = "0.8.3", optional = true }
tonic = { version = "0.9.0", optional = true }
prost = { version = "0.11.6", optional = true }
prost-types = { version = "0.11.6", optional = true }

Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-otlp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ opentelemetry-http = { version = "0.8", path = "../opentelemetry-http", optional
protobuf = { version = "2.18", optional = true }

prost = { version = "0.11.0", optional = true }
tonic = { version = "0.8.0", optional = true }
tonic = { version = "0.9.0", optional = true }
tokio = { version = "1.0", features = ["sync", "rt"], optional = true }

reqwest = { version = "0.11", optional = true, default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ with-serde = ["protobuf/with-serde", "serde", "serde_json"]

[dependencies]
grpcio = { version = "0.12", optional = true }
tonic = { version = "0.8.0", optional = true }
tonic = { version = "0.9.0", optional = true }
prost = { version = "0.11.0", optional = true }
protobuf = { version = "2.18", optional = true } # todo: update to 3.0 so we have docs for generated types.
opentelemetry = { version = "0.19", default-features = false, features = ["trace", "metrics"], path = "../opentelemetry" }
Expand All @@ -56,6 +56,6 @@ serde_json = { version = "1.0", optional = true }
[dev-dependencies]
protobuf-codegen = { version = "2.16" }
protoc-grpcio = { version = "3.0" }
tonic-build = { version = "0.8.0" }
tonic-build = { version = "0.9.0" }
prost-build = { version = "0.11.1" }
tempfile = "3.3.0"
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub mod logs_service_client {
/// Attempt to create a new client by connecting to a given endpoint.
pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
where
D: std::convert::TryInto<tonic::transport::Endpoint>,
D: TryInto<tonic::transport::Endpoint>,
D::Error: Into<StdError>,
{
let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
Expand Down Expand Up @@ -123,12 +123,31 @@ pub mod logs_service_client {
self.inner = self.inner.accept_compressed(encoding);
self
}
/// Limits the maximum size of a decoded message.
///
/// Default: `4MB`
#[must_use]
pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
self.inner = self.inner.max_decoding_message_size(limit);
self
}
/// Limits the maximum size of an encoded message.
///
/// Default: `usize::MAX`
#[must_use]
pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
self.inner = self.inner.max_encoding_message_size(limit);
self
}
/// For performance reasons, it is recommended to keep this RPC
/// alive for the entire life of the application.
pub async fn export(
&mut self,
request: impl tonic::IntoRequest<super::ExportLogsServiceRequest>,
) -> Result<tonic::Response<super::ExportLogsServiceResponse>, tonic::Status> {
) -> std::result::Result<
tonic::Response<super::ExportLogsServiceResponse>,
tonic::Status,
> {
self.inner
.ready()
.await
Expand All @@ -142,7 +161,15 @@ pub mod logs_service_client {
let path = http::uri::PathAndQuery::from_static(
"/opentelemetry.proto.collector.logs.v1.LogsService/Export",
);
self.inner.unary(request.into_request(), path, codec).await
let mut req = request.into_request();
req.extensions_mut()
.insert(
GrpcMethod::new(
"opentelemetry.proto.collector.logs.v1.LogsService",
"Export",
),
);
self.inner.unary(req, path, codec).await
}
}
}
Expand All @@ -158,7 +185,10 @@ pub mod logs_service_server {
async fn export(
&self,
request: tonic::Request<super::ExportLogsServiceRequest>,
) -> Result<tonic::Response<super::ExportLogsServiceResponse>, tonic::Status>;
) -> std::result::Result<
tonic::Response<super::ExportLogsServiceResponse>,
tonic::Status,
>;
}
/// Service that can be used to push logs between one Application instrumented with
/// OpenTelemetry and an collector, or between an collector and a central collector (in this
Expand All @@ -168,6 +198,8 @@ pub mod logs_service_server {
inner: _Inner<T>,
accept_compression_encodings: EnabledCompressionEncodings,
send_compression_encodings: EnabledCompressionEncodings,
max_decoding_message_size: Option<usize>,
max_encoding_message_size: Option<usize>,
}
struct _Inner<T>(Arc<T>);
impl<T: LogsService> LogsServiceServer<T> {
Expand All @@ -180,6 +212,8 @@ pub mod logs_service_server {
inner,
accept_compression_encodings: Default::default(),
send_compression_encodings: Default::default(),
max_decoding_message_size: None,
max_encoding_message_size: None,
}
}
pub fn with_interceptor<F>(
Expand All @@ -203,6 +237,22 @@ pub mod logs_service_server {
self.send_compression_encodings.enable(encoding);
self
}
/// Limits the maximum size of a decoded message.
///
/// Default: `4MB`
#[must_use]
pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
self.max_decoding_message_size = Some(limit);
self
}
/// Limits the maximum size of an encoded message.
///
/// Default: `usize::MAX`
#[must_use]
pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
self.max_encoding_message_size = Some(limit);
self
}
}
impl<T, B> tonic::codegen::Service<http::Request<B>> for LogsServiceServer<T>
where
Expand All @@ -216,7 +266,7 @@ pub mod logs_service_server {
fn poll_ready(
&mut self,
_cx: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>> {
) -> Poll<std::result::Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}
fn call(&mut self, req: http::Request<B>) -> Self::Future {
Expand All @@ -238,13 +288,15 @@ pub mod logs_service_server {
&mut self,
request: tonic::Request<super::ExportLogsServiceRequest>,
) -> Self::Future {
let inner = self.0.clone();
let inner = Arc::clone(&self.0);
let fut = async move { (*inner).export(request).await };
Box::pin(fut)
}
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let max_decoding_message_size = self.max_decoding_message_size;
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let inner = inner.0;
Expand All @@ -254,6 +306,10 @@ pub mod logs_service_server {
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
)
.apply_max_message_size_config(
max_decoding_message_size,
max_encoding_message_size,
);
let res = grpc.unary(method, req).await;
Ok(res)
Expand Down Expand Up @@ -282,12 +338,14 @@ pub mod logs_service_server {
inner,
accept_compression_encodings: self.accept_compression_encodings,
send_compression_encodings: self.send_compression_encodings,
max_decoding_message_size: self.max_decoding_message_size,
max_encoding_message_size: self.max_encoding_message_size,
}
}
}
impl<T: LogsService> Clone for _Inner<T> {
fn clone(&self) -> Self {
Self(self.0.clone())
Self(Arc::clone(&self.0))
}
}
impl<T: std::fmt::Debug> std::fmt::Debug for _Inner<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub mod metrics_service_client {
/// Attempt to create a new client by connecting to a given endpoint.
pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
where
D: std::convert::TryInto<tonic::transport::Endpoint>,
D: TryInto<tonic::transport::Endpoint>,
D::Error: Into<StdError>,
{
let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
Expand Down Expand Up @@ -123,12 +123,28 @@ pub mod metrics_service_client {
self.inner = self.inner.accept_compressed(encoding);
self
}
/// Limits the maximum size of a decoded message.
///
/// Default: `4MB`
#[must_use]
pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
self.inner = self.inner.max_decoding_message_size(limit);
self
}
/// Limits the maximum size of an encoded message.
///
/// Default: `usize::MAX`
#[must_use]
pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
self.inner = self.inner.max_encoding_message_size(limit);
self
}
/// For performance reasons, it is recommended to keep this RPC
/// alive for the entire life of the application.
pub async fn export(
&mut self,
request: impl tonic::IntoRequest<super::ExportMetricsServiceRequest>,
) -> Result<
) -> std::result::Result<
tonic::Response<super::ExportMetricsServiceResponse>,
tonic::Status,
> {
Expand All @@ -145,7 +161,15 @@ pub mod metrics_service_client {
let path = http::uri::PathAndQuery::from_static(
"/opentelemetry.proto.collector.metrics.v1.MetricsService/Export",
);
self.inner.unary(request.into_request(), path, codec).await
let mut req = request.into_request();
req.extensions_mut()
.insert(
GrpcMethod::new(
"opentelemetry.proto.collector.metrics.v1.MetricsService",
"Export",
),
);
self.inner.unary(req, path, codec).await
}
}
}
Expand All @@ -161,7 +185,10 @@ pub mod metrics_service_server {
async fn export(
&self,
request: tonic::Request<super::ExportMetricsServiceRequest>,
) -> Result<tonic::Response<super::ExportMetricsServiceResponse>, tonic::Status>;
) -> std::result::Result<
tonic::Response<super::ExportMetricsServiceResponse>,
tonic::Status,
>;
}
/// Service that can be used to push metrics between one Application
/// instrumented with OpenTelemetry and a collector, or between a collector and a
Expand All @@ -171,6 +198,8 @@ pub mod metrics_service_server {
inner: _Inner<T>,
accept_compression_encodings: EnabledCompressionEncodings,
send_compression_encodings: EnabledCompressionEncodings,
max_decoding_message_size: Option<usize>,
max_encoding_message_size: Option<usize>,
}
struct _Inner<T>(Arc<T>);
impl<T: MetricsService> MetricsServiceServer<T> {
Expand All @@ -183,6 +212,8 @@ pub mod metrics_service_server {
inner,
accept_compression_encodings: Default::default(),
send_compression_encodings: Default::default(),
max_decoding_message_size: None,
max_encoding_message_size: None,
}
}
pub fn with_interceptor<F>(
Expand All @@ -206,6 +237,22 @@ pub mod metrics_service_server {
self.send_compression_encodings.enable(encoding);
self
}
/// Limits the maximum size of a decoded message.
///
/// Default: `4MB`
#[must_use]
pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
self.max_decoding_message_size = Some(limit);
self
}
/// Limits the maximum size of an encoded message.
///
/// Default: `usize::MAX`
#[must_use]
pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
self.max_encoding_message_size = Some(limit);
self
}
}
impl<T, B> tonic::codegen::Service<http::Request<B>> for MetricsServiceServer<T>
where
Expand All @@ -219,7 +266,7 @@ pub mod metrics_service_server {
fn poll_ready(
&mut self,
_cx: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>> {
) -> Poll<std::result::Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}
fn call(&mut self, req: http::Request<B>) -> Self::Future {
Expand All @@ -241,13 +288,15 @@ pub mod metrics_service_server {
&mut self,
request: tonic::Request<super::ExportMetricsServiceRequest>,
) -> Self::Future {
let inner = self.0.clone();
let inner = Arc::clone(&self.0);
let fut = async move { (*inner).export(request).await };
Box::pin(fut)
}
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let max_decoding_message_size = self.max_decoding_message_size;
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let inner = inner.0;
Expand All @@ -257,6 +306,10 @@ pub mod metrics_service_server {
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
)
.apply_max_message_size_config(
max_decoding_message_size,
max_encoding_message_size,
);
let res = grpc.unary(method, req).await;
Ok(res)
Expand Down Expand Up @@ -285,12 +338,14 @@ pub mod metrics_service_server {
inner,
accept_compression_encodings: self.accept_compression_encodings,
send_compression_encodings: self.send_compression_encodings,
max_decoding_message_size: self.max_decoding_message_size,
max_encoding_message_size: self.max_encoding_message_size,
}
}
}
impl<T: MetricsService> Clone for _Inner<T> {
fn clone(&self) -> Self {
Self(self.0.clone())
Self(Arc::clone(&self.0))
}
}
impl<T: std::fmt::Debug> std::fmt::Debug for _Inner<T> {
Expand Down
Loading

0 comments on commit 482d951

Please sign in to comment.