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

[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 #36453

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36453 from tanvi-jagtap:tjagtap_ruby 5442361454
PiperOrigin-RevId: 630293748
pull/36517/head
Tanvi Jagtap 10 months ago committed by Copybara-Service
parent 29ba397f01
commit b72d31845e
  1. 15
      BUILD
  2. 4
      src/cpp/client/call_credentials.cc
  3. 4
      src/cpp/client/channel_cc.cc
  4. 11
      src/cpp/client/client_context.cc
  5. 5
      src/cpp/client/secure_credentials.cc
  6. 6
      src/cpp/client/xds_credentials.cc
  7. 11
      src/cpp/common/alarm.cc
  8. 10
      src/cpp/common/channel_arguments.cc
  9. 7
      src/cpp/common/completion_queue_cc.cc
  10. 8
      src/cpp/common/tls_certificate_provider.cc
  11. 14
      src/cpp/common/tls_certificate_verifier.cc
  12. 14
      src/cpp/common/tls_credentials_options.cc
  13. 1
      src/cpp/ext/csm/BUILD
  14. 3
      src/cpp/ext/csm/metadata_exchange.cc
  15. 8
      src/cpp/ext/filters/census/client_filter.cc
  16. 1
      src/cpp/ext/gcp/BUILD
  17. 9
      src/cpp/ext/gcp/environment_autodetect.cc
  18. 1
      src/cpp/ext/otel/BUILD
  19. 8
      src/cpp/ext/otel/key_value_iterable.h
  20. 3
      src/cpp/ext/otel/otel_client_call_tracer.cc
  21. 80
      src/cpp/ext/otel/otel_plugin.cc
  22. 14
      src/cpp/server/external_connection_acceptor_impl.cc
  23. 3
      src/cpp/server/health/default_health_check_service.cc
  24. 40
      src/cpp/server/load_reporter/load_data_store.cc
  25. 25
      src/cpp/server/load_reporter/load_reporter.cc
  26. 12
      src/cpp/server/load_reporter/load_reporter_async_service_impl.cc
  27. 6
      src/cpp/server/load_reporter/load_reporter_async_service_impl.h
  28. 5
      src/cpp/server/orca/orca_service.cc
  29. 4
      src/cpp/server/server_builder.cc
  30. 55
      src/cpp/server/server_cc.cc
  31. 15
      src/cpp/server/server_context.cc
  32. 6
      src/cpp/server/xds_server_credentials.cc
  33. 5
      src/cpp/thread_manager/thread_manager.cc

15
BUILD

@ -1192,7 +1192,10 @@ grpc_cc_library(
hdrs = [
"src/cpp/client/secure_credentials.h",
],
external_deps = ["absl/strings"],
external_deps = [
"absl/log:check",
"absl/strings",
],
language = "c++",
deps = [
"exec_ctx",
@ -1214,6 +1217,9 @@ grpc_cc_library(
hdrs = [
"src/cpp/server/secure_server_credentials.h",
],
external_deps = [
"absl/log:check",
],
language = "c++",
public_hdrs = [
"include/grpcpp/xds_server_builder.h",
@ -2124,6 +2130,9 @@ grpc_cc_library(
"src/cpp/server/load_reporter/constants.h",
"src/cpp/server/load_reporter/load_data_store.h",
],
external_deps = [
"absl/log:check",
],
language = "c++",
deps = [
"gpr",
@ -2182,6 +2191,7 @@ grpc_cc_library(
"src/cpp/server/load_reporter/load_reporter_async_service_impl.h",
],
external_deps = [
"absl/log:check",
"absl/memory",
"protobuf_headers",
],
@ -2223,6 +2233,7 @@ grpc_cc_library(
"src/cpp/server/load_reporter/load_reporter.h",
],
external_deps = [
"absl/log:check",
"opencensus-stats",
"opencensus-tags",
"protobuf_headers",
@ -2697,6 +2708,7 @@ grpc_cc_library(
],
external_deps = [
"absl/base:core_headers",
"absl/log:check",
"absl/strings",
"absl/time",
"absl/types:optional",
@ -2855,6 +2867,7 @@ grpc_cc_library(
external_deps = [
"absl/base:core_headers",
"absl/base:endian",
"absl/log:check",
"absl/status",
"absl/status:statusor",
"absl/strings",

@ -11,6 +11,8 @@
// 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.
#include "absl/log/check.h"
#include "absl/strings/str_cat.h"
#include <grpc/support/port_platform.h>
@ -22,7 +24,7 @@ namespace grpc {
CallCredentials::CallCredentials(grpc_call_credentials* c_creds)
: c_creds_(c_creds) {
GPR_ASSERT(c_creds != nullptr);
CHECK_NE(c_creds, nullptr);
}
CallCredentials::~CallCredentials() { grpc_call_credentials_release(c_creds_); }

@ -23,6 +23,8 @@
#include <utility>
#include <vector>
#include "absl/log/check.h"
#include <grpc/grpc.h>
#include <grpc/impl/connectivity_state.h>
#include <grpc/slice.h>
@ -207,7 +209,7 @@ bool Channel::WaitForStateChangeImpl(grpc_connectivity_state last_observed,
void* tag = nullptr;
NotifyOnStateChangeImpl(last_observed, deadline, &cq, nullptr);
cq.Next(&tag, &ok);
GPR_ASSERT(tag == nullptr);
CHECK_EQ(tag, nullptr);
return ok;
}

@ -24,6 +24,7 @@
#include <utility>
#include <vector>
#include "absl/log/check.h"
#include "absl/strings/str_format.h"
#include <grpc/compression.h>
@ -125,7 +126,7 @@ void ClientContext::AddMetadata(const std::string& meta_key,
void ClientContext::set_call(grpc_call* call,
const std::shared_ptr<Channel>& channel) {
internal::MutexLock lock(&mu_);
GPR_ASSERT(call_ == nullptr);
CHECK_EQ(call_, nullptr);
call_ = call;
channel_ = channel;
if (creds_ && !creds_->ApplyToCall(call_)) {
@ -148,7 +149,7 @@ void ClientContext::set_compression_algorithm(
grpc_core::Crash(absl::StrFormat(
"Name for compression algorithm '%d' unknown.", algorithm));
}
GPR_ASSERT(algorithm_name != nullptr);
CHECK_NE(algorithm_name, nullptr);
AddMetadata(GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY, algorithm_name);
}
@ -180,9 +181,9 @@ std::string ClientContext::peer() const {
}
void ClientContext::SetGlobalCallbacks(GlobalCallbacks* client_callbacks) {
GPR_ASSERT(g_client_callbacks == g_default_client_callbacks);
GPR_ASSERT(client_callbacks != nullptr);
GPR_ASSERT(client_callbacks != g_default_client_callbacks);
CHECK(g_client_callbacks == g_default_client_callbacks);
CHECK_NE(client_callbacks, nullptr);
CHECK(client_callbacks != g_default_client_callbacks);
g_client_callbacks = client_callbacks;
}

@ -24,6 +24,7 @@
#include <memory>
#include <utility>
#include "absl/log/check.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_join.h"
@ -362,7 +363,7 @@ class MetadataCredentialsPluginWrapper final : private internal::GrpcLibrary {
grpc_metadata creds_md[GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX],
size_t* num_creds_md, grpc_status_code* status,
const char** error_details) {
GPR_ASSERT(wrapper);
CHECK(wrapper);
MetadataCredentialsPluginWrapper* w =
static_cast<MetadataCredentialsPluginWrapper*>(wrapper);
if (!w->plugin_) {
@ -393,7 +394,7 @@ class MetadataCredentialsPluginWrapper final : private internal::GrpcLibrary {
}
static char* DebugString(void* wrapper) {
GPR_ASSERT(wrapper);
CHECK(wrapper);
MetadataCredentialsPluginWrapper* w =
static_cast<MetadataCredentialsPluginWrapper*>(wrapper);
return gpr_strdup(w->plugin_->DebugString().c_str());

@ -18,6 +18,8 @@
#include <memory>
#include "absl/log/check.h"
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
#include <grpc/support/log.h>
@ -30,13 +32,13 @@ class XdsChannelCredentialsImpl final : public ChannelCredentials {
const std::shared_ptr<ChannelCredentials>& fallback_creds)
: ChannelCredentials(
grpc_xds_credentials_create(fallback_creds->c_creds_)) {
GPR_ASSERT(fallback_creds->c_creds_ != nullptr);
CHECK_NE(fallback_creds->c_creds_, nullptr);
}
};
std::shared_ptr<ChannelCredentials> XdsCredentials(
const std::shared_ptr<ChannelCredentials>& fallback_creds) {
GPR_ASSERT(fallback_creds != nullptr);
CHECK_NE(fallback_creds, nullptr);
return std::make_shared<XdsChannelCredentialsImpl>(fallback_creds);
}

@ -20,6 +20,7 @@
#include <memory>
#include <utility>
#include "absl/log/check.h"
#include "absl/status/status.h"
#include <grpc/event_engine/event_engine.h>
@ -65,10 +66,10 @@ class AlarmImpl : public grpc::internal::CompletionQueueTag {
GRPC_CQ_INTERNAL_REF(cq->cq(), "alarm");
cq_ = cq->cq();
tag_ = tag;
GPR_ASSERT(grpc_cq_begin_op(cq_, this));
CHECK(grpc_cq_begin_op(cq_, this));
Ref();
GPR_ASSERT(cq_armed_.exchange(true) == false);
GPR_ASSERT(!callback_armed_.load());
CHECK(cq_armed_.exchange(true) == false);
CHECK(!callback_armed_.load());
cq_timer_handle_ = event_engine_->RunAfter(
grpc_core::Timestamp::FromTimespecRoundUp(deadline) -
grpc_core::ExecCtx::Get()->Now(),
@ -79,8 +80,8 @@ class AlarmImpl : public grpc::internal::CompletionQueueTag {
// Don't use any CQ at all. Instead just use the timer to fire the function
callback_ = std::move(f);
Ref();
GPR_ASSERT(callback_armed_.exchange(true) == false);
GPR_ASSERT(!cq_armed_.load());
CHECK(callback_armed_.exchange(true) == false);
CHECK(!cq_armed_.load());
callback_timer_handle_ = event_engine_->RunAfter(
grpc_core::Timestamp::FromTimespecRoundUp(deadline) -
grpc_core::ExecCtx::Get()->Now(),

@ -20,6 +20,8 @@
#include <string>
#include <vector>
#include "absl/log/check.h"
#include <grpc/impl/channel_arg_names.h>
#include <grpc/impl/compression_types.h>
#include <grpc/support/log.h>
@ -45,7 +47,7 @@ ChannelArguments::ChannelArguments(const ChannelArguments& other)
for (const auto& a : other.args_) {
grpc_arg ap;
ap.type = a.type;
GPR_ASSERT(list_it_src->c_str() == a.key);
CHECK(list_it_src->c_str() == a.key);
ap.key = const_cast<char*>(list_it_dst->c_str());
++list_it_src;
++list_it_dst;
@ -54,7 +56,7 @@ ChannelArguments::ChannelArguments(const ChannelArguments& other)
ap.value.integer = a.value.integer;
break;
case GRPC_ARG_STRING:
GPR_ASSERT(list_it_src->c_str() == a.value.string);
CHECK(list_it_src->c_str() == a.value.string);
ap.value.string = const_cast<char*>(list_it_dst->c_str());
++list_it_src;
++list_it_dst;
@ -101,7 +103,7 @@ void ChannelArguments::SetSocketMutator(grpc_socket_mutator* mutator) {
for (auto& arg : args_) {
if (arg.type == mutator_arg.type &&
std::string(arg.key) == std::string(mutator_arg.key)) {
GPR_ASSERT(!replaced);
CHECK(!replaced);
arg.value.pointer.vtable->destroy(arg.value.pointer.p);
arg.value.pointer = mutator_arg.value.pointer;
replaced = true;
@ -130,7 +132,7 @@ void ChannelArguments::SetUserAgentPrefix(
++strings_it;
if (arg.type == GRPC_ARG_STRING) {
if (std::string(arg.key) == GRPC_ARG_PRIMARY_USER_AGENT_STRING) {
GPR_ASSERT(arg.value.string == strings_it->c_str());
CHECK(arg.value.string == strings_it->c_str());
*(strings_it) = user_agent_prefix + " " + arg.value.string;
arg.value.string = const_cast<char*>(strings_it->c_str());
replaced = true;

@ -18,6 +18,7 @@
#include <vector>
#include "absl/base/thread_annotations.h"
#include "absl/log/check.h"
#include <grpc/grpc.h>
#include <grpc/support/cpu.h>
@ -83,7 +84,7 @@ struct CallbackAlternativeCQ {
gpr_time_from_millis(100, GPR_TIMESPAN)));
continue;
}
GPR_DEBUG_ASSERT(ev.type == GRPC_OP_COMPLETE);
DCHECK(ev.type == GRPC_OP_COMPLETE);
// We can always execute the callback inline rather than
// pushing it to another Executor thread because this
// thread is definitely running on a background thread, does not
@ -169,7 +170,7 @@ CompletionQueue::CompletionQueueTLSCache::CompletionQueueTLSCache(
}
CompletionQueue::CompletionQueueTLSCache::~CompletionQueueTLSCache() {
GPR_ASSERT(flushed_);
CHECK(flushed_);
}
bool CompletionQueue::CompletionQueueTLSCache::Flush(void** tag, bool* ok) {
@ -199,7 +200,7 @@ void CompletionQueue::ReleaseCallbackAlternativeCQ(CompletionQueue* cq)
(void)cq;
// This accesses g_callback_alternative_cq without acquiring the mutex
// but it's considered safe because it just reads the pointer address.
GPR_DEBUG_ASSERT(cq == g_callback_alternative_cq.cq);
DCHECK(cq == g_callback_alternative_cq.cq);
g_callback_alternative_cq.Unref();
}

@ -17,6 +17,8 @@
#include <string>
#include <vector>
#include "absl/log/check.h"
#include <grpc/credentials.h>
#include <grpc/grpc_security.h>
#include <grpc/support/log.h>
@ -28,7 +30,7 @@ namespace experimental {
StaticDataCertificateProvider::StaticDataCertificateProvider(
const std::string& root_certificate,
const std::vector<IdentityKeyCertPair>& identity_key_cert_pairs) {
GPR_ASSERT(!root_certificate.empty() || !identity_key_cert_pairs.empty());
CHECK(!root_certificate.empty() || !identity_key_cert_pairs.empty());
grpc_tls_identity_pairs* pairs_core = grpc_tls_identity_pairs_create();
for (const IdentityKeyCertPair& pair : identity_key_cert_pairs) {
grpc_tls_identity_pairs_add_pair(pairs_core, pair.private_key.c_str(),
@ -36,7 +38,7 @@ StaticDataCertificateProvider::StaticDataCertificateProvider(
}
c_provider_ = grpc_tls_certificate_provider_static_data_create(
root_certificate.c_str(), pairs_core);
GPR_ASSERT(c_provider_ != nullptr);
CHECK_NE(c_provider_, nullptr);
};
StaticDataCertificateProvider::~StaticDataCertificateProvider() {
@ -50,7 +52,7 @@ FileWatcherCertificateProvider::FileWatcherCertificateProvider(
c_provider_ = grpc_tls_certificate_provider_file_watcher_create(
private_key_path.c_str(), identity_certificate_path.c_str(),
root_cert_path.c_str(), refresh_interval_sec);
GPR_ASSERT(c_provider_ != nullptr);
CHECK_NE(c_provider_, nullptr);
};
FileWatcherCertificateProvider::~FileWatcherCertificateProvider() {

@ -22,6 +22,8 @@
#include <utility>
#include <vector>
#include "absl/log/check.h"
#include <grpc/credentials.h>
#include <grpc/grpc_security.h>
#include <grpc/status.h>
@ -39,7 +41,7 @@ namespace experimental {
TlsCustomVerificationCheckRequest::TlsCustomVerificationCheckRequest(
grpc_tls_custom_verification_check_request* request)
: c_request_(request) {
GPR_ASSERT(c_request_ != nullptr);
CHECK_NE(c_request_, nullptr);
}
grpc::string_ref TlsCustomVerificationCheckRequest::target_name() const {
@ -119,8 +121,8 @@ CertificateVerifier::~CertificateVerifier() {
bool CertificateVerifier::Verify(TlsCustomVerificationCheckRequest* request,
std::function<void(grpc::Status)> callback,
grpc::Status* sync_status) {
GPR_ASSERT(request != nullptr);
GPR_ASSERT(request->c_request() != nullptr);
CHECK_NE(request, nullptr);
CHECK_NE(request->c_request(), nullptr);
{
internal::MutexLock lock(&mu_);
request_map_.emplace(request->c_request(), std::move(callback));
@ -143,8 +145,8 @@ bool CertificateVerifier::Verify(TlsCustomVerificationCheckRequest* request,
}
void CertificateVerifier::Cancel(TlsCustomVerificationCheckRequest* request) {
GPR_ASSERT(request != nullptr);
GPR_ASSERT(request->c_request() != nullptr);
CHECK_NE(request, nullptr);
CHECK_NE(request->c_request(), nullptr);
grpc_tls_certificate_verifier_cancel(verifier_, request->c_request());
}
@ -191,7 +193,7 @@ int ExternalCertificateVerifier::VerifyInCoreExternalVerifier(
internal::MutexLock lock(&self->mu_);
auto pair = self->request_map_.emplace(
request, AsyncRequestState(callback, callback_arg, request));
GPR_ASSERT(pair.second);
CHECK(pair.second);
cpp_request = &pair.first->second.cpp_request;
}
grpc::Status sync_current_verifier_status;

@ -19,6 +19,8 @@
#include <memory>
#include <string>
#include "absl/log/check.h"
#include <grpc/credentials.h>
#include <grpc/grpc_crl_provider.h>
#include <grpc/grpc_security.h>
@ -104,13 +106,13 @@ void TlsCredentialsOptions::set_certificate_verifier(
void TlsCredentialsOptions::set_min_tls_version(grpc_tls_version tls_version) {
grpc_tls_credentials_options* options = mutable_c_credentials_options();
GPR_ASSERT(options != nullptr);
CHECK_NE(options, nullptr);
grpc_tls_credentials_options_set_min_tls_version(options, tls_version);
}
void TlsCredentialsOptions::set_max_tls_version(grpc_tls_version tls_version) {
grpc_tls_credentials_options* options = mutable_c_credentials_options();
GPR_ASSERT(options != nullptr);
CHECK_NE(options, nullptr);
grpc_tls_credentials_options_set_max_tls_version(options, tls_version);
}
@ -121,14 +123,14 @@ grpc_tls_credentials_options* TlsCredentialsOptions::c_credentials_options()
void TlsCredentialsOptions::set_check_call_host(bool check_call_host) {
grpc_tls_credentials_options* options = mutable_c_credentials_options();
GPR_ASSERT(options != nullptr);
CHECK_NE(options, nullptr);
grpc_tls_credentials_options_set_check_call_host(options, check_call_host);
}
void TlsChannelCredentialsOptions::set_verify_server_certs(
bool verify_server_certs) {
grpc_tls_credentials_options* options = mutable_c_credentials_options();
GPR_ASSERT(options != nullptr);
CHECK_NE(options, nullptr);
grpc_tls_credentials_options_set_verify_server_cert(options,
verify_server_certs);
}
@ -136,7 +138,7 @@ void TlsChannelCredentialsOptions::set_verify_server_certs(
void TlsServerCredentialsOptions::set_cert_request_type(
grpc_ssl_client_certificate_request_type cert_request_type) {
grpc_tls_credentials_options* options = mutable_c_credentials_options();
GPR_ASSERT(options != nullptr);
CHECK_NE(options, nullptr);
grpc_tls_credentials_options_set_cert_request_type(options,
cert_request_type);
}
@ -144,7 +146,7 @@ void TlsServerCredentialsOptions::set_cert_request_type(
void TlsServerCredentialsOptions::set_send_client_ca_list(
bool send_client_ca_list) {
grpc_tls_credentials_options* options = mutable_c_credentials_options();
GPR_ASSERT(options != nullptr);
CHECK_NE(options, nullptr);
grpc_tls_credentials_options_set_send_client_ca_list(options,
send_client_ca_list);
}

@ -41,6 +41,7 @@ grpc_cc_library(
],
external_deps = [
"absl/functional:any_invocable",
"absl/log:check",
"absl/status:statusor",
"absl/strings",
"absl/types:optional",

@ -25,6 +25,7 @@
#include <cstdint>
#include <unordered_map>
#include "absl/log/check.h"
#include "absl/status/statusor.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_split.h"
@ -263,7 +264,7 @@ NextFromAttributeList(absl::Span<const RemoteAttribute> attributes,
size_t start_index, size_t curr,
google_protobuf_Struct* decoded_metadata,
upb_Arena* arena) {
GPR_DEBUG_ASSERT(curr >= start_index);
DCHECK_GE(curr, start_index);
const size_t index = curr - start_index;
if (index >= attributes.size()) return absl::nullopt;
const auto& attribute = attributes[index];

@ -28,6 +28,7 @@
#include <utility>
#include <vector>
#include "absl/log/check.h"
#include "absl/status/status.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
@ -106,9 +107,8 @@ OpenCensusClientFilter::MakeCallPromise(
call_context, path != nullptr ? path->Ref() : grpc_core::Slice(),
grpc_core::GetContext<grpc_core::Arena>(),
OpenCensusTracingEnabled() && tracing_enabled_);
GPR_DEBUG_ASSERT(
call_context[GRPC_CONTEXT_CALL_TRACER_ANNOTATION_INTERFACE].value ==
nullptr);
DCHECK(call_context[GRPC_CONTEXT_CALL_TRACER_ANNOTATION_INTERFACE].value ==
nullptr);
call_context[GRPC_CONTEXT_CALL_TRACER_ANNOTATION_INTERFACE].value = tracer;
call_context[GRPC_CONTEXT_CALL_TRACER_ANNOTATION_INTERFACE].destroy = nullptr;
return next_promise_factory(std::move(call_args));
@ -407,7 +407,7 @@ void OpenCensusCallTracer::RecordApiLatency(absl::Duration api_latency,
CensusContext OpenCensusCallTracer::CreateCensusContextForCallAttempt() {
if (!tracing_enabled_) return CensusContext(context_.tags());
GPR_DEBUG_ASSERT(context_.Context().IsValid());
DCHECK(context_.Context().IsValid());
auto context = CensusContext(absl::StrCat("Attempt.", method_),
&(context_.Span()), context_.tags());
grpc::internal::OpenCensusRegistry::Get()

@ -156,6 +156,7 @@ grpc_cc_library(
"absl/base:core_headers",
"absl/container:flat_hash_map",
"absl/functional:any_invocable",
"absl/log:check",
"absl/status",
"absl/status:statusor",
"absl/types:optional",

@ -22,6 +22,7 @@
#include <utility>
#include "absl/container/flat_hash_map.h"
#include "absl/log/check.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/types/optional.h"
@ -245,7 +246,7 @@ class EnvironmentAutoDetectHelper
void FetchMetadataServerAttributesAsynchronouslyLocked()
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_) {
GPR_ASSERT(!attributes_to_fetch_.empty());
CHECK(!attributes_to_fetch_.empty());
for (auto& element : attributes_to_fetch_) {
queries_.push_back(grpc_core::MakeOrphanable<grpc_core::MetadataQuery>(
element.first, &pollent_,
@ -330,7 +331,9 @@ EnvironmentAutoDetect* g_autodetect = nullptr;
} // namespace
void EnvironmentAutoDetect::Create(std::string project_id) {
GPR_ASSERT(g_autodetect == nullptr && !project_id.empty());
CHECK_EQ(g_autodetect, nullptr);
CHECK(!project_id.empty());
g_autodetect = new EnvironmentAutoDetect(project_id);
}
@ -338,7 +341,7 @@ EnvironmentAutoDetect& EnvironmentAutoDetect::Get() { return *g_autodetect; }
EnvironmentAutoDetect::EnvironmentAutoDetect(std::string project_id)
: project_id_(std::move(project_id)) {
GPR_ASSERT(!project_id_.empty());
CHECK(!project_id_.empty());
}
void EnvironmentAutoDetect::NotifyOnDone(absl::AnyInvocable<void()> callback) {

@ -47,6 +47,7 @@ grpc_cc_library(
"absl/container:flat_hash_map",
"absl/container:flat_hash_set",
"absl/functional:any_invocable",
"absl/log:check",
"absl/status",
"absl/status:statusor",
"absl/strings",

@ -23,6 +23,7 @@
#include <utility>
#include "absl/log/check.h"
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "absl/types/span.h"
@ -101,10 +102,9 @@ class OpenTelemetryPlugin::KeyValueIterable
}
// Add per-call optional labels
if (!optional_labels_.empty()) {
GPR_ASSERT(
optional_labels_.size() ==
static_cast<size_t>(grpc_core::ClientCallTracer::CallAttemptTracer::
OptionalLabelKey::kSize));
CHECK(optional_labels_.size() ==
static_cast<size_t>(grpc_core::ClientCallTracer::CallAttemptTracer::
OptionalLabelKey::kSize));
for (size_t i = 0; i < optional_labels_.size(); ++i) {
if (!otel_plugin_->per_call_optional_label_bits_.test(i)) {
continue;

@ -27,6 +27,7 @@
#include <utility>
#include "absl/functional/any_invocable.h"
#include "absl/log/check.h"
#include "absl/status/status.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
@ -209,7 +210,7 @@ OpenTelemetryPlugin::ClientCallTracer::CallAttemptTracer::StartNewTcpTrace() {
void OpenTelemetryPlugin::ClientCallTracer::CallAttemptTracer::SetOptionalLabel(
OptionalLabelKey key, grpc_core::RefCountedStringValue value) {
GPR_ASSERT(key < OptionalLabelKey::kSize);
CHECK(key < OptionalLabelKey::kSize);
optional_labels_[static_cast<size_t>(key)] = std::move(value);
}

@ -22,6 +22,7 @@
#include <type_traits>
#include <utility>
#include "absl/log/check.h"
#include "opentelemetry/metrics/meter.h"
#include "opentelemetry/metrics/meter_provider.h"
#include "opentelemetry/metrics/sync_instruments.h"
@ -205,7 +206,7 @@ OpenTelemetryPluginBuilderImpl::SetServerSelector(
OpenTelemetryPluginBuilderImpl& OpenTelemetryPluginBuilderImpl::AddPluginOption(
std::unique_ptr<InternalOpenTelemetryPluginOption> option) {
// We allow a limit of 64 plugin options to be registered at this time.
GPR_ASSERT(plugin_options_.size() < 64);
CHECK_LT(plugin_options_.size(), 64u);
plugin_options_.push_back(std::move(option));
return *this;
}
@ -275,11 +276,11 @@ void OpenTelemetryPlugin::CallbackMetricReporter::Report(
auto* callback_gauge_state =
absl::get_if<std::unique_ptr<CallbackGaugeState<int64_t>>>(
&instrument_data.instrument);
GPR_ASSERT(callback_gauge_state != nullptr);
CHECK_NE(callback_gauge_state, nullptr);
const auto& descriptor =
grpc_core::GlobalInstrumentsRegistry::GetInstrumentDescriptor(handle);
GPR_ASSERT(descriptor.label_keys.size() == label_values.size());
GPR_ASSERT(descriptor.optional_label_keys.size() == optional_values.size());
CHECK(descriptor.label_keys.size() == label_values.size());
CHECK(descriptor.optional_label_keys.size() == optional_values.size());
auto& cell = (*callback_gauge_state)->caches.at(key_);
std::vector<std::string> key;
key.reserve(label_values.size() +
@ -304,11 +305,11 @@ void OpenTelemetryPlugin::CallbackMetricReporter::Report(
auto* callback_gauge_state =
absl::get_if<std::unique_ptr<CallbackGaugeState<double>>>(
&instrument_data.instrument);
GPR_ASSERT(callback_gauge_state != nullptr);
CHECK_NE(callback_gauge_state, nullptr);
const auto& descriptor =
grpc_core::GlobalInstrumentsRegistry::GetInstrumentDescriptor(handle);
GPR_ASSERT(descriptor.label_keys.size() == label_values.size());
GPR_ASSERT(descriptor.optional_label_keys.size() == optional_values.size());
CHECK(descriptor.label_keys.size() == label_values.size());
CHECK(descriptor.optional_label_keys.size() == optional_values.size());
auto& cell = (*callback_gauge_state)->caches.at(key_);
std::vector<std::string> key;
key.reserve(label_values.size() +
@ -420,9 +421,9 @@ OpenTelemetryPlugin::OpenTelemetryPlugin(
"Compressed message bytes received per server call", "By");
}
// Store optional label keys for per call metrics
GPR_ASSERT(static_cast<size_t>(
grpc_core::ClientCallTracer::CallAttemptTracer::
OptionalLabelKey::kSize) <= kOptionalLabelsSizeLimit);
CHECK(static_cast<size_t>(grpc_core::ClientCallTracer::CallAttemptTracer::
OptionalLabelKey::kSize) <=
kOptionalLabelsSizeLimit);
for (const auto& key : optional_label_keys) {
auto optional_key = OptionalLabelStringToKey(key);
if (optional_key.has_value()) {
@ -434,8 +435,8 @@ OpenTelemetryPlugin::OpenTelemetryPlugin(
grpc_core::GlobalInstrumentsRegistry::ForEach(
[&, this](const grpc_core::GlobalInstrumentsRegistry::
GlobalInstrumentDescriptor& descriptor) {
GPR_ASSERT(descriptor.optional_label_keys.size() <=
kOptionalLabelsSizeLimit);
CHECK(descriptor.optional_label_keys.size() <=
kOptionalLabelsSizeLimit);
if (instruments_data_.size() < descriptor.index + 1) {
instruments_data_.resize(descriptor.index + 1);
}
@ -590,13 +591,13 @@ void OpenTelemetryPlugin::AddCounter(
// This instrument is disabled.
return;
}
GPR_ASSERT(absl::holds_alternative<
std::unique_ptr<opentelemetry::metrics::Counter<uint64_t>>>(
CHECK(absl::holds_alternative<
std::unique_ptr<opentelemetry::metrics::Counter<uint64_t>>>(
instrument_data.instrument));
const auto& descriptor =
grpc_core::GlobalInstrumentsRegistry::GetInstrumentDescriptor(handle);
GPR_ASSERT(descriptor.label_keys.size() == label_values.size());
GPR_ASSERT(descriptor.optional_label_keys.size() == optional_values.size());
CHECK(descriptor.label_keys.size() == label_values.size());
CHECK(descriptor.optional_label_keys.size() == optional_values.size());
absl::get<std::unique_ptr<opentelemetry::metrics::Counter<uint64_t>>>(
instrument_data.instrument)
->Add(value, NPCMetricsKeyValueIterable(
@ -614,13 +615,13 @@ void OpenTelemetryPlugin::AddCounter(
// This instrument is disabled.
return;
}
GPR_ASSERT(absl::holds_alternative<
std::unique_ptr<opentelemetry::metrics::Counter<double>>>(
CHECK(absl::holds_alternative<
std::unique_ptr<opentelemetry::metrics::Counter<double>>>(
instrument_data.instrument));
const auto& descriptor =
grpc_core::GlobalInstrumentsRegistry::GetInstrumentDescriptor(handle);
GPR_ASSERT(descriptor.label_keys.size() == label_values.size());
GPR_ASSERT(descriptor.optional_label_keys.size() == optional_values.size());
CHECK(descriptor.label_keys.size() == label_values.size());
CHECK(descriptor.optional_label_keys.size() == optional_values.size());
absl::get<std::unique_ptr<opentelemetry::metrics::Counter<double>>>(
instrument_data.instrument)
->Add(value, NPCMetricsKeyValueIterable(
@ -638,13 +639,13 @@ void OpenTelemetryPlugin::RecordHistogram(
// This instrument is disabled.
return;
}
GPR_ASSERT(absl::holds_alternative<
std::unique_ptr<opentelemetry::metrics::Histogram<uint64_t>>>(
CHECK(absl::holds_alternative<
std::unique_ptr<opentelemetry::metrics::Histogram<uint64_t>>>(
instrument_data.instrument));
const auto& descriptor =
grpc_core::GlobalInstrumentsRegistry::GetInstrumentDescriptor(handle);
GPR_ASSERT(descriptor.label_keys.size() == label_values.size());
GPR_ASSERT(descriptor.optional_label_keys.size() == optional_values.size());
CHECK(descriptor.label_keys.size() == label_values.size());
CHECK(descriptor.optional_label_keys.size() == optional_values.size());
absl::get<std::unique_ptr<opentelemetry::metrics::Histogram<uint64_t>>>(
instrument_data.instrument)
->Record(value,
@ -664,13 +665,13 @@ void OpenTelemetryPlugin::RecordHistogram(
// This instrument is disabled.
return;
}
GPR_ASSERT(absl::holds_alternative<
std::unique_ptr<opentelemetry::metrics::Histogram<double>>>(
CHECK(absl::holds_alternative<
std::unique_ptr<opentelemetry::metrics::Histogram<double>>>(
instrument_data.instrument));
const auto& descriptor =
grpc_core::GlobalInstrumentsRegistry::GetInstrumentDescriptor(handle);
GPR_ASSERT(descriptor.label_keys.size() == label_values.size());
GPR_ASSERT(descriptor.optional_label_keys.size() == optional_values.size());
CHECK(descriptor.label_keys.size() == label_values.size());
CHECK(descriptor.optional_label_keys.size() == optional_values.size());
absl::get<std::unique_ptr<opentelemetry::metrics::Histogram<double>>>(
instrument_data.instrument)
->Record(value,
@ -702,7 +703,7 @@ void OpenTelemetryPlugin::AddCallback(
auto* callback_gauge_state =
absl::get_if<std::unique_ptr<CallbackGaugeState<int64_t>>>(
&instrument_data.instrument);
GPR_ASSERT(callback_gauge_state != nullptr);
CHECK_NE(callback_gauge_state, nullptr);
(*callback_gauge_state)
->caches.emplace(callback,
CallbackGaugeState<int64_t>::Cache{});
@ -722,7 +723,7 @@ void OpenTelemetryPlugin::AddCallback(
auto* callback_gauge_state =
absl::get_if<std::unique_ptr<CallbackGaugeState<double>>>(
&instrument_data.instrument);
GPR_ASSERT(callback_gauge_state != nullptr);
CHECK_NE(callback_gauge_state, nullptr);
(*callback_gauge_state)
->caches.emplace(callback, CallbackGaugeState<double>::Cache{});
if (!std::exchange((*callback_gauge_state)->ot_callback_registered,
@ -770,9 +771,9 @@ void OpenTelemetryPlugin::RemoveCallback(
auto* callback_gauge_state =
absl::get_if<std::unique_ptr<CallbackGaugeState<int64_t>>>(
&instrument_data.instrument);
GPR_ASSERT(callback_gauge_state != nullptr);
GPR_ASSERT((*callback_gauge_state)->ot_callback_registered);
GPR_ASSERT((*callback_gauge_state)->caches.erase(callback) == 1);
CHECK_NE(callback_gauge_state, nullptr);
CHECK((*callback_gauge_state)->ot_callback_registered);
CHECK_EQ((*callback_gauge_state)->caches.erase(callback), 1u);
if ((*callback_gauge_state)->caches.empty()) {
gauges_that_need_to_remove_callback.push_back(
callback_gauge_state->get());
@ -789,9 +790,9 @@ void OpenTelemetryPlugin::RemoveCallback(
auto* callback_gauge_state =
absl::get_if<std::unique_ptr<CallbackGaugeState<double>>>(
&instrument_data.instrument);
GPR_ASSERT(callback_gauge_state != nullptr);
GPR_ASSERT((*callback_gauge_state)->ot_callback_registered);
GPR_ASSERT((*callback_gauge_state)->caches.erase(callback) == 1);
CHECK_NE(callback_gauge_state, nullptr);
CHECK((*callback_gauge_state)->ot_callback_registered);
CHECK_EQ((*callback_gauge_state)->caches.erase(callback), 1u);
if ((*callback_gauge_state)->caches.empty()) {
gauges_that_need_to_remove_callback.push_back(
callback_gauge_state->get());
@ -822,8 +823,8 @@ void OpenTelemetryPlugin::CallbackGaugeState<ValueType>::Observe(
const auto& descriptor =
grpc_core::GlobalInstrumentsRegistry::GetInstrumentDescriptor({id});
for (const auto& pair : cache) {
GPR_ASSERT(pair.first.size() <= (descriptor.label_keys.size() +
descriptor.optional_label_keys.size()));
CHECK(pair.first.size() <= (descriptor.label_keys.size() +
descriptor.optional_label_keys.size()));
auto& instrument_data = ot_plugin->instruments_data_.at(id);
opentelemetry::nostd::get<opentelemetry::nostd::shared_ptr<
opentelemetry::metrics::ObserverResultT<ValueType>>>(result)
@ -852,8 +853,7 @@ void OpenTelemetryPlugin::CallbackGaugeState<ValueType>::CallbackGaugeCallback(
auto* registered_metric_callback = elem.first;
auto iter = callback_gauge_state->ot_plugin->callback_timestamps_.find(
registered_metric_callback);
GPR_ASSERT(iter !=
callback_gauge_state->ot_plugin->callback_timestamps_.end());
CHECK(iter != callback_gauge_state->ot_plugin->callback_timestamps_.end());
if (now - iter->second < registered_metric_callback->min_interval()) {
// Use cached value.
callback_gauge_state->Observe(result, elem.second);

@ -21,6 +21,8 @@
#include <memory>
#include <utility>
#include "absl/log/check.h"
#include <grpc/support/log.h>
#include <grpcpp/server_builder.h>
#include <grpcpp/support/byte_buffer.h>
@ -49,14 +51,14 @@ ExternalConnectionAcceptorImpl::ExternalConnectionAcceptorImpl(
ServerBuilder::experimental_type::ExternalConnectionType type,
std::shared_ptr<ServerCredentials> creds)
: name_(name), creds_(std::move(creds)) {
GPR_ASSERT(type ==
ServerBuilder::experimental_type::ExternalConnectionType::FROM_FD);
CHECK(type ==
ServerBuilder::experimental_type::ExternalConnectionType::FROM_FD);
}
std::unique_ptr<experimental::ExternalConnectionAcceptor>
ExternalConnectionAcceptorImpl::GetAcceptor() {
grpc_core::MutexLock lock(&mu_);
GPR_ASSERT(!has_acceptor_);
CHECK(!has_acceptor_);
has_acceptor_ = true;
return std::unique_ptr<experimental::ExternalConnectionAcceptor>(
new AcceptorWrapper(shared_from_this()));
@ -85,9 +87,9 @@ void ExternalConnectionAcceptorImpl::Shutdown() {
void ExternalConnectionAcceptorImpl::Start() {
grpc_core::MutexLock lock(&mu_);
GPR_ASSERT(!started_);
GPR_ASSERT(has_acceptor_);
GPR_ASSERT(!shutdown_);
CHECK(!started_);
CHECK(has_acceptor_);
CHECK(!shutdown_);
started_ = true;
}

@ -23,6 +23,7 @@
#include <memory>
#include <utility>
#include "absl/log/check.h"
#include "upb/base/string_view.h"
#include "upb/mem/arena.hpp"
@ -109,7 +110,7 @@ void DefaultHealthCheckService::UnregisterWatch(
DefaultHealthCheckService::HealthCheckServiceImpl*
DefaultHealthCheckService::GetHealthCheckService() {
GPR_ASSERT(impl_ == nullptr);
CHECK(impl_ == nullptr);
impl_ = std::make_unique<HealthCheckServiceImpl>(this);
return impl_.get();
}

@ -26,6 +26,8 @@
#include <set>
#include <unordered_map>
#include "absl/log/check.h"
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
@ -74,7 +76,7 @@ std::set<V> UnorderedMapOfSetExtract(std::unordered_map<K, std::set<V>>& map,
// From a non-empty container, returns a pointer to a random element.
template <typename C>
const typename C::value_type* RandomElement(const C& container) {
GPR_ASSERT(!container.empty());
CHECK(!container.empty());
auto it = container.begin();
std::advance(it, std::rand() % container.size());
return &(*it);
@ -85,12 +87,12 @@ const typename C::value_type* RandomElement(const C& container) {
LoadRecordKey::LoadRecordKey(const std::string& client_ip_and_token,
std::string user_id)
: user_id_(std::move(user_id)) {
GPR_ASSERT(client_ip_and_token.size() >= 2);
CHECK_GE(client_ip_and_token.size(), 2u);
int ip_hex_size;
GPR_ASSERT(sscanf(client_ip_and_token.substr(0, 2).c_str(), "%d",
&ip_hex_size) == 1);
GPR_ASSERT(ip_hex_size == 0 || ip_hex_size == kIpv4AddressLength ||
ip_hex_size == kIpv6AddressLength);
CHECK(sscanf(client_ip_and_token.substr(0, 2).c_str(), "%d", &ip_hex_size) ==
1);
CHECK(ip_hex_size == 0 || ip_hex_size == kIpv4AddressLength ||
ip_hex_size == kIpv6AddressLength);
size_t cur_pos = 2;
client_ip_hex_ = client_ip_and_token.substr(cur_pos, ip_hex_size);
cur_pos += ip_hex_size;
@ -159,9 +161,9 @@ void PerBalancerStore::MergeRow(const LoadRecordKey& key,
// We always keep track of num_calls_in_progress_, so that when this
// store is resumed, we still have a correct value of
// num_calls_in_progress_.
GPR_ASSERT(static_cast<int64_t>(num_calls_in_progress_) +
value.GetNumCallsInProgressDelta() >=
0);
CHECK(static_cast<int64_t>(num_calls_in_progress_) +
value.GetNumCallsInProgressDelta() >=
0);
num_calls_in_progress_ += value.GetNumCallsInProgressDelta();
}
@ -177,14 +179,14 @@ void PerBalancerStore::Resume() {
}
uint64_t PerBalancerStore::GetNumCallsInProgressForReport() {
GPR_ASSERT(!suspended_);
CHECK(!suspended_);
last_reported_num_calls_in_progress_ = num_calls_in_progress_;
return num_calls_in_progress_;
}
void PerHostStore::ReportStreamCreated(const std::string& lb_id,
const std::string& load_key) {
GPR_ASSERT(lb_id != kInvalidLbId);
CHECK(lb_id != kInvalidLbId);
SetUpForNewLbId(lb_id, load_key);
// Prior to this one, there was no load balancer receiving report, so we may
// have unassigned orphaned stores to assign to this new balancer.
@ -210,11 +212,11 @@ void PerHostStore::ReportStreamCreated(const std::string& lb_id,
void PerHostStore::ReportStreamClosed(const std::string& lb_id) {
auto it_store_for_gone_lb = per_balancer_stores_.find(lb_id);
GPR_ASSERT(it_store_for_gone_lb != per_balancer_stores_.end());
CHECK(it_store_for_gone_lb != per_balancer_stores_.end());
// Remove this closed stream from our records.
GPR_ASSERT(UnorderedMapOfSetEraseKeyValue(
load_key_to_receiving_lb_ids_, it_store_for_gone_lb->second->load_key(),
lb_id));
CHECK(UnorderedMapOfSetEraseKeyValue(load_key_to_receiving_lb_ids_,
it_store_for_gone_lb->second->load_key(),
lb_id));
std::set<PerBalancerStore*> orphaned_stores =
UnorderedMapOfSetExtract(assigned_stores_, lb_id);
// The stores that were assigned to this balancer are orphaned now. They
@ -256,7 +258,7 @@ const std::set<PerBalancerStore*>* PerHostStore::GetAssignedStores(
void PerHostStore::AssignOrphanedStore(PerBalancerStore* orphaned_store,
const std::string& new_receiver) {
auto it = assigned_stores_.find(new_receiver);
GPR_ASSERT(it != assigned_stores_.end());
CHECK(it != assigned_stores_.end());
it->second.insert(orphaned_store);
gpr_log(GPR_INFO,
"[PerHostStore %p] Re-assigned orphaned store (%p) with original LB"
@ -269,8 +271,8 @@ void PerHostStore::SetUpForNewLbId(const std::string& lb_id,
const std::string& load_key) {
// The top-level caller (i.e., LoadReportService) should guarantee the
// lb_id is unique for each reporting stream.
GPR_ASSERT(per_balancer_stores_.find(lb_id) == per_balancer_stores_.end());
GPR_ASSERT(assigned_stores_.find(lb_id) == assigned_stores_.end());
CHECK(per_balancer_stores_.find(lb_id) == per_balancer_stores_.end());
CHECK(assigned_stores_.find(lb_id) == assigned_stores_.end());
load_key_to_receiving_lb_ids_[load_key].insert(lb_id);
std::unique_ptr<PerBalancerStore> per_balancer_store(
new PerBalancerStore(lb_id, load_key));
@ -335,7 +337,7 @@ void LoadDataStore::ReportStreamCreated(const std::string& hostname,
void LoadDataStore::ReportStreamClosed(const std::string& hostname,
const std::string& lb_id) {
auto it_per_host_store = per_host_stores_.find(hostname);
GPR_ASSERT(it_per_host_store != per_host_stores_.end());
CHECK(it_per_host_store != per_host_stores_.end());
it_per_host_store->second.ReportStreamClosed(lb_id);
}

@ -27,6 +27,7 @@
#include <set>
#include <tuple>
#include "absl/log/check.h"
#include "opencensus/tags/tag_key.h"
#include <grpc/support/log.h>
@ -168,11 +169,10 @@ double CensusViewProvider::GetRelatedViewDataRowDouble(
const ViewDataMap& view_data_map, const char* view_name,
size_t view_name_len, const std::vector<std::string>& tag_values) {
auto it_vd = view_data_map.find(std::string(view_name, view_name_len));
GPR_ASSERT(it_vd != view_data_map.end());
GPR_ASSERT(it_vd->second.type() ==
::opencensus::stats::ViewData::Type::kDouble);
CHECK(it_vd != view_data_map.end());
CHECK(it_vd->second.type() == ::opencensus::stats::ViewData::Type::kDouble);
auto it_row = it_vd->second.double_data().find(tag_values);
GPR_ASSERT(it_row != it_vd->second.double_data().end());
CHECK(it_row != it_vd->second.double_data().end());
return it_row->second;
}
@ -180,12 +180,11 @@ uint64_t CensusViewProvider::GetRelatedViewDataRowInt(
const ViewDataMap& view_data_map, const char* view_name,
size_t view_name_len, const std::vector<std::string>& tag_values) {
auto it_vd = view_data_map.find(std::string(view_name, view_name_len));
GPR_ASSERT(it_vd != view_data_map.end());
GPR_ASSERT(it_vd->second.type() ==
::opencensus::stats::ViewData::Type::kInt64);
CHECK(it_vd != view_data_map.end());
CHECK(it_vd->second.type() == ::opencensus::stats::ViewData::Type::kInt64);
auto it_row = it_vd->second.int_data().find(tag_values);
GPR_ASSERT(it_row != it_vd->second.int_data().end());
GPR_ASSERT(it_row->second >= 0);
CHECK(it_row != it_vd->second.int_data().end());
CHECK_GE(it_row->second, 0);
return it_row->second;
}
@ -230,7 +229,7 @@ std::string LoadReporter::GenerateLbId() {
}
int64_t lb_id = next_lb_id_++;
// Overflow should never happen.
GPR_ASSERT(lb_id >= 0);
CHECK_GE(lb_id, 0);
// Convert to padded hex string for a 32-bit LB ID. E.g, "0000ca5b".
char buf[kLbIdLength + 1];
snprintf(buf, sizeof(buf), "%08" PRIx64, lb_id);
@ -299,11 +298,11 @@ LoadReporter::GenerateLoads(const std::string& hostname,
const std::string& lb_id) {
grpc_core::MutexLock lock(&store_mu_);
auto assigned_stores = load_data_store_.GetAssignedStores(hostname, lb_id);
GPR_ASSERT(assigned_stores != nullptr);
GPR_ASSERT(!assigned_stores->empty());
CHECK_NE(assigned_stores, nullptr);
CHECK(!assigned_stores->empty());
::google::protobuf::RepeatedPtrField<grpc::lb::v1::Load> loads;
for (PerBalancerStore* per_balancer_store : *assigned_stores) {
GPR_ASSERT(!per_balancer_store->IsSuspended());
CHECK(!per_balancer_store->IsSuspended());
if (!per_balancer_store->load_record_map().empty()) {
for (const auto& p : per_balancer_store->load_record_map()) {
const auto& key = p.first;

@ -22,6 +22,8 @@
#include <google/protobuf/repeated_ptr_field.h>
#include "absl/log/check.h"
#include <grpc/support/port_platform.h>
#include <grpc/support/time.h>
#include <grpcpp/support/status.h>
@ -34,8 +36,8 @@ namespace grpc {
namespace load_reporter {
void LoadReporterAsyncServiceImpl::CallableTag::Run(bool ok) {
GPR_ASSERT(handler_function_ != nullptr);
GPR_ASSERT(handler_ != nullptr);
CHECK(handler_function_ != nullptr);
CHECK_NE(handler_, nullptr);
handler_function_(std::move(handler_), ok);
}
@ -109,7 +111,7 @@ void LoadReporterAsyncServiceImpl::Work(void* arg) {
while (true) {
if (!service->cq_->Next(&tag, &ok)) {
// The completion queue is shutting down.
GPR_ASSERT(service->shutdown_);
CHECK(service->shutdown_);
break;
}
if (tag == service) {
@ -164,7 +166,7 @@ void LoadReporterAsyncServiceImpl::ReportLoadHandler::OnRequestDelivered(
// tag will not pop out if the call never starts (
// https://github.com/grpc/grpc/issues/10136). So we need to manually
// release the ownership of the handler in this case.
GPR_ASSERT(on_done_notified_.ReleaseHandler() != nullptr);
CHECK_NE(on_done_notified_.ReleaseHandler(), nullptr);
}
if (!ok || shutdown_) {
// The value of ok being false means that the server is shutting down.
@ -325,7 +327,7 @@ void LoadReporterAsyncServiceImpl::ReportLoadHandler::SendReport(
void LoadReporterAsyncServiceImpl::ReportLoadHandler::OnDoneNotified(
std::shared_ptr<ReportLoadHandler> self, bool ok) {
GPR_ASSERT(ok);
CHECK(ok);
done_notified_ = true;
if (ctx_.IsCancelled()) {
is_cancelled_ = true;

@ -27,6 +27,8 @@
#include <string>
#include <utility>
#include "absl/log/check.h"
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include <grpcpp/alarm.h>
@ -81,8 +83,8 @@ class LoadReporterAsyncServiceImpl
CallableTag(HandlerFunction func,
std::shared_ptr<ReportLoadHandler> handler)
: handler_function_(std::move(func)), handler_(std::move(handler)) {
GPR_ASSERT(handler_function_ != nullptr);
GPR_ASSERT(handler_ != nullptr);
CHECK(handler_function_ != nullptr);
CHECK_NE(handler_, nullptr);
}
// Runs the tag. This should be called only once. The handler is no longer

@ -21,6 +21,7 @@
#include <utility>
#include "absl/base/thread_annotations.h"
#include "absl/log/check.h"
#include "absl/strings/string_view.h"
#include "absl/time/time.h"
#include "absl/types/optional.h"
@ -71,7 +72,7 @@ class OrcaService::Reactor : public ServerWriteReactor<ByteBuffer>,
engine_(grpc_event_engine::experimental::GetDefaultEventEngine()) {
// Get slice from request.
Slice slice;
GPR_ASSERT(request_buffer->DumpToSingleSlice(&slice).ok());
CHECK(request_buffer->DumpToSingleSlice(&slice).ok());
// Parse request proto.
upb::Arena arena;
xds_service_orca_v3_OrcaLoadReportRequest* request =
@ -173,7 +174,7 @@ OrcaService::OrcaService(ServerMetricRecorder* const server_metric_recorder,
Options options)
: server_metric_recorder_(server_metric_recorder),
min_report_duration_(options.min_report_duration) {
GPR_ASSERT(server_metric_recorder_ != nullptr);
CHECK_NE(server_metric_recorder_, nullptr);
AddMethod(new internal::RpcServiceMethod(
"/xds.service.orca.v3.OpenRcaService/StreamCoreMetrics",
internal::RpcMethod::SERVER_STREAMING, /*handler=*/nullptr));

@ -25,6 +25,8 @@
#include <utility>
#include <vector>
#include "absl/log/check.h"
#include <grpc/grpc.h>
#include <grpc/impl/channel_arg_names.h>
#include <grpc/impl/compression_types.h>
@ -188,7 +190,7 @@ void ServerBuilder::experimental_type::SetAuthorizationPolicyProvider(
void ServerBuilder::experimental_type::EnableCallMetricRecording(
experimental::ServerMetricRecorder* server_metric_recorder) {
builder_->AddChannelArgument(GRPC_ARG_SERVER_CALL_METRIC_RECORDING, 1);
GPR_ASSERT(builder_->server_metric_recorder_ == nullptr);
CHECK_EQ(builder_->server_metric_recorder_, nullptr);
builder_->server_metric_recorder_ = server_metric_recorder;
}

@ -29,6 +29,7 @@
#include <utility>
#include <vector>
#include "absl/log/check.h"
#include "absl/status/status.h"
#include <grpc/byte_buffer.h>
@ -239,11 +240,10 @@ void ServerInterface::RegisteredAsyncRequest::IssueRequest(
ServerCompletionQueue* notification_cq) {
// The following call_start_batch is internally-generated so no need for an
// explanatory log on failure.
GPR_ASSERT(grpc_server_request_registered_call(
server_->server(), registered_method, &call_,
&context_->deadline_, context_->client_metadata_.arr(),
payload, call_cq_->cq(), notification_cq->cq(),
this) == GRPC_CALL_OK);
CHECK(grpc_server_request_registered_call(
server_->server(), registered_method, &call_, &context_->deadline_,
context_->client_metadata_.arr(), payload, call_cq_->cq(),
notification_cq->cq(), this) == GRPC_CALL_OK);
}
ServerInterface::GenericAsyncRequest::GenericAsyncRequest(
@ -254,8 +254,8 @@ ServerInterface::GenericAsyncRequest::GenericAsyncRequest(
: BaseAsyncRequest(server, context, stream, call_cq, notification_cq, tag,
delete_on_finalize) {
grpc_call_details_init(&call_details_);
GPR_ASSERT(notification_cq);
GPR_ASSERT(call_cq);
CHECK(notification_cq);
CHECK(call_cq);
if (issue_request) {
IssueRequest();
}
@ -289,10 +289,10 @@ bool ServerInterface::GenericAsyncRequest::FinalizeResult(void** tag,
void ServerInterface::GenericAsyncRequest::IssueRequest() {
// The following call_start_batch is internally-generated so no need for an
// explanatory log on failure.
GPR_ASSERT(grpc_server_request_call(server_->server(), &call_, &call_details_,
context_->client_metadata_.arr(),
call_cq_->cq(), notification_cq_->cq(),
this) == GRPC_CALL_OK);
CHECK(grpc_server_request_call(server_->server(), &call_, &call_details_,
context_->client_metadata_.arr(),
call_cq_->cq(), notification_cq_->cq(),
this) == GRPC_CALL_OK);
}
namespace {
@ -480,7 +480,7 @@ class Server::SyncRequest final : public grpc::internal::CompletionQueueTag {
// Ensure the cq_ is shutdown
grpc::PhonyTag ignored_tag;
GPR_ASSERT(cq_.Pluck(&ignored_tag) == false);
CHECK(cq_.Pluck(&ignored_tag) == false);
// Cleanup structures allocated during Run/ContinueRunAfterInterception
wrapped_call_.Destroy();
@ -642,8 +642,8 @@ class Server::CallbackRequest final
void Run(bool ok) {
void* ignored = req_;
bool new_ok = ok;
GPR_ASSERT(!req_->FinalizeResult(&ignored, &new_ok));
GPR_ASSERT(ignored == req_);
CHECK(!req_->FinalizeResult(&ignored, &new_ok));
CHECK(ignored == req_);
if (!ok) {
// The call has been shutdown.
@ -824,8 +824,8 @@ class Server::SyncRequestThreadManager : public grpc::ThreadManager {
// Under the AllocatingRequestMatcher model we will never see an invalid tag
// here.
GPR_DEBUG_ASSERT(sync_req != nullptr);
GPR_DEBUG_ASSERT(ok);
DCHECK_NE(sync_req, nullptr);
DCHECK(ok);
sync_req->Run(global_callbacks_, resources);
}
@ -997,8 +997,8 @@ Server::~Server() {
}
void Server::SetGlobalCallbacks(GlobalCallbacks* callbacks) {
GPR_ASSERT(!grpc::g_callbacks);
GPR_ASSERT(callbacks);
CHECK(!grpc::g_callbacks);
CHECK(callbacks);
grpc::g_callbacks.reset(callbacks);
}
@ -1042,8 +1042,8 @@ static grpc_server_register_method_payload_handling PayloadHandlingForMethod(
bool Server::RegisterService(const std::string* addr, grpc::Service* service) {
bool has_async_methods = service->has_async_methods();
if (has_async_methods) {
GPR_ASSERT(service->server_ == nullptr &&
"Can only register an asynchronous service against one server.");
CHECK_EQ(service->server_, nullptr)
<< "Can only register an asynchronous service against one server.";
service->server_ = this;
}
@ -1100,17 +1100,16 @@ bool Server::RegisterService(const std::string* addr, grpc::Service* service) {
}
void Server::RegisterAsyncGenericService(grpc::AsyncGenericService* service) {
GPR_ASSERT(service->server_ == nullptr &&
"Can only register an async generic service against one server.");
CHECK_EQ(service->server_, nullptr)
<< "Can only register an async generic service against one server.";
service->server_ = this;
has_async_generic_service_ = true;
}
void Server::RegisterCallbackGenericService(
grpc::CallbackGenericService* service) {
GPR_ASSERT(
service->server_ == nullptr &&
"Can only register a callback generic service against one server.");
CHECK_EQ(service->server_, nullptr)
<< "Can only register a callback generic service against one server.";
service->server_ = this;
has_callback_generic_service_ = true;
generic_handler_.reset(service->Handler());
@ -1126,7 +1125,7 @@ void Server::RegisterCallbackGenericService(
int Server::AddListeningPort(const std::string& addr,
grpc::ServerCredentials* creds) {
GPR_ASSERT(!started_);
CHECK(!started_);
int port = creds->AddPortToServer(addr, server_);
global_callbacks_->AddPort(this, addr, creds, port);
return port;
@ -1142,7 +1141,7 @@ void Server::UnrefWithPossibleNotify() {
// No refs outstanding means that shutdown has been initiated and no more
// callback requests are outstanding.
grpc::internal::MutexLock lock(&mu_);
GPR_ASSERT(shutdown_);
CHECK(shutdown_);
shutdown_done_ = true;
shutdown_done_cv_.Signal();
}
@ -1160,7 +1159,7 @@ void Server::UnrefAndWaitLocked() {
}
void Server::Start(grpc::ServerCompletionQueue** cqs, size_t num_cqs) {
GPR_ASSERT(!started_);
CHECK(!started_);
global_callbacks_->PreServerStart(this);
started_ = true;

@ -28,6 +28,7 @@
#include <utility>
#include <vector>
#include "absl/log/check.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
@ -155,8 +156,8 @@ class ServerContextBase::CompletionOp final
return;
}
// Start a phony op so that we can return the tag
GPR_ASSERT(grpc_call_start_batch(call_.call(), nullptr, 0, core_cq_tag_,
nullptr) == GRPC_CALL_OK);
CHECK(grpc_call_start_batch(call_.call(), nullptr, 0, core_cq_tag_,
nullptr) == GRPC_CALL_OK);
}
private:
@ -197,8 +198,8 @@ void ServerContextBase::CompletionOp::FillOps(internal::Call* call) {
interceptor_methods_.SetCallOpSetInterface(this);
// The following call_start_batch is internally-generated so no need for an
// explanatory log on failure.
GPR_ASSERT(grpc_call_start_batch(call->call(), &ops, 1, core_cq_tag_,
nullptr) == GRPC_CALL_OK);
CHECK(grpc_call_start_batch(call->call(), &ops, 1, core_cq_tag_, nullptr) ==
GRPC_CALL_OK);
// No interceptors to run here
}
@ -302,7 +303,7 @@ ServerContextBase::CallWrapper::~CallWrapper() {
void ServerContextBase::BeginCompletionOp(
internal::Call* call, std::function<void(bool)> callback,
grpc::internal::ServerCallbackCall* callback_controller) {
GPR_ASSERT(!completion_op_);
CHECK(!completion_op_);
if (rpc_info_) {
rpc_info_->Ref();
}
@ -374,7 +375,7 @@ void ServerContextBase::set_compression_algorithm(
grpc_core::Crash(absl::StrFormat(
"Name for compression algorithm '%d' unknown.", algorithm));
}
GPR_ASSERT(algorithm_name != nullptr);
CHECK_NE(algorithm_name, nullptr);
AddInitialMetadata(GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY, algorithm_name);
}
@ -404,7 +405,7 @@ void ServerContextBase::SetLoadReportingCosts(
void ServerContextBase::CreateCallMetricRecorder(
experimental::ServerMetricRecorder* server_metric_recorder) {
if (call_.call == nullptr) return;
GPR_ASSERT(call_metric_recorder_ == nullptr);
CHECK_EQ(call_metric_recorder_, nullptr);
grpc_core::Arena* arena = grpc_call_get_arena(call_.call);
auto* backend_metric_state =
arena->New<BackendMetricState>(server_metric_recorder);

@ -18,6 +18,8 @@
#include <memory>
#include "absl/log/check.h"
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
#include <grpc/support/log.h>
@ -27,8 +29,8 @@ namespace grpc {
std::shared_ptr<ServerCredentials> XdsServerCredentials(
const std::shared_ptr<ServerCredentials>& fallback_credentials) {
GPR_ASSERT(fallback_credentials != nullptr);
GPR_ASSERT(fallback_credentials->c_creds_ != nullptr);
CHECK_NE(fallback_credentials, nullptr);
CHECK_NE(fallback_credentials->c_creds_, nullptr);
return std::shared_ptr<ServerCredentials>(new ServerCredentials(
grpc_xds_server_credentials_create(fallback_credentials->c_creds_)));
}

@ -20,6 +20,7 @@
#include <climits>
#include "absl/log/check.h"
#include "absl/strings/str_format.h"
#include <grpc/support/log.h>
@ -68,7 +69,7 @@ ThreadManager::ThreadManager(const char*, grpc_resource_quota* resource_quota,
ThreadManager::~ThreadManager() {
{
grpc_core::MutexLock lock(&mu_);
GPR_ASSERT(num_threads_ == 0);
CHECK_EQ(num_threads_, 0);
}
CleanupCompletedThreads();
@ -142,7 +143,7 @@ void ThreadManager::Initialize() {
for (int i = 0; i < min_pollers_; i++) {
WorkerThread* worker = new WorkerThread(this);
GPR_ASSERT(worker->created()); // Must be able to create the minimum
CHECK(worker->created()); // Must be able to create the minimum
worker->Start();
}
}

Loading…
Cancel
Save