[grpc][Gpr_To_Absl_Logging] Migrating from gpr to absl logging GPR_ASSERT (#36269)

[grpc][Gpr_To_Absl_Logging] Migrating from gpr to absl logging GPR_ASSERT
Replacing GPR_ASSERT with absl CHECK

Will not be replacing CHECK with CHECK_EQ , CHECK_NE etc because there are too many callsites. Only a few - which fit into single - line regex will be changed. This would be small in number just to reduce the load later.

Replacing CHECK with CHECK_EQ , CHECK_NE etc could be done using Cider-V once these changes are submitted if we want to clean up later. Given that we have 5000+ instances of GPR_ASSERT to edit, Doing it manually is too much work for both the author and reviewer.

<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes #36269

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36269 from tanvi-jagtap:tjagtap_gpr_assert_qps 26dcf74e27
PiperOrigin-RevId: 623504407
pull/36157/merge
Tanvi Jagtap 11 months ago committed by Copybara-Service
parent 3e0eeed4fa
commit de9bdf7f8e
  1. 2
      CMakeLists.txt
  2. 2
      build_autogenerated.yaml
  3. 9
      test/cpp/qps/BUILD
  4. 3
      test/cpp/qps/benchmark_config.cc
  5. 11
      test/cpp/qps/client_async.cc
  6. 4
      test/cpp/qps/client_sync.cc
  7. 11
      test/cpp/qps/driver.cc
  8. 4
      test/cpp/qps/json_run_localhost.cc
  9. 5
      test/cpp/qps/parse_json.cc
  10. 6
      test/cpp/qps/qps_benchmark_script.bzl
  11. 7
      test/cpp/qps/qps_json_driver.cc
  12. 3
      test/cpp/qps/qps_worker.cc

2
CMakeLists.txt generated

@ -22729,6 +22729,7 @@ target_include_directories(qps_json_driver
target_link_libraries(qps_json_driver
${_gRPC_ALLTARGETS_LIBRARIES}
absl::check
grpc++_test_config
grpc++_test_util
)
@ -22801,6 +22802,7 @@ target_include_directories(qps_worker
target_link_libraries(qps_worker
${_gRPC_ALLTARGETS_LIBRARIES}
absl::check
grpc++_test_config
grpc++_test_util
)

@ -14360,6 +14360,7 @@ targets:
- test/cpp/qps/server_sync.cc
- test/cpp/qps/usage_timer.cc
deps:
- absl/log:check
- grpc++_test_config
- grpc++_test_util
- name: qps_worker
@ -14393,6 +14394,7 @@ targets:
- test/cpp/qps/usage_timer.cc
- test/cpp/qps/worker.cc
deps:
- absl/log:check
- grpc++_test_config
- grpc++_test_util
- name: query_extensions_test

@ -24,7 +24,10 @@ grpc_cc_library(
name = "parse_json",
srcs = ["parse_json.cc"],
hdrs = ["parse_json.h"],
external_deps = ["protobuf"],
external_deps = [
"absl/log:check",
"protobuf",
],
deps = ["//:grpc++"],
)
@ -46,6 +49,7 @@ grpc_cc_library(
"qps_worker.h",
"server.h",
],
external_deps = ["absl/log:check"],
deps = [
":histogram",
":interarrival",
@ -73,6 +77,7 @@ grpc_cc_library(
"driver.h",
"report.h",
],
external_deps = ["absl/log:check"],
deps = [
":histogram",
":parse_json",
@ -97,6 +102,7 @@ grpc_cc_library(
],
external_deps = [
"absl/flags:flag",
"absl/log:check",
],
deps = [
":driver_impl",
@ -123,6 +129,7 @@ grpc_cc_binary(
srcs = ["qps_json_driver.cc"],
external_deps = [
"absl/flags:flag",
"absl/log:check",
],
deps = [
":benchmark_config",

@ -19,6 +19,7 @@
#include "test/cpp/qps/benchmark_config.h"
#include "absl/flags/flag.h"
#include "absl/log/check.h"
#include <grpc/support/log.h>
#include <grpcpp/create_channel.h>
@ -72,7 +73,7 @@ static std::shared_ptr<Reporter> InitBenchmarkReporters() {
std::shared_ptr<ChannelCredentials> channel_creds =
testing::GetCredentialsProvider()->GetChannelCredentials(
absl::GetFlag(FLAGS_rpc_reporter_credential_type), &channel_args);
GPR_ASSERT(!absl::GetFlag(FLAGS_rpc_reporter_server_address).empty());
CHECK(!absl::GetFlag(FLAGS_rpc_reporter_server_address).empty());
composite_reporter->add(std::unique_ptr<Reporter>(new RpcReporter(
"RpcReporter",
grpc::CreateChannel(absl::GetFlag(FLAGS_rpc_reporter_server_address),

@ -27,6 +27,7 @@
#include <utility>
#include <vector>
#include "absl/log/check.h"
#include "absl/memory/memory.h"
#include <grpc/grpc.h>
@ -86,7 +87,7 @@ class ClientRpcContextUnaryImpl : public ClientRpcContext {
prepare_req_(prepare_req) {}
~ClientRpcContextUnaryImpl() override {}
void Start(CompletionQueue* cq, const ClientConfig& config) override {
GPR_ASSERT(!config.use_coalesce_api()); // not supported.
CHECK(!config.use_coalesce_api()); // not supported.
StartInternal(cq);
}
bool RunNextState(bool /*ok*/, HistogramEntry* entry) override {
@ -475,7 +476,7 @@ class ClientRpcContextStreamingPingPongImpl : public ClientRpcContext {
messages_issued_ = 0;
coalesce_ = coalesce;
if (coalesce_) {
GPR_ASSERT(messages_per_stream_ != 0);
CHECK_NE(messages_per_stream_, 0);
context_.set_initial_metadata_corked(true);
}
stream_ = prepare_req_(stub_, &context_, cq);
@ -543,7 +544,7 @@ class ClientRpcContextStreamingFromClientImpl : public ClientRpcContext {
prepare_req_(prepare_req) {}
~ClientRpcContextStreamingFromClientImpl() override {}
void Start(CompletionQueue* cq, const ClientConfig& config) override {
GPR_ASSERT(!config.use_coalesce_api()); // not supported yet.
CHECK(!config.use_coalesce_api()); // not supported yet.
StartInternal(cq);
}
bool RunNextState(bool ok, HistogramEntry* entry) override {
@ -675,7 +676,7 @@ class ClientRpcContextStreamingFromServerImpl : public ClientRpcContext {
prepare_req_(prepare_req) {}
~ClientRpcContextStreamingFromServerImpl() override {}
void Start(CompletionQueue* cq, const ClientConfig& config) override {
GPR_ASSERT(!config.use_coalesce_api()); // not supported
CHECK(!config.use_coalesce_api()); // not supported
StartInternal(cq);
}
bool RunNextState(bool ok, HistogramEntry* entry) override {
@ -790,7 +791,7 @@ class ClientRpcContextGenericStreamingImpl : public ClientRpcContext {
prepare_req_(std::move(prepare_req)) {}
~ClientRpcContextGenericStreamingImpl() override {}
void Start(CompletionQueue* cq, const ClientConfig& config) override {
GPR_ASSERT(!config.use_coalesce_api()); // not supported yet.
CHECK(!config.use_coalesce_api()); // not supported yet.
StartInternal(cq, config.messages_per_stream());
}
bool RunNextState(bool ok, HistogramEntry* entry) override {

@ -24,6 +24,8 @@
#include <thread>
#include <vector>
#include "absl/log/check.h"
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
@ -398,7 +400,7 @@ class SynchronousStreamingBothWaysClient final
};
std::unique_ptr<Client> CreateSynchronousClient(const ClientConfig& config) {
GPR_ASSERT(!config.use_coalesce_api()); // not supported yet.
CHECK(!config.use_coalesce_api()); // not supported yet.
switch (config.rpc_type()) {
case UNARY:
return std::unique_ptr<Client>(new SynchronousUnaryClient(config));

@ -25,6 +25,7 @@
#include <unordered_map>
#include <vector>
#include "absl/log/check.h"
#include "google/protobuf/timestamp.pb.h"
#include <grpc/support/alloc.h>
@ -271,7 +272,7 @@ static void ReceiveFinalStatusFromClients(
// long on some scenarios (e.g. unconstrained streaming_from_server). See
// https://github.com/grpc/grpc/blob/3bd0cd208ea549760a2daf595f79b91b247fe240/test/cpp/qps/server_async.cc#L176
// where the shutdown delay pretty much determines the wait here.
GPR_ASSERT(!client->stream->Read(&client_status));
CHECK(!client->stream->Read(&client_status));
} else {
grpc_core::Crash(
absl::StrFormat("Couldn't get final status from client %zu", i));
@ -323,7 +324,7 @@ static void ReceiveFinalStatusFromServer(const std::vector<ServerData>& servers,
result.add_server_stats()->CopyFrom(server_status.stats());
result.add_server_cores(server_status.cores());
// That final status should be the last message on the server stream
GPR_ASSERT(!server->stream->Read(&server_status));
CHECK(!server->stream->Read(&server_status));
} else {
grpc_core::Crash(
absl::StrFormat("Couldn't get final status from server %zu", i));
@ -407,7 +408,7 @@ std::unique_ptr<ScenarioResult> RunScenario(
workers.push_back(addr);
}
}
GPR_ASSERT(!workers.empty());
CHECK(!workers.empty());
// if num_clients is set to <=0, do dynamic sizing: all workers
// except for servers are clients
@ -418,7 +419,7 @@ std::unique_ptr<ScenarioResult> RunScenario(
// TODO(ctiller): support running multiple configurations, and binpack
// client/server pairs
// to available workers
GPR_ASSERT(workers.size() >= num_clients + num_servers);
CHECK_GE(workers.size(), num_clients + num_servers);
// Trim to just what we need
workers.resize(num_clients + num_servers);
@ -472,7 +473,7 @@ std::unique_ptr<ScenarioResult> RunScenario(
if (qps_server_target_override.length() > 0) {
// overriding the qps server target only makes since if there is <= 1
// servers
GPR_ASSERT(num_servers <= 1);
CHECK_LE(num_servers, 1u);
client_config.clear_server_targets();
client_config.add_server_targets(qps_server_target_override);
}

@ -28,6 +28,8 @@
#include <sys/wait.h>
#endif
#include "absl/log/check.h"
#include <grpc/support/log.h>
#include "src/core/lib/gprpp/crash.h"
@ -134,5 +136,5 @@ int main(int argc, char** argv) {
delete g_workers[i];
}
}
GPR_ASSERT(driver_join_status == 0);
CHECK_EQ(driver_join_status, 0);
}

@ -20,6 +20,7 @@
#include <string>
#include "absl/log/check.h"
#include "absl/strings/str_format.h"
#include <grpc/support/log.h>
@ -43,7 +44,7 @@ void ParseJson(const std::string& json, const std::string& type,
static_cast<int>(status.code()), errmsg.c_str());
grpc_core::Crash(absl::StrFormat("JSON: %s", json.c_str()));
}
GPR_ASSERT(msg->ParseFromString(binary));
CHECK(msg->ParseFromString(binary));
}
std::string SerializeJson(const GRPC_CUSTOM_MESSAGE& msg,
@ -56,7 +57,7 @@ std::string SerializeJson(const GRPC_CUSTOM_MESSAGE& msg,
msg.SerializeToString(&binary);
auto status =
BinaryToJsonString(type_resolver.get(), type, binary, &json_string);
GPR_ASSERT(status.ok());
CHECK(status.ok());
return json_string;
}

@ -56,6 +56,9 @@ def qps_json_driver_batch():
"//test/cpp/util:test_config",
"//test/cpp/util:test_util",
],
external_deps = [
"absl/log:check",
],
tags = [
"qps_json_driver",
"no_mac",
@ -80,6 +83,9 @@ def json_run_localhost_batch():
"//test/cpp/qps:qps_json_driver",
"//test/cpp/qps:qps_worker",
],
external_deps = [
"absl/log:check",
],
deps = [
"//:gpr",
"//test/core/util:grpc_test_util",

@ -22,6 +22,7 @@
#include <set>
#include "absl/flags/flag.h"
#include "absl/log/check.h"
#include <grpc/support/log.h>
#include <grpcpp/impl/codegen/config_protobuf.h>
@ -244,12 +245,12 @@ static bool QpsDriver() {
if (scfile) {
// Read the json data from disk
FILE* json_file = fopen(absl::GetFlag(FLAGS_scenarios_file).c_str(), "r");
GPR_ASSERT(json_file != nullptr);
CHECK_NE(json_file, nullptr);
fseek(json_file, 0, SEEK_END);
long len = ftell(json_file);
char* data = new char[len];
fseek(json_file, 0, SEEK_SET);
GPR_ASSERT(len == (long)fread(data, 1, len, json_file));
CHECK_EQ(len, (long)fread(data, 1, len, json_file));
fclose(json_file);
json = std::string(data, data + len);
delete[] data;
@ -266,7 +267,7 @@ static bool QpsDriver() {
bool success = true;
// Make sure that there is at least some valid scenario here
GPR_ASSERT(scenarios.scenarios_size() > 0);
CHECK_GT(scenarios.scenarios_size(), 0);
for (int i = 0; i < scenarios.scenarios_size(); i++) {
if (absl::GetFlag(FLAGS_search_param).empty()) {

@ -25,6 +25,7 @@
#include <thread>
#include <vector>
#include "absl/log/check.h"
#include "absl/memory/memory.h"
#include <grpc/grpc.h>
@ -180,7 +181,7 @@ class WorkerServiceImpl final : public WorkerService::Service {
void ReleaseInstance() {
std::lock_guard<std::mutex> g(mu_);
GPR_ASSERT(acquired_);
CHECK(acquired_);
acquired_ = false;
}

Loading…
Cancel
Save