Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ray/util/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ ray_cc_library(
":thread_utils",
"@com_github_spdlog//:spdlog",
"@com_google_absl//absl/debugging:failure_signal_handler",
"@com_google_absl//absl/log:globals",
"@com_google_absl//absl/strings:str_format",
"@com_google_googletest//:gtest_prod",
],
Expand Down
22 changes: 22 additions & 0 deletions src/ray/util/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <iostream>
#include <limits>
#include <memory>
#include <mutex>
#include <sstream>
#include <string>
#include <string_view>
Expand All @@ -44,6 +45,7 @@
#include "absl/debugging/failure_signal_handler.h"
#include "absl/debugging/stacktrace.h"
#include "absl/debugging/symbolize.h"
#include "absl/log/globals.h"
#include "absl/strings/numbers.h"
#include "absl/strings/str_format.h"
#include "ray/util/thread_utils.h"
Expand Down Expand Up @@ -345,12 +347,32 @@ void RayLog::InitLogFormat() {
return 1;
}

namespace {

// gRPC >= 1.65 logs through absl. When GRPC_VERBOSITY is unset it leaves absl's
// minimum log level alone, and absl defaults to INFO, so gRPC INFO messages (e.g.
// "Got goaway") end up on stderr and are forwarded to the driver. Older gRPC
// defaulted to ERROR; keep that unless the user asks for more with
// GRPC_VERBOSITY. Ray's own logging goes through spdlog and is unaffected.
void InitAbslLogging() {
static std::once_flag once;
std::call_once(once, [] {
const char *grpc_verbosity = std::getenv("GRPC_VERBOSITY");
if (grpc_verbosity == nullptr || grpc_verbosity[0] == '\0') {
absl::SetMinLogLevel(absl::LogSeverityAtLeast::kError);
}
});
}

} // namespace

/*static*/ void RayLog::StartRayLog(const std::string &app_name,
RayLogLevel severity_threshold,
const std::string &log_filepath,
const std::string &err_log_filepath,
size_t log_rotation_max_size,
size_t log_rotation_file_num) {
InitAbslLogging();
InitSeverityThreshold(severity_threshold);
InitLogFormat();

Expand Down
1 change: 1 addition & 0 deletions src/ray/util/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ ray_cc_test(
"//src/ray/util:path_utils",
"//src/ray/util:time",
"@boost//:asio",
"@com_google_absl//absl/log:globals",
"@com_google_absl//absl/strings:str_format",
"@com_google_googletest//:gtest_main",
"@nlohmann_json",
Expand Down
10 changes: 10 additions & 0 deletions src/ray/util/tests/logging_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <string>
#include <vector>

#include "absl/log/globals.h"
#include "absl/strings/str_format.h"
#include "absl/strings/str_split.h"
#include "gtest/gtest.h"
Expand Down Expand Up @@ -189,6 +190,15 @@ TEST(PrintLogTest, TestRayLogEveryMs) {
EXPECT_LT(occurrences, 15);
}

// gRPC logs through absl; without GRPC_VERBOSITY its INFO messages would reach
// stderr. StartRayLog keeps absl at ERROR, as older gRPC did.
TEST(PrintLogTest, TestAbslMinLogLevelDefaultsToError) {
ASSERT_EQ(std::getenv("GRPC_VERBOSITY"), nullptr);
RayLog::StartRayLog("/tmp/gcs", RayLogLevel::INFO, /*log_filepath=*/"");
EXPECT_EQ(absl::MinLogLevel(), absl::LogSeverityAtLeast::kError);
RayLog::ShutDownRayLog();
}
Comment on lines +195 to +200

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The test TestAbslMinLogLevelDefaultsToError is environment-dependent and will fail if the GRPC_VERBOSITY environment variable is set (even to an empty string) in the test runner's environment. To make the test robust and prevent flaky failures in local development or CI environments, we should skip the assertion or the test when GRPC_VERBOSITY is present.

TEST(PrintLogTest, TestAbslMinLogLevelDefaultsToError) {
  if (std::getenv("GRPC_VERBOSITY") != nullptr) {
    SUCCEED() << "Skipping test because GRPC_VERBOSITY is set in the environment.";
    return;
  }
  RayLog::StartRayLog("/tmp/gcs", RayLogLevel::INFO, /*log_filepath=*/"");
  EXPECT_EQ(absl::MinLogLevel(), absl::LogSeverityAtLeast::kError);
  RayLog::ShutDownRayLog();
}


TEST(PrintLogTest, TestTextLogging) {
SetEnv("RAY_BACKEND_LOG_JSON", "0");
RayLog::StartRayLog("/tmp/gcs", RayLogLevel::INFO, /*log_filepath=*/"");
Expand Down
Loading