Skip to content

Commit

Permalink
[grpc][Gpr_To_Absl_Logging] Migrating from gpr to absl logging GPR_AS…
Browse files Browse the repository at this point in the history
…SERT (#36467)

[grpc][Gpr_To_Absl_Logging] Migrating from gpr to absl logging GPR_ASSERT
Replacing GPR_ASSERT with absl CHECK.
These changes have been made using string replacement and regex.
Will not be replacing all instances of CHECK with CHECK_EQ , CHECK_NE etc because there are too many callsites. Only ones which are doable using very simple regex with least chance of failure will be replaced.
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 #36467

COPYBARA_INTEGRATE_REVIEW=#36467 from tanvi-jagtap:tjagtap_src_core_lib 30d3ff5
PiperOrigin-RevId: 629995895
  • Loading branch information
tanvi-jagtap authored and Copybara-Service committed May 2, 2024
1 parent 468bb25 commit 9603942
Show file tree
Hide file tree
Showing 25 changed files with 106 additions and 152 deletions.
2 changes: 1 addition & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2983,7 +2983,6 @@ grpc_cc_library(
deps = [
"gpr_platform",
"//src/core:env",
"//src/core:gpr_log_internal",
],
)

Expand Down Expand Up @@ -3100,6 +3099,7 @@ grpc_cc_library(
external_deps = [
"absl/base:core_headers",
"absl/container:inlined_vector",
"absl/log:check",
"absl/status",
"absl/strings:str_format",
],
Expand Down
1 change: 0 additions & 1 deletion Package.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion build_autogenerated.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions gRPC-C++.podspec

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions gRPC-Core.podspec

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion grpc.gemspec

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 14 additions & 10 deletions src/core/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -288,15 +288,6 @@ grpc_cc_library(
],
)

grpc_cc_library(
name = "gpr_log_internal",
hdrs = [
"lib/gpr/log_internal.h",
],
language = "c++",
deps = ["//:gpr_platform"],
)

grpc_cc_library(
name = "env",
srcs = [
Expand Down Expand Up @@ -1276,6 +1267,7 @@ grpc_cc_library(
],
external_deps = [
"absl/base:core_headers",
"absl/log:check",
"absl/status",
"absl/status:statusor",
"absl/types:optional",
Expand Down Expand Up @@ -2865,7 +2857,10 @@ grpc_cc_library(
"lib/transport/bdp_estimator.cc",
],
hdrs = ["lib/transport/bdp_estimator.h"],
external_deps = ["absl/strings"],
external_deps = [
"absl/log:check",
"absl/strings",
],
deps = [
"time",
"//:gpr",
Expand Down Expand Up @@ -7097,6 +7092,7 @@ grpc_cc_library(
],
external_deps = [
"absl/base:core_headers",
"absl/log:check",
"absl/status",
"absl/status:statusor",
"absl/types:optional",
Expand Down Expand Up @@ -7298,6 +7294,9 @@ grpc_cc_library(
hdrs = [
"lib/transport/call_filters.h",
],
external_deps = [
"absl/log:check",
],
deps = [
"call_final_info",
"latch",
Expand Down Expand Up @@ -7405,6 +7404,9 @@ grpc_cc_library(
hdrs = [
"lib/transport/call_spine.h",
],
external_deps = [
"absl/log:check",
],
deps = [
"1999",
"call_arena_allocator",
Expand Down Expand Up @@ -7439,6 +7441,7 @@ grpc_cc_library(
"absl/container:flat_hash_set",
"absl/container:inlined_vector",
"absl/functional:function_ref",
"absl/log:check",
"absl/meta:type_traits",
"absl/strings",
"absl/strings:str_format",
Expand Down Expand Up @@ -7473,6 +7476,7 @@ grpc_cc_library(
],
external_deps = [
"absl/base:core_headers",
"absl/log:check",
"absl/types:optional",
],
deps = [
Expand Down
5 changes: 3 additions & 2 deletions src/core/handshaker/handshaker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <string>
#include <utility>

#include "absl/log/check.h"
#include "absl/status/status.h"
#include "absl/strings/str_format.h"

Expand Down Expand Up @@ -100,7 +101,7 @@ bool HandshakeManager::CallNextHandshakerLocked(grpc_error_handle error) {
this, StatusToString(error).c_str(), is_shutdown_, index_,
HandshakerArgsString(&args_).c_str());
}
GPR_ASSERT(index_ <= handshakers_.size());
CHECK(index_ <= handshakers_.size());
// If we got an error or we've been shut down or we're exiting early or
// we've finished the last handshaker, invoke the on_handshake_done
// callback. Otherwise, call the next handshaker.
Expand Down Expand Up @@ -177,7 +178,7 @@ void HandshakeManager::DoHandshake(grpc_endpoint* endpoint,
bool done;
{
MutexLock lock(&mu_);
GPR_ASSERT(index_ == 0);
CHECK_EQ(index_, 0u);
// Construct handshaker args. These will be passed through all
// handshakers and eventually be freed by the on_handshake_done callback.
args_.endpoint = endpoint;
Expand Down
5 changes: 3 additions & 2 deletions src/core/handshaker/tcp_connect/tcp_connect_handshaker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <memory>

#include "absl/base/thread_annotations.h"
#include "absl/log/check.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/types/optional.h"
Expand Down Expand Up @@ -124,7 +125,7 @@ void TCPConnectHandshaker::DoHandshake(grpc_tcp_server_acceptor* /*acceptor*/,
MutexLock lock(&mu_);
on_handshake_done_ = on_handshake_done;
}
GPR_ASSERT(args->endpoint == nullptr);
CHECK_EQ(args->endpoint, nullptr);
args_ = args;
absl::StatusOr<URI> uri = URI::Parse(
args->args.GetString(GRPC_ARG_TCP_HANDSHAKER_RESOLVED_ADDRESS).value());
Expand Down Expand Up @@ -179,7 +180,7 @@ void TCPConnectHandshaker::Connected(void* arg, grpc_error_handle error) {
}
return;
}
GPR_ASSERT(self->endpoint_to_destroy_ != nullptr);
CHECK_NE(self->endpoint_to_destroy_, nullptr);
self->args_->endpoint = self->endpoint_to_destroy_;
self->endpoint_to_destroy_ = nullptr;
if (self->bind_endpoint_to_pollset_) {
Expand Down
1 change: 0 additions & 1 deletion src/core/lib/config/load_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

#include <grpc/support/port_platform.h>

#include "src/core/lib/gpr/log_internal.h"
#include "src/core/lib/gprpp/env.h"

namespace grpc_core {
Expand Down
55 changes: 0 additions & 55 deletions src/core/lib/gpr/log_internal.h

This file was deleted.

8 changes: 5 additions & 3 deletions src/core/lib/transport/batch_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include <type_traits>

#include "absl/log/check.h"

#include <grpc/support/port_platform.h>

#include "src/core/lib/promise/poll.h"
Expand Down Expand Up @@ -96,13 +98,13 @@ BatchBuilder::Batch* BatchBuilder::GetBatch(Target target) {
batch_ = GetContext<Arena>()->NewPooled<Batch>(payload_,
target_->stream_refcount);
}
GPR_ASSERT(batch_ != nullptr);
CHECK_NE(batch_, nullptr);
return batch_;
}

void BatchBuilder::FlushBatch() {
GPR_ASSERT(batch_ != nullptr);
GPR_ASSERT(target_.has_value());
CHECK_NE(batch_, nullptr);
CHECK(target_.has_value());
if (grpc_call_trace.enabled()) {
gpr_log(
GPR_DEBUG, "%sPerform transport stream op batch: %p %s",
Expand Down
4 changes: 3 additions & 1 deletion src/core/lib/transport/bdp_estimator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#include <algorithm>

#include "absl/log/check.h"

#include <grpc/support/port_platform.h>

grpc_core::TraceFlag grpc_bdp_estimator_trace(false, "bdp_estimator");
Expand Down Expand Up @@ -53,7 +55,7 @@ Timestamp BdpEstimator::CompletePing() {
std::string(name_).c_str(), accumulator_, estimate_, dt,
bw / 125000.0, bw_est_ / 125000.0);
}
GPR_ASSERT(ping_state_ == PingState::STARTED);
CHECK(ping_state_ == PingState::STARTED);
if (accumulator_ > 2 * estimate_ / 3 && bw > bw_est_) {
estimate_ = std::max(accumulator_, estimate_ * 2);
bw_est_ = bw;
Expand Down
5 changes: 3 additions & 2 deletions src/core/lib/transport/bdp_estimator.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <string>

#include "absl/log/check.h"
#include "absl/strings/string_view.h"

#include <grpc/support/log.h>
Expand Down Expand Up @@ -54,7 +55,7 @@ class BdpEstimator {
gpr_log(GPR_INFO, "bdp[%s]:sched acc=%" PRId64 " est=%" PRId64,
std::string(name_).c_str(), accumulator_, estimate_);
}
GPR_ASSERT(ping_state_ == PingState::UNSCHEDULED);
CHECK(ping_state_ == PingState::UNSCHEDULED);
ping_state_ = PingState::SCHEDULED;
accumulator_ = 0;
}
Expand All @@ -67,7 +68,7 @@ class BdpEstimator {
gpr_log(GPR_INFO, "bdp[%s]:start acc=%" PRId64 " est=%" PRId64,
std::string(name_).c_str(), accumulator_, estimate_);
}
GPR_ASSERT(ping_state_ == PingState::SCHEDULED);
CHECK(ping_state_ == PingState::SCHEDULED);
ping_state_ = PingState::STARTED;
ping_start_time_ = gpr_now(GPR_CLOCK_MONOTONIC);
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/lib/transport/call_destination.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class UnstartedCallDestination
// and started.
// Must be called from the party owned by the call, eg the following must
// hold:
// GPR_ASSERT(GetContext<Activity>() == unstarted_call_handler.party());
// CHECK(GetContext<Activity>() == unstarted_call_handler.party());
virtual void StartCall(UnstartedCallHandler unstarted_call_handler) = 0;
};

Expand Down

0 comments on commit 9603942

Please sign in to comment.