From 87858b66b5b680d03aa0393b3c78c84db6b6b8e1 Mon Sep 17 00:00:00 2001 From: Ben Sully Date: Tue, 17 Sep 2024 06:09:00 -0500 Subject: [PATCH] chore: bump dependencies and fix clippy/lint errors (#113) --- CHANGELOG.md | 7 + crates/grafana-plugin-sdk/Cargo.toml | 16 +- .../src/backend/resource.rs | 2 +- .../grafana-plugin-sdk/src/data/field_type.rs | 3 +- .../grafana-plugin-sdk/src/data/frame/mod.rs | 4 - crates/grafana-plugin-sdk/src/lib.rs | 8 +- .../src/pluginv2/pluginv2.rs | 221 +++++++----------- rust-toolchain.toml | 4 +- 8 files changed, 104 insertions(+), 161 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8688576d..6bb70b6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - ReleaseDate +- Bump itertools dependency to 0.13.0 +- Bump prost dependency to 0.13.2 +- Bump reqwest dependency to 0.12.7 +- Bump tonic dependency to 0.12.2 +- Bump tonic-health dependency to 0.12.2 +- Increase MSRV to 1.63, due to tokio-util requiring it + ## [0.4.3] - 2024-01-18 ### Added diff --git a/crates/grafana-plugin-sdk/Cargo.toml b/crates/grafana-plugin-sdk/Cargo.toml index 4118ba4b..3d98a0c1 100644 --- a/crates/grafana-plugin-sdk/Cargo.toml +++ b/crates/grafana-plugin-sdk/Cargo.toml @@ -4,7 +4,7 @@ version = "0.4.3" authors = ["Ben Sully "] license = "MIT/Apache-2.0" edition = "2021" -rust-version = "1.57" +rust-version = "1.63" repository = "https://github.com/grafana/grafana-plugin-sdk-rust" description = "SDK for building Grafana backend plugins." @@ -18,10 +18,10 @@ futures-core = "0.3.28" futures-util = "0.3.28" grafana-plugin-sdk-macros = { version = "0.4.3", path = "../grafana-plugin-sdk-macros" } http = "1.0.0" -itertools = "0.12.0" +itertools = "0.13.0" num-traits = "0.2.15" -prost = "0.12.3" -reqwest_lib = { package = "reqwest", version = "0.11.18", optional = true } +prost = "0.13.2" +reqwest_lib = { package = "reqwest", version = "0.12.7", optional = true } serde = { version = "1.0.164", features = ["derive"] } serde_json = { version = "1.0.96", features = ["float_roundtrip", "raw_value"] } serde_with = "3.0.0" @@ -29,8 +29,8 @@ thiserror = "1.0.40" time = { version = "0.3.22", features = ["formatting", "macros"] } tokio = { version = "1.28.2", features = ["rt-multi-thread"] } tokio-stream = { version = "0.1.14", features = ["net"] } -tonic = "0.10.2" -tonic-health = "0.10.2" +tonic = "0.12.2" +tonic-health = "0.12.2" tracing = "0.1.37" tracing-core = "0.1.31" tracing-log = "0.2.0" @@ -52,8 +52,8 @@ tokio = { version = "1.28.2", features = ["rt-multi-thread"] } tokio-stream = "0.1.14" [build-dependencies] -prost-build = { version = "0.12.3", optional = true } -tonic-build = { version = "0.10.2", optional = true } +prost-build = { version = "0.13.2", optional = true } +tonic-build = { version = "0.12.2", optional = true } # docs.rs-specific configuration [package.metadata.docs.rs] diff --git a/crates/grafana-plugin-sdk/src/backend/resource.rs b/crates/grafana-plugin-sdk/src/backend/resource.rs index 099ff64c..7ce880bd 100644 --- a/crates/grafana-plugin-sdk/src/backend/resource.rs +++ b/crates/grafana-plugin-sdk/src/backend/resource.rs @@ -66,7 +66,7 @@ impl TryFrom for CallResourceRequest { impl TryFrom> for pluginv2::CallResourceResponse { type Error = ConvertToError; fn try_from(mut other: Response) -> Result { - let grouped_headers = other.headers_mut().drain().group_by(|x| x.0.clone()); + let grouped_headers = other.headers_mut().drain().chunk_by(|x| x.0.clone()); let headers = grouped_headers .into_iter() .map(|(k, values)| { diff --git a/crates/grafana-plugin-sdk/src/data/field_type.rs b/crates/grafana-plugin-sdk/src/data/field_type.rs index 74881f3b..c81ac419 100644 --- a/crates/grafana-plugin-sdk/src/data/field_type.rs +++ b/crates/grafana-plugin-sdk/src/data/field_type.rs @@ -201,6 +201,7 @@ impl IntoFieldType for NaiveDate { fn into_field_type(self) -> Option { self.and_hms_opt(0, 0, 0) .expect("hms are valid") + .and_utc() .timestamp_nanos_opt() } } @@ -219,7 +220,7 @@ impl IntoFieldType for NaiveDateTime { type ElementType = i64; const TYPE_INFO_TYPE: TypeInfoType = TypeInfoType::Time; fn into_field_type(self) -> Option { - self.timestamp_nanos_opt() + self.and_utc().timestamp_nanos_opt() } } diff --git a/crates/grafana-plugin-sdk/src/data/frame/mod.rs b/crates/grafana-plugin-sdk/src/data/frame/mod.rs index ebc8221d..4a71f4ca 100644 --- a/crates/grafana-plugin-sdk/src/data/frame/mod.rs +++ b/crates/grafana-plugin-sdk/src/data/frame/mod.rs @@ -24,10 +24,6 @@ pub const TIME_FIELD_NAME: &str = "Time"; /// The standard name for time series value fields. pub const VALUE_FIELD_NAME: &str = "Value"; -mod sealed { - pub trait Sealed {} -} - /// A structured, two-dimensional data frame. /// /// `Frame`s can be created manually using [`Frame::new`] if desired. diff --git a/crates/grafana-plugin-sdk/src/lib.rs b/crates/grafana-plugin-sdk/src/lib.rs index 6914fe35..ca320143 100644 --- a/crates/grafana-plugin-sdk/src/lib.rs +++ b/crates/grafana-plugin-sdk/src/lib.rs @@ -3,11 +3,11 @@ This crate contains a Rust implementation of the Grafana plugin SDK. It is divided into three main modules: - [`backend`] contains the traits that must be implemented by backend plugins for various pieces of functionality, -whether querying data, calling resources, or streaming data between Grafana and the plugin. + whether querying data, calling resources, or streaming data between Grafana and the plugin. - [`data`] contains the fundamental data structures used by backend plugins, such as [`Frame`][data::Frame]s, [`Field`][data::Field]s, -and their associated metadata. + and their associated metadata. - [`live`] contains functionality used by [Grafana Live], the streaming messaging service available from -Grafana 8.0. + Grafana 8.0. The [`prelude`] contains some useful unambiguous traits which are helpful when creating some structures, particularly [`Frame`][data::Frame]s and [`Field`][data::Field]s. @@ -24,7 +24,7 @@ the [crate examples] or [sample app repo] to get started with writing a backend The following feature flags enable additional functionality for this crate: - `reqwest` - adds an [`IntoHttpResponse`][crate::backend::IntoHttpResponse] implementation for - [`reqwest::Response`] + [`reqwest::Response`] [Backend plugins on grafana.com]: https://grafana.com/docs/grafana/latest/developers/plugins/backend/ [Grafana Live]: https://grafana.com/docs/grafana/latest/live/ diff --git a/crates/grafana-plugin-sdk/src/pluginv2/pluginv2.rs b/crates/grafana-plugin-sdk/src/pluginv2/pluginv2.rs index 8b48f391..360fb6c2 100644 --- a/crates/grafana-plugin-sdk/src/pluginv2/pluginv2.rs +++ b/crates/grafana-plugin-sdk/src/pluginv2/pluginv2.rs @@ -1,4 +1,4 @@ -#[allow(clippy::derive_partial_eq_without_eq)] +// This file is @generated by prost-build. #[derive(Clone, PartialEq, ::prost::Message)] pub struct AppInstanceSettings { #[prost(bytes = "vec", tag = "3")] @@ -11,7 +11,6 @@ pub struct AppInstanceSettings { #[prost(int64, tag = "5")] pub last_updated_ms: i64, } -#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct DataSourceInstanceSettings { #[prost(int64, tag = "1")] @@ -40,7 +39,6 @@ pub struct DataSourceInstanceSettings { #[prost(string, tag = "11")] pub uid: ::prost::alloc::string::String, } -#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct User { #[prost(string, tag = "1")] @@ -52,7 +50,6 @@ pub struct User { #[prost(string, tag = "4")] pub role: ::prost::alloc::string::String, } -#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct PluginContext { /// The Grafana organization id the request originating from. @@ -83,13 +80,11 @@ pub struct PluginContext { DataSourceInstanceSettings, >, } -#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct StringList { #[prost(string, repeated, tag = "1")] pub values: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, } -#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct CallResourceRequest { #[prost(message, optional, tag = "1")] @@ -105,7 +100,6 @@ pub struct CallResourceRequest { #[prost(bytes = "bytes", tag = "6")] pub body: ::prost::bytes::Bytes, } -#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct CallResourceResponse { #[prost(int32, tag = "1")] @@ -115,15 +109,13 @@ pub struct CallResourceResponse { #[prost(bytes = "bytes", tag = "3")] pub body: ::prost::bytes::Bytes, } -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] +#[derive(Clone, Copy, PartialEq, ::prost::Message)] pub struct TimeRange { #[prost(int64, tag = "1")] pub from_epoch_ms: i64, #[prost(int64, tag = "2")] pub to_epoch_ms: i64, } -#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct DataQuery { #[prost(string, tag = "1")] @@ -140,7 +132,6 @@ pub struct DataQuery { pub query_type: ::prost::alloc::string::String, } /// QueryDataRequest -#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct QueryDataRequest { #[prost(message, optional, tag = "1")] @@ -155,7 +146,6 @@ pub struct QueryDataRequest { #[prost(message, repeated, tag = "3")] pub queries: ::prost::alloc::vec::Vec, } -#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct QueryDataResponse { /// Map of refId to response @@ -165,7 +155,6 @@ pub struct QueryDataResponse { DataResponse, >, } -#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct DataResponse { /// Arrow encoded DataFrames @@ -184,13 +173,11 @@ pub struct DataResponse { #[prost(int32, tag = "4")] pub status: i32, } -#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct CollectMetricsRequest { #[prost(message, optional, tag = "1")] pub plugin_context: ::core::option::Option, } -#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct CollectMetricsResponse { #[prost(message, optional, tag = "1")] @@ -198,14 +185,12 @@ pub struct CollectMetricsResponse { } /// Nested message and enum types in `CollectMetricsResponse`. pub mod collect_metrics_response { - #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct Payload { #[prost(bytes = "vec", tag = "1")] pub prometheus: ::prost::alloc::vec::Vec, } } -#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct CheckHealthRequest { #[prost(message, optional, tag = "1")] @@ -217,7 +202,6 @@ pub struct CheckHealthRequest { ::prost::alloc::string::String, >, } -#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct CheckHealthResponse { #[prost(enumeration = "check_health_response::HealthStatus", tag = "1")] @@ -269,7 +253,6 @@ pub mod check_health_response { } } } -#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct SubscribeStreamRequest { #[prost(message, optional, tag = "1")] @@ -282,7 +265,6 @@ pub struct SubscribeStreamRequest { #[prost(bytes = "bytes", tag = "3")] pub data: ::prost::bytes::Bytes, } -#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct SubscribeStreamResponse { /// status of subscribe response. @@ -336,7 +318,6 @@ pub mod subscribe_stream_response { } } } -#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct PublishStreamRequest { #[prost(message, optional, tag = "1")] @@ -349,7 +330,6 @@ pub struct PublishStreamRequest { #[prost(bytes = "vec", tag = "3")] pub data: ::prost::alloc::vec::Vec, } -#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct PublishStreamResponse { /// status of publish response. @@ -405,7 +385,6 @@ pub mod publish_stream_response { } } } -#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct RunStreamRequest { #[prost(message, optional, tag = "1")] @@ -418,7 +397,6 @@ pub struct RunStreamRequest { #[prost(bytes = "bytes", tag = "3")] pub data: ::prost::bytes::Bytes, } -#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct StreamPacket { /// JSON-encoded data to publish into a channel. @@ -449,8 +427,8 @@ pub mod resource_client { where T: tonic::client::GrpcService, T::Error: Into, - T::ResponseBody: Body + Send + 'static, - ::Error: Into + Send, + T::ResponseBody: Body + std::marker::Send + 'static, + ::Error: Into + std::marker::Send, { pub fn new(inner: T) -> Self { let inner = tonic::client::Grpc::new(inner); @@ -475,7 +453,7 @@ pub mod resource_client { >, , - >>::Error: Into + Send + Sync, + >>::Error: Into + std::marker::Send + std::marker::Sync, { ResourceClient::new(InterceptedService::new(inner, interceptor)) } @@ -561,8 +539,8 @@ pub mod data_client { where T: tonic::client::GrpcService, T::Error: Into, - T::ResponseBody: Body + Send + 'static, - ::Error: Into + Send, + T::ResponseBody: Body + std::marker::Send + 'static, + ::Error: Into + std::marker::Send, { pub fn new(inner: T) -> Self { let inner = tonic::client::Grpc::new(inner); @@ -587,7 +565,7 @@ pub mod data_client { >, , - >>::Error: Into + Send + Sync, + >>::Error: Into + std::marker::Send + std::marker::Sync, { DataClient::new(InterceptedService::new(inner, interceptor)) } @@ -670,8 +648,8 @@ pub mod diagnostics_client { where T: tonic::client::GrpcService, T::Error: Into, - T::ResponseBody: Body + Send + 'static, - ::Error: Into + Send, + T::ResponseBody: Body + std::marker::Send + 'static, + ::Error: Into + std::marker::Send, { pub fn new(inner: T) -> Self { let inner = tonic::client::Grpc::new(inner); @@ -696,7 +674,7 @@ pub mod diagnostics_client { >, , - >>::Error: Into + Send + Sync, + >>::Error: Into + std::marker::Send + std::marker::Sync, { DiagnosticsClient::new(InterceptedService::new(inner, interceptor)) } @@ -807,8 +785,8 @@ pub mod stream_client { where T: tonic::client::GrpcService, T::Error: Into, - T::ResponseBody: Body + Send + 'static, - ::Error: Into + Send, + T::ResponseBody: Body + std::marker::Send + 'static, + ::Error: Into + std::marker::Send, { pub fn new(inner: T) -> Self { let inner = tonic::client::Grpc::new(inner); @@ -833,7 +811,7 @@ pub mod stream_client { >, , - >>::Error: Into + Send + Sync, + >>::Error: Into + std::marker::Send + std::marker::Sync, { StreamClient::new(InterceptedService::new(inner, interceptor)) } @@ -962,12 +940,12 @@ pub mod resource_server { use tonic::codegen::*; /// Generated trait containing gRPC methods that should be implemented for use with ResourceServer. #[async_trait] - pub trait Resource: Send + Sync + 'static { + pub trait Resource: std::marker::Send + std::marker::Sync + 'static { /// Server streaming response type for the CallResource method. type CallResourceStream: tonic::codegen::tokio_stream::Stream< Item = std::result::Result, > - + Send + + std::marker::Send + 'static; async fn call_resource( &self, @@ -978,20 +956,18 @@ pub mod resource_server { >; } #[derive(Debug)] - pub struct ResourceServer { - inner: _Inner, + pub struct ResourceServer { + inner: Arc, accept_compression_encodings: EnabledCompressionEncodings, send_compression_encodings: EnabledCompressionEncodings, max_decoding_message_size: Option, max_encoding_message_size: Option, } - struct _Inner(Arc); - impl ResourceServer { + impl ResourceServer { pub fn new(inner: T) -> Self { Self::from_arc(Arc::new(inner)) } pub fn from_arc(inner: Arc) -> Self { - let inner = _Inner(inner); Self { inner, accept_compression_encodings: Default::default(), @@ -1041,8 +1017,8 @@ pub mod resource_server { impl tonic::codegen::Service> for ResourceServer where T: Resource, - B: Body + Send + 'static, - B::Error: Into + Send + 'static, + B: Body + std::marker::Send + 'static, + B::Error: Into + std::marker::Send + 'static, { type Response = http::Response; type Error = std::convert::Infallible; @@ -1054,7 +1030,6 @@ pub mod resource_server { Poll::Ready(Ok(())) } fn call(&mut self, req: http::Request) -> Self::Future { - let inner = self.inner.clone(); match req.uri().path() { "/pluginv2.Resource/CallResource" => { #[allow(non_camel_case_types)] @@ -1086,7 +1061,6 @@ pub mod resource_server { let max_encoding_message_size = self.max_encoding_message_size; let inner = self.inner.clone(); let fut = async move { - let inner = inner.0; let method = CallResourceSvc(inner); let codec = tonic::codec::ProstCodec::default(); let mut grpc = tonic::server::Grpc::new(codec) @@ -1108,8 +1082,11 @@ pub mod resource_server { Ok( http::Response::builder() .status(200) - .header("grpc-status", "12") - .header("content-type", "application/grpc") + .header("grpc-status", tonic::Code::Unimplemented as i32) + .header( + http::header::CONTENT_TYPE, + tonic::metadata::GRPC_CONTENT_TYPE, + ) .body(empty_body()) .unwrap(), ) @@ -1118,7 +1095,7 @@ pub mod resource_server { } } } - impl Clone for ResourceServer { + impl Clone for ResourceServer { fn clone(&self) -> Self { let inner = self.inner.clone(); Self { @@ -1130,18 +1107,10 @@ pub mod resource_server { } } } - impl Clone for _Inner { - fn clone(&self) -> Self { - Self(Arc::clone(&self.0)) - } - } - impl std::fmt::Debug for _Inner { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{:?}", self.0) - } - } - impl tonic::server::NamedService for ResourceServer { - const NAME: &'static str = "pluginv2.Resource"; + /// Generated gRPC service name + pub const SERVICE_NAME: &str = "pluginv2.Resource"; + impl tonic::server::NamedService for ResourceServer { + const NAME: &'static str = SERVICE_NAME; } } /// Generated server implementations. @@ -1150,7 +1119,7 @@ pub mod data_server { use tonic::codegen::*; /// Generated trait containing gRPC methods that should be implemented for use with DataServer. #[async_trait] - pub trait Data: Send + Sync + 'static { + pub trait Data: std::marker::Send + std::marker::Sync + 'static { async fn query_data( &self, request: tonic::Request, @@ -1160,20 +1129,18 @@ pub mod data_server { >; } #[derive(Debug)] - pub struct DataServer { - inner: _Inner, + pub struct DataServer { + inner: Arc, accept_compression_encodings: EnabledCompressionEncodings, send_compression_encodings: EnabledCompressionEncodings, max_decoding_message_size: Option, max_encoding_message_size: Option, } - struct _Inner(Arc); - impl DataServer { + impl DataServer { pub fn new(inner: T) -> Self { Self::from_arc(Arc::new(inner)) } pub fn from_arc(inner: Arc) -> Self { - let inner = _Inner(inner); Self { inner, accept_compression_encodings: Default::default(), @@ -1223,8 +1190,8 @@ pub mod data_server { impl tonic::codegen::Service> for DataServer where T: Data, - B: Body + Send + 'static, - B::Error: Into + Send + 'static, + B: Body + std::marker::Send + 'static, + B::Error: Into + std::marker::Send + 'static, { type Response = http::Response; type Error = std::convert::Infallible; @@ -1236,7 +1203,6 @@ pub mod data_server { Poll::Ready(Ok(())) } fn call(&mut self, req: http::Request) -> Self::Future { - let inner = self.inner.clone(); match req.uri().path() { "/pluginv2.Data/QueryData" => { #[allow(non_camel_case_types)] @@ -1265,7 +1231,6 @@ pub mod data_server { let max_encoding_message_size = self.max_encoding_message_size; let inner = self.inner.clone(); let fut = async move { - let inner = inner.0; let method = QueryDataSvc(inner); let codec = tonic::codec::ProstCodec::default(); let mut grpc = tonic::server::Grpc::new(codec) @@ -1287,8 +1252,11 @@ pub mod data_server { Ok( http::Response::builder() .status(200) - .header("grpc-status", "12") - .header("content-type", "application/grpc") + .header("grpc-status", tonic::Code::Unimplemented as i32) + .header( + http::header::CONTENT_TYPE, + tonic::metadata::GRPC_CONTENT_TYPE, + ) .body(empty_body()) .unwrap(), ) @@ -1297,7 +1265,7 @@ pub mod data_server { } } } - impl Clone for DataServer { + impl Clone for DataServer { fn clone(&self) -> Self { let inner = self.inner.clone(); Self { @@ -1309,18 +1277,10 @@ pub mod data_server { } } } - impl Clone for _Inner { - fn clone(&self) -> Self { - Self(Arc::clone(&self.0)) - } - } - impl std::fmt::Debug for _Inner { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{:?}", self.0) - } - } - impl tonic::server::NamedService for DataServer { - const NAME: &'static str = "pluginv2.Data"; + /// Generated gRPC service name + pub const SERVICE_NAME: &str = "pluginv2.Data"; + impl tonic::server::NamedService for DataServer { + const NAME: &'static str = SERVICE_NAME; } } /// Generated server implementations. @@ -1329,7 +1289,7 @@ pub mod diagnostics_server { use tonic::codegen::*; /// Generated trait containing gRPC methods that should be implemented for use with DiagnosticsServer. #[async_trait] - pub trait Diagnostics: Send + Sync + 'static { + pub trait Diagnostics: std::marker::Send + std::marker::Sync + 'static { async fn check_health( &self, request: tonic::Request, @@ -1346,20 +1306,18 @@ pub mod diagnostics_server { >; } #[derive(Debug)] - pub struct DiagnosticsServer { - inner: _Inner, + pub struct DiagnosticsServer { + inner: Arc, accept_compression_encodings: EnabledCompressionEncodings, send_compression_encodings: EnabledCompressionEncodings, max_decoding_message_size: Option, max_encoding_message_size: Option, } - struct _Inner(Arc); - impl DiagnosticsServer { + impl DiagnosticsServer { pub fn new(inner: T) -> Self { Self::from_arc(Arc::new(inner)) } pub fn from_arc(inner: Arc) -> Self { - let inner = _Inner(inner); Self { inner, accept_compression_encodings: Default::default(), @@ -1409,8 +1367,8 @@ pub mod diagnostics_server { impl tonic::codegen::Service> for DiagnosticsServer where T: Diagnostics, - B: Body + Send + 'static, - B::Error: Into + Send + 'static, + B: Body + std::marker::Send + 'static, + B::Error: Into + std::marker::Send + 'static, { type Response = http::Response; type Error = std::convert::Infallible; @@ -1422,7 +1380,6 @@ pub mod diagnostics_server { Poll::Ready(Ok(())) } fn call(&mut self, req: http::Request) -> Self::Future { - let inner = self.inner.clone(); match req.uri().path() { "/pluginv2.Diagnostics/CheckHealth" => { #[allow(non_camel_case_types)] @@ -1453,7 +1410,6 @@ pub mod diagnostics_server { let max_encoding_message_size = self.max_encoding_message_size; let inner = self.inner.clone(); let fut = async move { - let inner = inner.0; let method = CheckHealthSvc(inner); let codec = tonic::codec::ProstCodec::default(); let mut grpc = tonic::server::Grpc::new(codec) @@ -1499,7 +1455,6 @@ pub mod diagnostics_server { let max_encoding_message_size = self.max_encoding_message_size; let inner = self.inner.clone(); let fut = async move { - let inner = inner.0; let method = CollectMetricsSvc(inner); let codec = tonic::codec::ProstCodec::default(); let mut grpc = tonic::server::Grpc::new(codec) @@ -1521,8 +1476,11 @@ pub mod diagnostics_server { Ok( http::Response::builder() .status(200) - .header("grpc-status", "12") - .header("content-type", "application/grpc") + .header("grpc-status", tonic::Code::Unimplemented as i32) + .header( + http::header::CONTENT_TYPE, + tonic::metadata::GRPC_CONTENT_TYPE, + ) .body(empty_body()) .unwrap(), ) @@ -1531,7 +1489,7 @@ pub mod diagnostics_server { } } } - impl Clone for DiagnosticsServer { + impl Clone for DiagnosticsServer { fn clone(&self) -> Self { let inner = self.inner.clone(); Self { @@ -1543,18 +1501,10 @@ pub mod diagnostics_server { } } } - impl Clone for _Inner { - fn clone(&self) -> Self { - Self(Arc::clone(&self.0)) - } - } - impl std::fmt::Debug for _Inner { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{:?}", self.0) - } - } - impl tonic::server::NamedService for DiagnosticsServer { - const NAME: &'static str = "pluginv2.Diagnostics"; + /// Generated gRPC service name + pub const SERVICE_NAME: &str = "pluginv2.Diagnostics"; + impl tonic::server::NamedService for DiagnosticsServer { + const NAME: &'static str = SERVICE_NAME; } } /// Generated server implementations. @@ -1563,7 +1513,7 @@ pub mod stream_server { use tonic::codegen::*; /// Generated trait containing gRPC methods that should be implemented for use with StreamServer. #[async_trait] - pub trait Stream: Send + Sync + 'static { + pub trait Stream: std::marker::Send + std::marker::Sync + 'static { /// SubscribeStream called when a user tries to subscribe to a plugin/datasource /// managed channel path – thus plugin can check subscribe permissions and communicate /// options with Grafana Core. When the first subscriber joins a channel, RunStream @@ -1579,7 +1529,7 @@ pub mod stream_server { type RunStreamStream: tonic::codegen::tokio_stream::Stream< Item = std::result::Result, > - + Send + + std::marker::Send + 'static; /// RunStream will be initiated by Grafana to consume a stream. RunStream will be /// called once for the first client successfully subscribed to a channel path. @@ -1602,20 +1552,18 @@ pub mod stream_server { >; } #[derive(Debug)] - pub struct StreamServer { - inner: _Inner, + pub struct StreamServer { + inner: Arc, accept_compression_encodings: EnabledCompressionEncodings, send_compression_encodings: EnabledCompressionEncodings, max_decoding_message_size: Option, max_encoding_message_size: Option, } - struct _Inner(Arc); - impl StreamServer { + impl StreamServer { pub fn new(inner: T) -> Self { Self::from_arc(Arc::new(inner)) } pub fn from_arc(inner: Arc) -> Self { - let inner = _Inner(inner); Self { inner, accept_compression_encodings: Default::default(), @@ -1665,8 +1613,8 @@ pub mod stream_server { impl tonic::codegen::Service> for StreamServer where T: Stream, - B: Body + Send + 'static, - B::Error: Into + Send + 'static, + B: Body + std::marker::Send + 'static, + B::Error: Into + std::marker::Send + 'static, { type Response = http::Response; type Error = std::convert::Infallible; @@ -1678,7 +1626,6 @@ pub mod stream_server { Poll::Ready(Ok(())) } fn call(&mut self, req: http::Request) -> Self::Future { - let inner = self.inner.clone(); match req.uri().path() { "/pluginv2.Stream/SubscribeStream" => { #[allow(non_camel_case_types)] @@ -1709,7 +1656,6 @@ pub mod stream_server { let max_encoding_message_size = self.max_encoding_message_size; let inner = self.inner.clone(); let fut = async move { - let inner = inner.0; let method = SubscribeStreamSvc(inner); let codec = tonic::codec::ProstCodec::default(); let mut grpc = tonic::server::Grpc::new(codec) @@ -1756,7 +1702,6 @@ pub mod stream_server { let max_encoding_message_size = self.max_encoding_message_size; let inner = self.inner.clone(); let fut = async move { - let inner = inner.0; let method = RunStreamSvc(inner); let codec = tonic::codec::ProstCodec::default(); let mut grpc = tonic::server::Grpc::new(codec) @@ -1802,7 +1747,6 @@ pub mod stream_server { let max_encoding_message_size = self.max_encoding_message_size; let inner = self.inner.clone(); let fut = async move { - let inner = inner.0; let method = PublishStreamSvc(inner); let codec = tonic::codec::ProstCodec::default(); let mut grpc = tonic::server::Grpc::new(codec) @@ -1824,8 +1768,11 @@ pub mod stream_server { Ok( http::Response::builder() .status(200) - .header("grpc-status", "12") - .header("content-type", "application/grpc") + .header("grpc-status", tonic::Code::Unimplemented as i32) + .header( + http::header::CONTENT_TYPE, + tonic::metadata::GRPC_CONTENT_TYPE, + ) .body(empty_body()) .unwrap(), ) @@ -1834,7 +1781,7 @@ pub mod stream_server { } } } - impl Clone for StreamServer { + impl Clone for StreamServer { fn clone(&self) -> Self { let inner = self.inner.clone(); Self { @@ -1846,17 +1793,9 @@ pub mod stream_server { } } } - impl Clone for _Inner { - fn clone(&self) -> Self { - Self(Arc::clone(&self.0)) - } - } - impl std::fmt::Debug for _Inner { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{:?}", self.0) - } - } - impl tonic::server::NamedService for StreamServer { - const NAME: &'static str = "pluginv2.Stream"; + /// Generated gRPC service name + pub const SERVICE_NAME: &str = "pluginv2.Stream"; + impl tonic::server::NamedService for StreamServer { + const NAME: &'static str = SERVICE_NAME; } } diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 72552224..3c7cae90 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "1.62.0" -components = ["rustfmt", "clippy"] +channel = "1.80.1" +components = ["rustfmt", "clippy", "rust-analyzer"]