feat: add gRPC reflection service (#1208)

* feat: add gRPC reflection service

* feat: add gRPC reflection service
This commit is contained in:
LFC
2023-03-21 11:23:29 +08:00
committed by GitHub
parent b8f7f603cf
commit af101480b3
5 changed files with 35 additions and 3 deletions

17
Cargo.lock generated
View File

@@ -3097,7 +3097,7 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]]
name = "greptime-proto"
version = "0.1.0"
source = "git+https://github.com/GreptimeTeam/greptime-proto.git?rev=dcf253314a05c9821bd90e7e09a168256c84f250#dcf253314a05c9821bd90e7e09a168256c84f250"
source = "git+https://github.com/GreptimeTeam/greptime-proto.git?rev=eb760d219206c77dd3a105ecb6a3ba97d9d650ec#eb760d219206c77dd3a105ecb6a3ba97d9d650ec"
dependencies = [
"prost",
"tonic",
@@ -6940,6 +6940,7 @@ dependencies = [
"tokio-stream",
"tokio-test",
"tonic",
"tonic-reflection",
"tower",
"tower-http",
]
@@ -8129,6 +8130,20 @@ dependencies = [
"syn",
]
[[package]]
name = "tonic-reflection"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67494bad4dda4c9bffae901dfe14e2b2c0f760adb4706dc10beeb81799f7f7b2"
dependencies = [
"bytes",
"prost",
"prost-types",
"tokio",
"tokio-stream",
"tonic",
]
[[package]]
name = "toolchain_find"
version = "0.2.0"

View File

@@ -10,7 +10,7 @@ common-base = { path = "../common/base" }
common-error = { path = "../common/error" }
common-time = { path = "../common/time" }
datatypes = { path = "../datatypes" }
greptime-proto = { git = "https://github.com/GreptimeTeam/greptime-proto.git", rev = "dcf253314a05c9821bd90e7e09a168256c84f250" }
greptime-proto = { git = "https://github.com/GreptimeTeam/greptime-proto.git", rev = "eb760d219206c77dd3a105ecb6a3ba97d9d650ec" }
prost.workspace = true
snafu = { version = "0.7", features = ["backtraces"] }
tonic.workspace = true

View File

@@ -68,6 +68,7 @@ tokio-rustls = "0.23"
tokio-stream = { version = "0.1", features = ["net"] }
tokio.workspace = true
tonic.workspace = true
tonic-reflection = "0.6"
tower = { version = "0.4", features = ["full"] }
tower-http = { version = "0.3", features = ["full"] }

View File

@@ -269,6 +269,12 @@ pub enum Error {
#[snafu(display("Invalid flush argument: {}", err_msg))]
InvalidFlushArgument { err_msg: String },
#[snafu(display("Failed to build gRPC reflection service, source: {}", source))]
GrpcReflectionService {
source: tonic_reflection::server::Error,
backtrace: Backtrace,
},
}
pub type Result<T> = std::result::Result<T, Error>;
@@ -287,6 +293,7 @@ impl ErrorExt for Error {
| InvalidPromRemoteReadQueryResult { .. }
| TcpBind { .. }
| CatalogError { .. }
| GrpcReflectionService { .. }
| BuildingContext { .. } => StatusCode::Internal,
InsertScript { source, .. }

View File

@@ -33,7 +33,9 @@ use tokio_stream::wrappers::TcpListenerStream;
use tonic::Status;
use crate::auth::UserProviderRef;
use crate::error::{AlreadyStartedSnafu, Result, StartGrpcSnafu, TcpBindSnafu};
use crate::error::{
AlreadyStartedSnafu, GrpcReflectionServiceSnafu, Result, StartGrpcSnafu, TcpBindSnafu,
};
use crate::grpc::database::DatabaseService;
use crate::grpc::flight::FlightHandler;
use crate::grpc::handler::GreptimeRequestHandler;
@@ -109,10 +111,17 @@ impl Server for GrpcServer {
(listener, addr)
};
let reflection_service = tonic_reflection::server::Builder::configure()
.register_encoded_file_descriptor_set(api::v1::GREPTIME_GRPC_DESC)
.with_service_name("greptime.v1.GreptimeDatabase")
.build()
.context(GrpcReflectionServiceSnafu)?;
// Would block to serve requests.
tonic::transport::Server::builder()
.add_service(self.create_flight_service())
.add_service(self.create_database_service())
.add_service(reflection_service)
.serve_with_incoming_shutdown(TcpListenerStream::new(listener), rx.map(drop))
.await
.context(StartGrpcSnafu)?;