Skip to content

Commit 40e2f6f

Browse files
authored
chore: update Tonic and Prost dependencies (tokio-rs#364)
This branch updates the console crates' dependency on `tonic` to v0.8.0 and `prost` to 0.11.0. In addition, I've added a [`cargo xtask`][xtask] command for manually regenerating the generated protobuf bindings. This is necessary as the current approach, regenerating the bindings in an integration test, does not work when the protos fail to compile (which they do after the Tonic update). Since running the crate's tests requires compiling the crate, if the proto bindings don't compile, we can't re-run the test. [xtask]: https://github.com/matklad/cargo-xtask
1 parent e4eff4d commit 40e2f6f

17 files changed

+298
-84
lines changed

.cargo/config

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
[build]
2-
rustflags = ["--cfg", "tokio_unstable"]
2+
rustflags = ["--cfg", "tokio_unstable"]
3+
4+
[alias]
5+
xtask = "run --manifest-path ./xtask/Cargo.toml --"

.github/workflows/ci.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ jobs:
7575
override: true
7676
- uses: Swatinem/rust-cache@v1
7777

78+
- name: Install Protoc
79+
uses: arduino/setup-protoc@v1
80+
with:
81+
repo-token: ${{ secrets.GITHUB_TOKEN }}
82+
7883
- name: Run cargo test (API)
7984
uses: actions-rs/cargo@v1
8085
with:

Cargo.lock

+23-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
members = [
33
"tokio-console",
44
"console-subscriber",
5-
"console-api"
5+
"console-api",
6+
"xtask"
67
]
78
resolver = "2"

console-api/Cargo.toml

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "console-api"
3-
version = "0.3.0"
3+
version = "0.4.0"
44
license = "MIT"
55
edition = "2021"
66
rust-version = "1.58.0"
@@ -29,19 +29,21 @@ keywords = [
2929
transport = ["tonic-build/transport", "tonic/transport"]
3030

3131
[dependencies]
32-
tonic = { version = "0.7", default-features = false, features = [
32+
tonic = { version = "0.8", default-features = false, features = [
3333
"prost",
3434
"codegen",
3535
"transport",
3636
] }
37-
prost = "0.10"
38-
prost-types = "0.10"
37+
prost = "0.11"
38+
prost-types = "0.11"
3939
tracing-core = "0.1.17"
4040

4141
[dev-dependencies]
42-
tonic-build = { version = "0.7", default-features = false, features = [
42+
tonic-build = { version = "0.8", default-features = false, features = [
4343
"prost", "transport"
4444
] }
45+
# explicit dep so we can get the version with fixed whitespace.
46+
prost-build = "0.11.1"
4547

4648
[package.metadata.docs.rs]
4749
all-features = true

console-api/src/generated/google.protobuf.rs

Whitespace-only changes.

console-api/src/generated/rs.tokio.console.common.rs

+27
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,18 @@ pub mod metadata {
165165
/// Indicates metadata is associated with an event.
166166
Event = 1,
167167
}
168+
impl Kind {
169+
/// String value of the enum field names used in the ProtoBuf definition.
170+
///
171+
/// The values are not transformed in any way and thus are considered stable
172+
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
173+
pub fn as_str_name(&self) -> &'static str {
174+
match self {
175+
Kind::Span => "SPAN",
176+
Kind::Event => "EVENT",
177+
}
178+
}
179+
}
168180
/// Describes the level of verbosity of a span or event.
169181
///
170182
/// Corresponds to `Level` in the `tracing` crate.
@@ -191,6 +203,21 @@ pub mod metadata {
191203
/// Designates very low priority, often extremely verbose, information.
192204
Trace = 4,
193205
}
206+
impl Level {
207+
/// String value of the enum field names used in the ProtoBuf definition.
208+
///
209+
/// The values are not transformed in any way and thus are considered stable
210+
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
211+
pub fn as_str_name(&self) -> &'static str {
212+
match self {
213+
Level::Error => "ERROR",
214+
Level::Warn => "WARN",
215+
Level::Info => "INFO",
216+
Level::Debug => "DEBUG",
217+
Level::Trace => "TRACE",
218+
}
219+
}
220+
}
194221
}
195222
/// Contains stats about objects that can be polled. Currently these can be:
196223
/// - tasks that have been spawned

console-api/src/generated/rs.tokio.console.instrument.rs

+29-11
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub struct ResumeRequest {
3030
/// - we can use one single timestamp for all the data
3131
/// - we can have all the new_metadata in one place
3232
/// - things such as async ops and resource ops do not make sense
33-
/// on their own as they have relations to tasks and resources
33+
/// on their own as they have relations to tasks and resources
3434
#[derive(Clone, PartialEq, ::prost::Message)]
3535
pub struct Update {
3636
/// The system time when this update was recorded.
@@ -64,6 +64,7 @@ pub struct ResumeResponse {
6464
pub mod instrument_client {
6565
#![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
6666
use tonic::codegen::*;
67+
use tonic::codegen::http::Uri;
6768
/// `InstrumentServer<T>` implements `Instrument` as a service.
6869
#[derive(Debug, Clone)]
6970
pub struct InstrumentClient<T> {
@@ -84,19 +85,24 @@ pub mod instrument_client {
8485
where
8586
T: tonic::client::GrpcService<tonic::body::BoxBody>,
8687
T::Error: Into<StdError>,
87-
T::ResponseBody: Default + Body<Data = Bytes> + Send + 'static,
88+
T::ResponseBody: Body<Data = Bytes> + Send + 'static,
8889
<T::ResponseBody as Body>::Error: Into<StdError> + Send,
8990
{
9091
pub fn new(inner: T) -> Self {
9192
let inner = tonic::client::Grpc::new(inner);
9293
Self { inner }
9394
}
95+
pub fn with_origin(inner: T, origin: Uri) -> Self {
96+
let inner = tonic::client::Grpc::with_origin(inner, origin);
97+
Self { inner }
98+
}
9499
pub fn with_interceptor<F>(
95100
inner: T,
96101
interceptor: F,
97102
) -> InstrumentClient<InterceptedService<T, F>>
98103
where
99104
F: tonic::service::Interceptor,
105+
T::ResponseBody: Default,
100106
T: tonic::codegen::Service<
101107
http::Request<tonic::body::BoxBody>,
102108
Response = http::Response<
@@ -109,19 +115,19 @@ pub mod instrument_client {
109115
{
110116
InstrumentClient::new(InterceptedService::new(inner, interceptor))
111117
}
112-
/// Compress requests with `gzip`.
118+
/// Compress requests with the given encoding.
113119
///
114120
/// This requires the server to support it otherwise it might respond with an
115121
/// error.
116122
#[must_use]
117-
pub fn send_gzip(mut self) -> Self {
118-
self.inner = self.inner.send_gzip();
123+
pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
124+
self.inner = self.inner.send_compressed(encoding);
119125
self
120126
}
121-
/// Enable decompressing responses with `gzip`.
127+
/// Enable decompressing responses.
122128
#[must_use]
123-
pub fn accept_gzip(mut self) -> Self {
124-
self.inner = self.inner.accept_gzip();
129+
pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
130+
self.inner = self.inner.accept_compressed(encoding);
125131
self
126132
}
127133
/// Produces a stream of updates representing the behavior of the instrumented async runtime.
@@ -258,8 +264,8 @@ pub mod instrument_server {
258264
#[derive(Debug)]
259265
pub struct InstrumentServer<T: Instrument> {
260266
inner: _Inner<T>,
261-
accept_compression_encodings: (),
262-
send_compression_encodings: (),
267+
accept_compression_encodings: EnabledCompressionEncodings,
268+
send_compression_encodings: EnabledCompressionEncodings,
263269
}
264270
struct _Inner<T>(Arc<T>);
265271
impl<T: Instrument> InstrumentServer<T> {
@@ -283,6 +289,18 @@ pub mod instrument_server {
283289
{
284290
InterceptedService::new(Self::new(inner), interceptor)
285291
}
292+
/// Enable decompressing requests with the given encoding.
293+
#[must_use]
294+
pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
295+
self.accept_compression_encodings.enable(encoding);
296+
self
297+
}
298+
/// Compress responses with the given encoding, if the client supports it.
299+
#[must_use]
300+
pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
301+
self.send_compression_encodings.enable(encoding);
302+
self
303+
}
286304
}
287305
impl<T, B> tonic::codegen::Service<http::Request<B>> for InstrumentServer<T>
288306
where
@@ -491,7 +509,7 @@ pub mod instrument_server {
491509
write!(f, "{:?}", self.0)
492510
}
493511
}
494-
impl<T: Instrument> tonic::transport::NamedService for InstrumentServer<T> {
512+
impl<T: Instrument> tonic::server::NamedService for InstrumentServer<T> {
495513
const NAME: &'static str = "rs.tokio.console.instrument.Instrument";
496514
}
497515
}

console-api/src/generated/rs.tokio.console.resources.rs

+11
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ pub mod resource {
8080
/// `TIMER` signals that this is a timer resource, e.g. waiting for a sleep to finish.
8181
Timer = 0,
8282
}
83+
impl Known {
84+
/// String value of the enum field names used in the ProtoBuf definition.
85+
///
86+
/// The values are not transformed in any way and thus are considered stable
87+
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
88+
pub fn as_str_name(&self) -> &'static str {
89+
match self {
90+
Known::Timer => "TIMER",
91+
}
92+
}
93+
}
8394
/// Every resource is either a known kind or an other (unknown) kind.
8495
#[derive(Clone, PartialEq, ::prost::Oneof)]
8596
pub enum Kind {

console-api/src/generated/rs.tokio.console.tasks.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub struct TaskDetails {
4747
///
4848
/// This is either:
4949
/// - the raw binary representation of a HdrHistogram.rs `Histogram`
50-
/// serialized to binary in the V2 format (legacy)
50+
/// serialized to binary in the V2 format (legacy)
5151
/// - a binary histogram plus details on outliers (current)
5252
#[prost(oneof="task_details::PollTimesHistogram", tags="3, 4")]
5353
pub poll_times_histogram: ::core::option::Option<task_details::PollTimesHistogram>,
@@ -58,7 +58,7 @@ pub mod task_details {
5858
///
5959
/// This is either:
6060
/// - the raw binary representation of a HdrHistogram.rs `Histogram`
61-
/// serialized to binary in the V2 format (legacy)
61+
/// serialized to binary in the V2 format (legacy)
6262
/// - a binary histogram plus details on outliers (current)
6363
#[derive(Clone, PartialEq, ::prost::Oneof)]
6464
pub enum PollTimesHistogram {
@@ -125,6 +125,18 @@ pub mod task {
125125
/// (such as `tokio::task::spawn_blocking`).
126126
Blocking = 1,
127127
}
128+
impl Kind {
129+
/// String value of the enum field names used in the ProtoBuf definition.
130+
///
131+
/// The values are not transformed in any way and thus are considered stable
132+
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
133+
pub fn as_str_name(&self) -> &'static str {
134+
match self {
135+
Kind::Spawn => "SPAWN",
136+
Kind::Blocking => "BLOCKING",
137+
}
138+
}
139+
}
128140
}
129141
/// Task performance statistics.
130142
#[derive(Clone, PartialEq, ::prost::Message)]

0 commit comments

Comments
 (0)