Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
65 changes: 58 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,54 @@ find_package(ZLIB REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(Threads)
find_package(Cares REQUIRED)
find_package(Glog REQUIRED)

# Propagate glog's required compile definition to all proxygen targets.
# glog 0.7+ requires GLOG_USE_GLOG_EXPORT but since glog::glog is linked
# PRIVATE on the monolithic library, OBJECT libraries don't inherit it.
get_target_property(_glog_defs glog::glog INTERFACE_COMPILE_DEFINITIONS)
if(_glog_defs)
add_compile_definitions(${_glog_defs})
# Set install-dir defaults before any install() rule references them. The
# matching defaults below (LIB_INSTALL_DIR / CMAKE_INSTALL_DIR) stay where they
# are since nothing earlier in this file consumes them.
if (NOT DEFINED INCLUDE_INSTALL_DIR)
set(INCLUDE_INSTALL_DIR "include")
endif()

# Logging backend selection. Default is glog (preserves historical behavior);
# downstream builds can opt in to folly::xlog or fully disable logging.
# Interpolated into lib/utils/proxygen-config.h.in as
# `#define PRX_LOGGING_@PROXYGEN_LOGGING_BACKEND@ 1` and consumed from
# proxygen/lib/utils/LogShim.h.
set(PROXYGEN_LOGGING_BACKEND "GLOG" CACHE STRING
"Logging backend. Valid choices: GLOG, XLOG, DISABLED")
set_property(CACHE PROXYGEN_LOGGING_BACKEND PROPERTY STRINGS GLOG XLOG DISABLED)
if(NOT PROXYGEN_LOGGING_BACKEND MATCHES "^(GLOG|XLOG|DISABLED)$")
message(FATAL_ERROR
"PROXYGEN_LOGGING_BACKEND must be one of: GLOG, XLOG, DISABLED "
"(got '${PROXYGEN_LOGGING_BACKEND}')")
endif()

# Glog is only required in the default GLOG backend; XLOG routes through
# folly::xlog and DISABLED strips logging entirely.
if(PROXYGEN_LOGGING_BACKEND STREQUAL "GLOG")
find_package(Glog REQUIRED)

# Propagate glog's required compile definition to all proxygen targets.
# glog 0.7+ requires GLOG_USE_GLOG_EXPORT but since glog::glog is linked
# PRIVATE on the monolithic library, OBJECT libraries don't inherit it.
get_target_property(_glog_defs glog::glog INTERFACE_COMPILE_DEFINITIONS)
if(_glog_defs)
add_compile_definitions(${_glog_defs})
endif()
endif()

# Generate <proxygen/proxygen-config.h> for this build. The template
# interpolates PROXYGEN_LOGGING_BACKEND into a
# `#define PRX_LOGGING_<BACKEND> 1`, which proxygen/lib/utils/LogShim.h
# consumes to pick the macro implementations.
# Generated into PROXYGEN_GENERATED_ROOT which is already on every proxygen
# target's include path (see ProxygenFunctions.cmake).
configure_file(
proxygen/lib/utils/proxygen-config.h.in
${PROXYGEN_GENERATED_ROOT}/proxygen/proxygen-config.h)
install(FILES ${PROXYGEN_GENERATED_ROOT}/proxygen/proxygen-config.h
DESTINATION ${INCLUDE_INSTALL_DIR}/proxygen/)

list(APPEND
_PROXYGEN_COMMON_COMPILE_OPTIONS
-Wall
Expand Down Expand Up @@ -173,6 +211,19 @@ set(PROXYGEN_DIR ${CMAKE_CURRENT_SOURCE_DIR}/proxygen)

add_subdirectory(proxygen)

# The generated lib/utils/CMakeLists.txt lists both Folly::folly_glog and
# Folly::folly_logging_logging as unconditional INTERFACE deps for the log
# shim. Narrow that to match the selected backend so downstream code doesn't
# pull in libraries it isn't actually using.
if(PROXYGEN_LOGGING_BACKEND STREQUAL "XLOG")
set_target_properties(proxygen_utils_log_shim PROPERTIES
INTERFACE_LINK_LIBRARIES
"proxygen_utils_config;Folly::folly_logging_logging")
elseif(PROXYGEN_LOGGING_BACKEND STREQUAL "DISABLED")
set_target_properties(proxygen_utils_log_shim PROPERTIES
INTERFACE_LINK_LIBRARIES "proxygen_utils_config")
endif()

# Resolve deferred dependencies for granular libraries
# (monolithic proxygen target is manually maintained in proxygen/lib/CMakeLists.txt)
proxygen_resolve_deferred_dependencies()
Expand Down
6 changes: 6 additions & 0 deletions build/fbcode_builder/manifests/snappy
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ subdir = snappy-27ab5f7f518430a021239bc26a5b2fd64affbc7b
[cmake.defines]
SNAPPY_BUILD_TESTS = OFF
SNAPPY_BUILD_BENCHMARKS = OFF
# folly's Compression.cpp dynamic_casts snappy::Source/Sink and needs their
# typeinfo. Snappy hardcodes -fno-rtti in CMAKE_CXX_FLAGS; override via the
# per-config flags variable, which is appended after (last -f wins in gcc).
CMAKE_CXX_FLAGS_RELWITHDEBINFO = -O2 -g -DNDEBUG -frtti
CMAKE_CXX_FLAGS_RELEASE = -O3 -DNDEBUG -frtti
CMAKE_CXX_FLAGS_DEBUG = -g -frtti

# Avoid problems like `relocation R_X86_64_PC32 against symbol` on ELF systems
# when linking rocksdb, which builds PIC even when building a static lib
Expand Down
35 changes: 18 additions & 17 deletions proxygen/httpclient/samples/H3Datagram/H3DatagramClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <proxygen/httpserver/samples/hq/InsecureVerifierDangerousDoNotUseInProduction.h>
#include <proxygen/lib/transport/ConnectUDPUtils.h>
#include <proxygen/lib/transport/H3DatagramAsyncSocket.h>
#include <proxygen/lib/utils/LogShim.h>

using namespace folly;
using namespace proxygen;
Expand Down Expand Up @@ -65,12 +66,12 @@ class DatagramClient
}

void start() {
CHECK(evb_->isInEventBaseThread());
PRX_CHECK(evb_->isInEventBaseThread());
try {
socket_.connect(SocketAddress(FLAGS_proxy_host, FLAGS_proxy_port));
} catch (const std::system_error& e) {
LOG(ERROR) << "Failed to connect to " << FLAGS_proxy_host << ":"
<< FLAGS_proxy_port << ": " << e.what();
PRX_LOG(ERROR) << "Failed to connect to " << FLAGS_proxy_host << ":"
<< FLAGS_proxy_port << ": " << e.what();
return;
}
socket_.resumeRead(this);
Expand All @@ -79,7 +80,7 @@ class DatagramClient
}

void shutdown() {
CHECK(evb_->isInEventBaseThread());
PRX_CHECK(evb_->isInEventBaseThread());
socket_.pauseRead();
socket_.close();
closing_ = true;
Expand All @@ -96,11 +97,11 @@ class DatagramClient
}

virtual void writePing(std::unique_ptr<folly::IOBuf> buf) {
VLOG(2) << "Writing Datagram";
PRX_VLOG(2) << "Writing Datagram";
auto res =
socket_.write(SocketAddress(FLAGS_proxy_host, FLAGS_proxy_port), buf);
if (res < 0) {
LOG(ERROR) << "Failure to write: errno=" << errno;
PRX_LOG(ERROR) << "Failure to write: errno=" << errno;
}
}

Expand All @@ -114,38 +115,38 @@ class DatagramClient
bool truncated,
OnDataAvailableParams) noexcept override {
++pongRecvd_;
VLOG(4) << "Read " << len << " bytes (trun:" << truncated << ") from "
<< client.describe() << " - " << std::string(buf_.data(), len);
PRX_VLOG(4) << "Read " << len << " bytes (trun:" << truncated << ") from "
<< client.describe() << " - " << std::string(buf_.data(), len);
auto datagramString = std::string(buf_.data(), len);
auto datagramInt = folly::tryTo<uint16_t>(datagramString);
if (!datagramInt.hasValue()) {
VLOG(2) << "Received Datagram without Integer value. Stopping. len="
<< datagramString.length();
PRX_VLOG(2) << "Received Datagram without Integer value. Stopping. len="
<< datagramString.length();
return;
}
VLOG(2) << "Received Datagram with Integer value (" << (int)*datagramInt
<< ")";
PRX_VLOG(2) << "Received Datagram with Integer value (" << (int)*datagramInt
<< ")";
if (*datagramInt >= std::numeric_limits<uint16_t>::max()) {
VLOG(2) << "Received Datagram with large Integer value. Stopping";
PRX_VLOG(2) << "Received Datagram with large Integer value. Stopping";
return;
}
VLOG(2) << "Sending Datagram with Integer value ("
<< (int)(*datagramInt + 1) << ")";
PRX_VLOG(2) << "Sending Datagram with Integer value ("
<< (int)(*datagramInt + 1) << ")";
n_ = (int)(*datagramInt + 1);

scheduleTimeout(1000);
}

