Skip to content

Commit

Permalink
Revert "http2: removes environment variable-triggered nghttp2 logging (
Browse files Browse the repository at this point in the history
…envoyproxy#34354)"

This reverts commit 14cd80f.

Signed-off-by: Yan Avlasov <yavlasov@google.com>
  • Loading branch information
yanavlasov committed Jun 25, 2024
1 parent 3456d51 commit 38478e3
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 1 deletion.
12 changes: 12 additions & 0 deletions source/common/http/http2/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ envoy_cc_library(
],
)

# Separate library for some nghttp2 setup stuff to avoid having tests take a
# dependency on everything in codec_lib.
envoy_cc_library(
name = "nghttp2_lib",
srcs = ["nghttp2.cc"],
hdrs = ["nghttp2.h"],
external_deps = ["nghttp2"],
deps = [
"//source/common/common:minimal_logger_lib",
],
)

envoy_cc_library(
name = "conn_pool_lib",
srcs = ["conn_pool.cc"],
Expand Down
35 changes: 35 additions & 0 deletions source/common/http/http2/nghttp2.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "source/common/http/http2/nghttp2.h"

#include "source/common/common/logger.h"

// nghttp2 fails to convey the POSIX ssize_t declaration
// that Microsoft declines to implement. Pick up a valid
// ssize_t declaration for win32 in our platform.h
#include "envoy/common/platform.h"

#include "nghttp2/nghttp2.h"

namespace Envoy {
namespace Http {
namespace Http2 {

void initializeNghttp2Logging() {
// When ENVOY_NGHTTP2_TRACE is set, we install a debug logger, to prevent nghttp2
// logging directly to stdout at -l trace.
nghttp2_set_debug_vprintf_callback([](const char* format, va_list args) {
if (std::getenv("ENVOY_NGHTTP2_TRACE") != nullptr) {
char buf[2048];
const int n = ::vsnprintf(buf, sizeof(buf), format, args);
// nghttp2 inserts new lines, but we also insert a new line in the ENVOY_LOG
// below, so avoid double \n.
if (n >= 1 && static_cast<size_t>(n) < sizeof(buf) && buf[n - 1] == '\n') {
buf[n - 1] = '\0';
}
ENVOY_LOG_TO_LOGGER(Logger::Registry::getLog(Logger::Id::http2), trace, "nghttp2: {}", buf);
}
});
}

} // namespace Http2
} // namespace Http
} // namespace Envoy
14 changes: 14 additions & 0 deletions source/common/http/http2/nghttp2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

namespace Envoy {
namespace Http {
namespace Http2 {

/**
* Setup nghttp2 trace-level logging for when debugging.
*/
void initializeNghttp2Logging();

} // namespace Http2
} // namespace Http
} // namespace Envoy
1 change: 1 addition & 0 deletions source/exe/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ envoy_cc_library(
deps = [
"//source/common/common:assert_lib",
"//source/common/event:libevent_lib",
"//source/common/http/http2:nghttp2_lib",
"//source/common/network/dns_resolver:dns_factory_util_lib",
"//source/server:proto_descriptors_lib",
],
Expand Down
2 changes: 2 additions & 0 deletions source/exe/process_wide.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "source/common/common/assert.h"
#include "source/common/event/libevent.h"
#include "source/common/http/http2/nghttp2.h"
#include "source/server/proto_descriptors.h"

namespace Envoy {
Expand Down Expand Up @@ -37,6 +38,7 @@ ProcessWide::ProcessWide(bool validate_proto_descriptors) {
#else
UNREFERENCED_PARAMETER(validate_proto_descriptors);
#endif
Http::Http2::initializeNghttp2Logging();

// We do not initialize Google gRPC here -- we instead instantiate
// Grpc::GoogleGrpcContext in MainCommon immediately after instantiating
Expand Down
2 changes: 1 addition & 1 deletion test/per_file_coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ declare -a KNOWN_LOW_COVERAGE=(
"source/common/crypto:95.5"
"source/common/event:95.1" # Emulated edge events guards don't report LCOV
"source/common/filesystem/posix:96.2" # FileReadToEndNotReadable fails in some env; createPath can't test all failure branches.
"source/common/http/http2:96.0"
"source/common/http/http2:95.9"
"source/common/json:94.6"
"source/common/matcher:94.4"
"source/common/memory:73.6" # tcmalloc code path is not enabled in coverage build, only gperf tcmalloc, see PR#32589
Expand Down

0 comments on commit 38478e3

Please sign in to comment.