From 43f52fb1c0bd7061291a8cf5188e1bf6bcaac8eb Mon Sep 17 00:00:00 2001 From: Rainer Schoenberger Date: Tue, 24 Sep 2024 11:08:19 +0200 Subject: [PATCH 1/2] Step gRPC version to 1.66.1 Signed-off-by: Rainer Schoenberger --- cmake/gRPC.cmake | 2 +- src/libCli/MessageFormatterJson.cpp | 2 +- third_party/gRPC_utils/cli_call.cc | 57 +++--- .../proto_reflection_descriptor_database.h | 55 +++--- .../proto_reflection_descriptor_database.cc | 174 +++++++++--------- 5 files changed, 146 insertions(+), 144 deletions(-) diff --git a/cmake/gRPC.cmake b/cmake/gRPC.cmake index 26424d4..415bd77 100644 --- a/cmake/gRPC.cmake +++ b/cmake/gRPC.cmake @@ -67,7 +67,7 @@ if(GWHISPER_FORCE_BUILDING_GRPC OR GRPC_NOT_FOUND) FetchContent_Declare( grpc GIT_REPOSITORY https://github.com/grpc/grpc - GIT_TAG v1.62.0 + GIT_TAG v1.66.1 GIT_PROGRESS TRUE ) set(FETCHCONTENT_QUIET OFF) diff --git a/src/libCli/MessageFormatterJson.cpp b/src/libCli/MessageFormatterJson.cpp index 9912fb8..a21a6cc 100644 --- a/src/libCli/MessageFormatterJson.cpp +++ b/src/libCli/MessageFormatterJson.cpp @@ -26,7 +26,7 @@ namespace cli printOptions.preserve_proto_field_names = true; // Will print primitive fields regardless of their values. So e.g. an int32 field set to 0 will not be omitted. - printOptions.always_print_primitive_fields = true; + printOptions.always_print_fields_with_no_presence = true; const auto status = google::protobuf::util::MessageToJsonString(f_message, &resultString, printOptions); if(not status.ok()) diff --git a/third_party/gRPC_utils/cli_call.cc b/third_party/gRPC_utils/cli_call.cc index 1831186..0ad7e7e 100644 --- a/third_party/gRPC_utils/cli_call.cc +++ b/third_party/gRPC_utils/cli_call.cc @@ -1,20 +1,20 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ +// +// +// Copyright 2015 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// // MODIFIED by IBM (Rainer Schoenberger) // original: #include "test/cpp/util/cli_call.h" @@ -31,9 +31,10 @@ #include #include +#include "absl/log/check.h" + #include #include -#include #include #include #include @@ -69,8 +70,8 @@ CliCall::CliCall(const std::shared_ptr& channel, : stub_(new grpc::GenericStub(channel)) { gpr_mu_init(&write_mu_); gpr_cv_init(&write_cv_); - // MODIFIED by IBM (Anna Riesch) - // original: no deadline + // MODIFIED by IBM (Anna Riesch, Rainer Schoenberger) + // original: deadline parsed from CLI args if (deadline.has_value()) { // Set timeout if optional parameter has a value. Otherwise don't set timeout = infinite deadline auto deadlineMs = deadline.value(); @@ -89,7 +90,7 @@ CliCall::CliCall(const std::shared_ptr& channel, void* got_tag; bool ok; cq_.Next(&got_tag, &ok); - GPR_ASSERT(ok); + CHECK(ok); } CliCall::~CliCall() { @@ -106,7 +107,7 @@ void CliCall::Write(const std::string& request) { grpc::ByteBuffer send_buffer(&req_slice, 1); call_->Write(send_buffer, tag(2)); cq_.Next(&got_tag, &ok); - GPR_ASSERT(ok); + CHECK(ok); } bool CliCall::Read(std::string* response, @@ -121,7 +122,7 @@ bool CliCall::Read(std::string* response, return false; } std::vector slices; - GPR_ASSERT(recv_buffer.Dump(&slices).ok()); + CHECK(recv_buffer.Dump(&slices).ok()); response->clear(); for (size_t i = 0; i < slices.size(); i++) { @@ -140,7 +141,7 @@ void CliCall::WritesDone() { call_->WritesDone(tag(4)); cq_.Next(&got_tag, &ok); - GPR_ASSERT(ok); + CHECK(ok); } void CliCall::WriteAndWait(const std::string& request) { @@ -183,7 +184,7 @@ bool CliCall::ReadAndMaybeNotifyWrite( cq_result = cq_.Next(&got_tag, &ok); if (got_tag == tag(2)) { - GPR_ASSERT(ok); + CHECK(ok); } } @@ -194,7 +195,7 @@ bool CliCall::ReadAndMaybeNotifyWrite( gpr_mu_lock(&write_mu_); if (!write_done_) { cq_.Next(&got_tag, &ok); - GPR_ASSERT(got_tag != tag(2)); + CHECK(got_tag != tag(2)); write_done_ = true; gpr_cv_signal(&write_cv_); } @@ -204,7 +205,7 @@ bool CliCall::ReadAndMaybeNotifyWrite( } std::vector slices; - GPR_ASSERT(recv_buffer.Dump(&slices).ok()); + CHECK(recv_buffer.Dump(&slices).ok()); response->clear(); for (size_t i = 0; i < slices.size(); i++) { response->append(reinterpret_cast(slices[i].begin()), @@ -223,7 +224,7 @@ Status CliCall::Finish(IncomingMetadataContainer* server_trailing_metadata) { call_->Finish(&status, tag(5)); cq_.Next(&got_tag, &ok); - GPR_ASSERT(ok); + CHECK(ok); if (server_trailing_metadata) { *server_trailing_metadata = ctx_.GetServerTrailingMetadata(); } diff --git a/third_party/gRPC_utils/gRPC_utils/proto_reflection_descriptor_database.h b/third_party/gRPC_utils/gRPC_utils/proto_reflection_descriptor_database.h index 1e758cb..5ddf218 100644 --- a/third_party/gRPC_utils/gRPC_utils/proto_reflection_descriptor_database.h +++ b/third_party/gRPC_utils/gRPC_utils/proto_reflection_descriptor_database.h @@ -1,22 +1,22 @@ -/* - * - * Copyright 2016 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#ifndef GRPC_TEST_CPP_PROTO_SERVER_REFLECTION_DATABSE_H -#define GRPC_TEST_CPP_PROTO_SERVER_REFLECTION_DATABSE_H +// +// +// Copyright 2016 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +#ifndef GRPC_TEST_CPP_UTIL_PROTO_REFLECTION_DESCRIPTOR_DATABASE_H +#define GRPC_TEST_CPP_UTIL_PROTO_REFLECTION_DESCRIPTOR_DATABASE_H #include #include @@ -44,9 +44,9 @@ class ProtoReflectionDescriptorDatabase : public protobuf::DescriptorDatabase { std::unique_ptr stub); explicit ProtoReflectionDescriptorDatabase( - const std::shared_ptr& channel); + const std::shared_ptr& channel); - virtual ~ProtoReflectionDescriptorDatabase(); + ~ProtoReflectionDescriptorDatabase() override; // The following four methods implement DescriptorDatabase interfaces. // @@ -80,10 +80,7 @@ class ProtoReflectionDescriptorDatabase : public protobuf::DescriptorDatabase { std::vector* output) override; // Provide a list of full names of registered services - bool GetServices(std::vector* output); - - /// @brief close the reflection stream with a default deadline. - /// @return return grpc status as a result of call the finish() on the reflection stream. + bool GetServices(std::vector* output); grpc::Status closeDescDbStream(); private: @@ -92,18 +89,18 @@ class ProtoReflectionDescriptorDatabase : public protobuf::DescriptorDatabase { grpc::reflection::v1alpha::ServerReflectionResponse> ClientStream; - const protobuf::FileDescriptorProto ParseFileDescriptorProtoResponse( - const grpc::string& byte_fd_proto); + protobuf::FileDescriptorProto ParseFileDescriptorProtoResponse( + const std::string& byte_fd_proto); void AddFileFromResponse( const grpc::reflection::v1alpha::FileDescriptorResponse& response); - const std::shared_ptr GetStream(); + std::shared_ptr GetStream(); bool DoOneRequest( const grpc::reflection::v1alpha::ServerReflectionRequest& request, grpc::reflection::v1alpha::ServerReflectionResponse& response); - + // MODIFIED: grpc::Status closeStream(); std::shared_ptr stream_; diff --git a/third_party/gRPC_utils/proto_reflection_descriptor_database.cc b/third_party/gRPC_utils/proto_reflection_descriptor_database.cc index 7f3bc3a..61efbba 100644 --- a/third_party/gRPC_utils/proto_reflection_descriptor_database.cc +++ b/third_party/gRPC_utils/proto_reflection_descriptor_database.cc @@ -1,20 +1,20 @@ -/* - * - * Copyright 2016 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ +// +// +// Copyright 2016 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// // MODIFIED by IBM (Rainer Schoenberger) // original: #include "test/cpp/util/proto_reflection_descriptor_database.h" @@ -24,7 +24,10 @@ #include -#include +#include "absl/log/log.h" + +// MODIFIED: unneeded include: +//#include "src/core/util/crash.h" using grpc::reflection::v1alpha::ErrorResponse; using grpc::reflection::v1alpha::ListServiceResponse; @@ -40,11 +43,28 @@ ProtoReflectionDescriptorDatabase::ProtoReflectionDescriptorDatabase( : stub_(std::move(stub)) {} ProtoReflectionDescriptorDatabase::ProtoReflectionDescriptorDatabase( - const std::shared_ptr& channel) + const std::shared_ptr& channel) : stub_(ServerReflection::NewStub(channel)) {} ProtoReflectionDescriptorDatabase::~ProtoReflectionDescriptorDatabase() { - closeStream(); + if (stream_) { + stream_->WritesDone(); + Status status = stream_->Finish(); + if (!status.ok()) { + if (status.error_code() == StatusCode::UNIMPLEMENTED) { + fprintf(stderr, + "Reflection request not implemented; " + "is the ServerReflection service enabled?\n"); + } else { + fprintf(stderr, + "ServerReflectionInfo rpc failed. Error code: %d, message: %s, " + "debug info: %s\n", + static_cast(status.error_code()), + status.error_message().c_str(), + ctx_.debug_error_string().c_str()); + } + } + } } bool ProtoReflectionDescriptorDatabase::FindFileByName( @@ -72,23 +92,19 @@ bool ProtoReflectionDescriptorDatabase::FindFileByName( ServerReflectionResponse::MessageResponseCase::kErrorResponse) { const ErrorResponse& error = response.error_response(); if (error.error_code() == StatusCode::NOT_FOUND) { - gpr_log(GPR_INFO, "NOT_FOUND from server for FindFileByName(%s)", - filename.c_str()); + LOG(INFO) << "NOT_FOUND from server for FindFileByName(" << filename + << ")"; } else { - gpr_log(GPR_INFO, - "Error on FindFileByName(%s)\n\tError code: %d\n" - "\tError Message: %s", - filename.c_str(), error.error_code(), - error.error_message().c_str()); + LOG(INFO) << "Error on FindFileByName(" << filename + << ")\n\tError code: " << error.error_code() + << "\n\tError Message: " << error.error_message(); } } else { - gpr_log( - GPR_INFO, - "Error on FindFileByName(%s) response type\n" - "\tExpecting: %d\n\tReceived: %d", - filename.c_str(), - ServerReflectionResponse::MessageResponseCase::kFileDescriptorResponse, - response.message_response_case()); + LOG(INFO) << "Error on FindFileByName(" << filename + << ") response type\n\tExpecting: " + << ServerReflectionResponse::MessageResponseCase:: + kFileDescriptorResponse + << "\n\tReceived: " << response.message_response_case(); } return cached_db_.FindFileByName(filename, output); @@ -120,24 +136,19 @@ bool ProtoReflectionDescriptorDatabase::FindFileContainingSymbol( const ErrorResponse& error = response.error_response(); if (error.error_code() == StatusCode::NOT_FOUND) { missing_symbols_.insert(symbol_name); - gpr_log(GPR_INFO, - "NOT_FOUND from server for FindFileContainingSymbol(%s)", - symbol_name.c_str()); + LOG(INFO) << "NOT_FOUND from server for FindFileContainingSymbol(" + << symbol_name << ")"; } else { - gpr_log(GPR_INFO, - "Error on FindFileContainingSymbol(%s)\n" - "\tError code: %d\n\tError Message: %s", - symbol_name.c_str(), error.error_code(), - error.error_message().c_str()); + LOG(INFO) << "Error on FindFileContainingSymbol(" << symbol_name + << ")\n\tError code: " << error.error_code() + << "\n\tError Message: " << error.error_message(); } } else { - gpr_log( - GPR_INFO, - "Error on FindFileContainingSymbol(%s) response type\n" - "\tExpecting: %d\n\tReceived: %d", - symbol_name.c_str(), - ServerReflectionResponse::MessageResponseCase::kFileDescriptorResponse, - response.message_response_case()); + LOG(INFO) << "Error on FindFileContainingSymbol(" << symbol_name + << ") response type\n\tExpecting: " + << ServerReflectionResponse::MessageResponseCase:: + kFileDescriptorResponse + << "\n\tReceived: " << response.message_response_case(); } return cached_db_.FindFileContainingSymbol(symbol_name, output); } @@ -153,7 +164,7 @@ bool ProtoReflectionDescriptorDatabase::FindFileContainingExtension( if (missing_extensions_.find(containing_type) != missing_extensions_.end() && missing_extensions_[containing_type].find(field_number) != missing_extensions_[containing_type].end()) { - gpr_log(GPR_INFO, "nested map."); + LOG(INFO) << "nested map."; return false; } @@ -180,24 +191,20 @@ bool ProtoReflectionDescriptorDatabase::FindFileContainingExtension( missing_extensions_[containing_type] = {}; } missing_extensions_[containing_type].insert(field_number); - gpr_log(GPR_INFO, - "NOT_FOUND from server for FindFileContainingExtension(%s, %d)", - containing_type.c_str(), field_number); + LOG(INFO) << "NOT_FOUND from server for FindFileContainingExtension(" + << containing_type << ", " << field_number << ")"; } else { - gpr_log(GPR_INFO, - "Error on FindFileContainingExtension(%s, %d)\n" - "\tError code: %d\n\tError Message: %s", - containing_type.c_str(), field_number, error.error_code(), - error.error_message().c_str()); + LOG(INFO) << "Error on FindFileContainingExtension(" << containing_type + << ", " << field_number + << ")\n\tError code: " << error.error_code() + << "\n\tError Message: " << error.error_message(); } } else { - gpr_log( - GPR_INFO, - "Error on FindFileContainingExtension(%s, %d) response type\n" - "\tExpecting: %d\n\tReceived: %d", - containing_type.c_str(), field_number, - ServerReflectionResponse::MessageResponseCase::kFileDescriptorResponse, - response.message_response_case()); + LOG(INFO) << "Error on FindFileContainingExtension(" << containing_type + << ", " << field_number << ") response type\n\tExpecting: " + << ServerReflectionResponse::MessageResponseCase:: + kFileDescriptorResponse + << "\n\tReceived: " << response.message_response_case(); } return cached_db_.FindFileContainingExtension(containing_type, field_number, @@ -231,21 +238,19 @@ bool ProtoReflectionDescriptorDatabase::FindAllExtensionNumbers( ServerReflectionResponse::MessageResponseCase::kErrorResponse) { const ErrorResponse& error = response.error_response(); if (error.error_code() == StatusCode::NOT_FOUND) { - gpr_log(GPR_INFO, "NOT_FOUND from server for FindAllExtensionNumbers(%s)", - extendee_type.c_str()); + LOG(INFO) << "NOT_FOUND from server for FindAllExtensionNumbers(" + << extendee_type << ")"; } else { - gpr_log(GPR_INFO, - "Error on FindAllExtensionNumbersExtension(%s)\n" - "\tError code: %d\n\tError Message: %s", - extendee_type.c_str(), error.error_code(), - error.error_message().c_str()); + LOG(INFO) << "Error on FindAllExtensionNumbersExtension(" << extendee_type + << ")\n\tError code: " << error.error_code() + << "\n\tError Message: " << error.error_message(); } } return false; } bool ProtoReflectionDescriptorDatabase::GetServices( - std::vector* output) { + std::vector* output) { ServerReflectionRequest request; request.set_list_services(""); ServerReflectionResponse response; @@ -264,23 +269,20 @@ bool ProtoReflectionDescriptorDatabase::GetServices( } else if (response.message_response_case() == ServerReflectionResponse::MessageResponseCase::kErrorResponse) { const ErrorResponse& error = response.error_response(); - gpr_log(GPR_INFO, - "Error on GetServices()\n\tError code: %d\n" - "\tError Message: %s", - error.error_code(), error.error_message().c_str()); + LOG(INFO) << "Error on GetServices()\n\tError code: " << error.error_code() + << "\n\tError Message: " << error.error_message(); } else { - gpr_log( - GPR_INFO, - "Error on GetServices() response type\n\tExpecting: %d\n\tReceived: %d", - ServerReflectionResponse::MessageResponseCase::kListServicesResponse, - response.message_response_case()); + LOG(INFO) + << "Error on GetServices() response type\n\tExpecting: " + << ServerReflectionResponse::MessageResponseCase::kListServicesResponse + << "\n\tReceived: " << response.message_response_case(); } return false; } -const protobuf::FileDescriptorProto +protobuf::FileDescriptorProto ProtoReflectionDescriptorDatabase::ParseFileDescriptorProtoResponse( - const grpc::string& byte_fd_proto) { + const std::string& byte_fd_proto) { protobuf::FileDescriptorProto file_desc_proto; file_desc_proto.ParseFromString(byte_fd_proto); return file_desc_proto; @@ -298,12 +300,14 @@ void ProtoReflectionDescriptorDatabase::AddFileFromResponse( } } -const std::shared_ptr +std::shared_ptr ProtoReflectionDescriptorDatabase::GetStream() { if (!stream_) { + // MODIFIED std::chrono::system_clock::time_point deadline = std::chrono::system_clock::now() + std::chrono::seconds(g_timeoutGrpcMainStreamSeconds); ctx_.set_deadline(deadline); + // END MODIFIED stream_ = stub_->ServerReflectionInfo(&ctx_); } return stream_; From c92f4ce0bcb65ee21413308a0d2fe9e23496eedb Mon Sep 17 00:00:00 2001 From: Rainer Schoenberger Date: Wed, 25 Sep 2024 10:41:13 +0200 Subject: [PATCH 2/2] initialize absl logging Signed-off-by: Rainer Schoenberger --- src/gwhisper/gwhisper.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gwhisper/gwhisper.cpp b/src/gwhisper/gwhisper.cpp index a8df901..d716e91 100644 --- a/src/gwhisper/gwhisper.cpp +++ b/src/gwhisper/gwhisper.cpp @@ -20,6 +20,7 @@ #include #include #include // generated during build +#include "absl/log/initialize.h" using namespace ArgParse; @@ -48,6 +49,9 @@ const char* g_helpString = int main(int argc, char **argv) { + // Some components we are consuming from gRPC (descDb / cliCall) use absl logging. Initialize it here: + absl::InitializeLog(); + // First we construct the initial Grammar for the CLI tool: Grammar grammarPool; GrammarElement *grammarRoot = cli::constructGrammar(grammarPool);