void onReadError(const folly::AsyncSocketException& ex) noexcept override {
LOG(ERROR) << ex.what();
PRX_LOG(ERROR) << ex.what();
}

void onReadClosed() noexcept override {
shutdown();
}

void timeoutExpired() noexcept override {
LOG(INFO) << "Timeout expired";
PRX_LOG(INFO) << "Timeout expired";
if (!closing_) {
sendPing();
}
Expand Down
33 changes: 17 additions & 16 deletions proxygen/httpclient/samples/curl/CurlClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <proxygen/lib/http/HTTPMessage.h>
#include <proxygen/lib/http/codec/HTTP2Codec.h>
#include <proxygen/lib/http/session/HTTPUpstreamSession.h>
#include <proxygen/lib/utils/LogShim.h>

using namespace folly;
using namespace proxygen;
Expand Down Expand Up @@ -130,10 +131,10 @@ void CurlClient::sslHandshakeFollowup(HTTPUpstreamSession* session) noexcept {
unsigned nextProtoLength = 0;
sslSocket->getSelectedNextProtocol(&nextProto, &nextProtoLength);
if (nextProto) {
VLOG(1) << "Client selected next protocol "
<< string((const char*)nextProto, nextProtoLength);
PRX_VLOG(1) << "Client selected next protocol "
<< string((const char*)nextProto, nextProtoLength);
} else {
VLOG(1) << "Client did not select a next protocol";
PRX_VLOG(1) << "Client did not select a next protocol";
}

// Note: This ssl session can be used by defining a member and setting
Expand Down Expand Up @@ -181,7 +182,7 @@ void CurlClient::setupHeaders() {
}

void CurlClient::sendRequest(HTTPTransaction* txn) {
LOG_IF(INFO, loggingEnabled_)
PRX_LOG_IF(INFO, loggingEnabled_)
<< fmt::format("Sending request for {}", url_.getUrl());
txn_ = txn;
setupHeaders();
Expand All @@ -199,7 +200,7 @@ void CurlClient::sendRequest(HTTPTransaction* txn) {

void CurlClient::sendBodyFromFile() {
const uint16_t kReadSize = 4096;
CHECK(inputFile_);
PRX_CHECK(inputFile_);
// Reading from the file by chunks
// Important note: It's pretty bad to call a blocking i/o function like
// ifstream::read() in an eventloop - but for the sake of this simple
Expand Down Expand Up @@ -231,7 +232,7 @@ void CurlClient::printMessageImpl(proxygen::HTTPMessage* msg,
}

void CurlClient::connectError(const folly::AsyncSocketException& ex) {
LOG_IF(ERROR, loggingEnabled_)
PRX_LOG_IF(ERROR, loggingEnabled_)
<< "Coudln't connect to " << url_.getHostAndPort() << ":" << ex.what();
}

Expand All @@ -258,7 +259,7 @@ void CurlClient::onBody(std::unique_ptr<folly::IOBuf> chain) noexcept {
if (!loggingEnabled_) {
return;
}
CHECK(outputStream_);
PRX_CHECK(outputStream_);
if (chain) {
const IOBuf* p = chain.get();
do {
Expand All @@ -270,11 +271,11 @@ void CurlClient::onBody(std::unique_ptr<folly::IOBuf> chain) noexcept {
}

void CurlClient::onTrailers(std::unique_ptr<HTTPHeaders>) noexcept {
LOG_IF(INFO, loggingEnabled_) << "Discarding trailers";
PRX_LOG_IF(INFO, loggingEnabled_) << "Discarding trailers";
}

void CurlClient::onEOM() noexcept {
LOG_IF(INFO, loggingEnabled_)
PRX_LOG_IF(INFO, loggingEnabled_)
<< fmt::format("Got EOM for {}. Txn Time= {} ms",
url_.getUrl(),
std::chrono::duration_cast<std::chrono::milliseconds>(
Expand All @@ -286,20 +287,20 @@ void CurlClient::onEOM() noexcept {
}

void CurlClient::onUpgrade(UpgradeProtocol) noexcept {
LOG_IF(INFO, loggingEnabled_) << "Discarding upgrade protocol";
PRX_LOG_IF(INFO, loggingEnabled_) << "Discarding upgrade protocol";
}

void CurlClient::onError(const HTTPException& error) noexcept {
LOG_IF(ERROR, loggingEnabled_) << "An error occurred: " << error.what();
PRX_LOG_IF(ERROR, loggingEnabled_) << "An error occurred: " << error.what();
}

void CurlClient::onEgressPaused() noexcept {
VLOG_IF(1, loggingEnabled_) << "Egress paused";
PRX_VLOG_IF(1, loggingEnabled_) << "Egress paused";
egressPaused_ = true;
}

void CurlClient::onEgressResumed() noexcept {
VLOG_IF(1, loggingEnabled_) << "Egress resumed";
PRX_VLOG_IF(1, loggingEnabled_) << "Egress resumed";
egressPaused_ = false;
if (inputFile_) {
sendBodyFromFile();
Expand All @@ -325,12 +326,12 @@ const string& CurlClient::getServerName() const {
// CurlPushHandler methods
void CurlClient::CurlPushHandler::setTransaction(
proxygen::HTTPTransaction* txn) noexcept {
LOG_IF(INFO, parent_->loggingEnabled_) << "Received pushed transaction";
PRX_LOG_IF(INFO, parent_->loggingEnabled_) << "Received pushed transaction";
pushedTxn_ = txn;
}

void CurlClient::CurlPushHandler::detachTransaction() noexcept {
LOG_IF(INFO, parent_->loggingEnabled_) << "Detached pushed transaction";
PRX_LOG_IF(INFO, parent_->loggingEnabled_) << "Detached pushed transaction";
}

void CurlClient::CurlPushHandler::onHeadersComplete(
Expand All @@ -351,7 +352,7 @@ void CurlClient::CurlPushHandler::onBody(
}

void CurlClient::CurlPushHandler::onEOM() noexcept {
LOG_IF(INFO, parent_->loggingEnabled_) << "Got PushTxn EOM";
PRX_LOG_IF(INFO, parent_->loggingEnabled_) << "Got PushTxn EOM";
}

void CurlClient::CurlPushHandler::onError(
Expand Down
9 changes: 5 additions & 4 deletions proxygen/httpclient/samples/curl/CurlClientMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <folly/portability/GFlags.h>
#include <proxygen/httpclient/samples/curl/CurlClient.h>
#include <proxygen/lib/http/HTTPConnector.h>
#include <proxygen/lib/utils/LogShim.h>

using namespace CurlService;
using namespace folly;
Expand Down Expand Up @@ -63,7 +64,7 @@ int main(int argc, char* argv[]) {

auto httpMethod = stringToMethod(FLAGS_http_method);
if (!httpMethod) {
LOG(ERROR) << "Unsupported http_method=" << FLAGS_http_method;
PRX_LOG(ERROR) << "Unsupported http_method=" << FLAGS_http_method;
return EXIT_FAILURE;
}

Expand All @@ -72,8 +73,8 @@ int main(int argc, char* argv[]) {
File f(FLAGS_input_filename);
(void)f;
} catch (const std::system_error& se) {
LOG(ERROR) << "Couldn't open file for POST method";
LOG(ERROR) << se.what();
PRX_LOG(ERROR) << "Couldn't open file for POST method";
PRX_LOG(ERROR) << se.what();
return EXIT_FAILURE;
}
}
Expand All @@ -97,7 +98,7 @@ int main(int argc, char* argv[]) {
} else {
addr = SocketAddress(url.getHost(), url.getPort(), true);
}
LOG(INFO) << "Trying to connect to " << addr;
PRX_LOG(INFO) << "Trying to connect to " << addr;

HTTPConnector connector(
&curlClient,
Expand Down
Loading
Loading