Skip to content

Commit

Permalink
fuzz: reduce log level when running under fuzz engine. (envoyproxy#4161)
Browse files Browse the repository at this point in the history
The ClusterFuzz stats indicated a lot of log spew, this is a structural
attempt to reduce it. We now run with logging off when under the engine,
but at ::info when running under bazel test. This can be further
overrides when debugging with -l to more verbose levels. The usual flow
is we download a repeater from the database and then reproduce with
logs.

There's still some log spam from libproto, will look into that
separately.

Risk Level: low
Testing: manual tests on CLI with different combinations of flags.

Signed-off-by: Harvey Tuch <htuch@google.com>
  • Loading branch information
htuch authored Aug 16, 2018
1 parent 7c04ac2 commit 132302c
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 6 deletions.
14 changes: 10 additions & 4 deletions test/fuzz/fuzz_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,27 @@
namespace Envoy {
namespace Fuzz {

void Runner::setupEnvironment(int argc, char** argv) {
spdlog::level::level_enum Runner::log_level_;

void Runner::setupEnvironment(int argc, char** argv, spdlog::level::level_enum default_log_level) {
Event::Libevent::Global::initialize();

TestEnvironment::initializeOptions(argc, argv);

static auto* lock = new Thread::MutexBasicLockable();
const auto environment_log_level = TestEnvironment::getOptions().logLevel();
Logger::Registry::initialize(std::min(environment_log_level, spdlog::level::info),
TestEnvironment::getOptions().logFormat(), *lock);
// We only override the default log level if it looks like we're debugging;
// otherwise the default environment log level might override the default and
// spew too much when running under a fuzz engine.
log_level_ =
environment_log_level <= spdlog::level::debug ? environment_log_level : default_log_level;
Logger::Registry::initialize(log_level_, TestEnvironment::getOptions().logFormat(), *lock);
}

} // namespace Fuzz
} // namespace Envoy

extern "C" int LLVMFuzzerInitialize(int* /*argc*/, char*** argv) {
Envoy::Fuzz::Runner::setupEnvironment(1, *argv);
Envoy::Fuzz::Runner::setupEnvironment(1, *argv, spdlog::level::off);
return 0;
}
12 changes: 11 additions & 1 deletion test/fuzz/fuzz_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Bring in DEFINE_PROTO_FUZZER definition as per
// https://github.com/google/libprotobuf-mutator#integrating-with-libfuzzer.
#include "libprotobuf_mutator/src/libfuzzer/libfuzzer_macro.h"
#include "spdlog/spdlog.h"

namespace Envoy {
namespace Fuzz {
Expand All @@ -17,8 +18,17 @@ class Runner {
* invoked in this environment.
* @param argc number of command-line args.
* @param argv array of command-line args.
* @param default_loglevel default log level (overridable with -l).
*/
static void setupEnvironment(int argc, char** argv);
static void setupEnvironment(int argc, char** argv, spdlog::level::level_enum default_log_level);

/**
* @return spdlog::level::level_enum the log level for the fuzzer.
*/
static spdlog::level::level_enum logLevel() { return log_level_; }

private:
static spdlog::level::level_enum log_level_;
};

} // namespace Fuzz
Expand Down
2 changes: 1 addition & 1 deletion test/fuzz/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ int main(int argc, char** argv) {
RELEASE_ASSERT(Envoy::Filesystem::directoryExists(corpus_path), "");
Envoy::test_corpus_ = Envoy::TestUtility::listFiles(corpus_path, true);
testing::InitGoogleTest(&argc, argv);
Envoy::Fuzz::Runner::setupEnvironment(argc, argv);
Envoy::Fuzz::Runner::setupEnvironment(argc, argv, spdlog::level::info);
return RUN_ALL_TESTS();
}
1 change: 1 addition & 0 deletions test/mocks/server/mocks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ MockOptions::MockOptions(const std::string& config_path) : config_path_(config_p
ON_CALL(*this, serviceClusterName()).WillByDefault(ReturnRef(service_cluster_name_));
ON_CALL(*this, serviceNodeName()).WillByDefault(ReturnRef(service_node_name_));
ON_CALL(*this, serviceZone()).WillByDefault(ReturnRef(service_zone_name_));
ON_CALL(*this, logLevel()).WillByDefault(Return(log_level_));
ON_CALL(*this, logPath()).WillByDefault(ReturnRef(log_path_));
ON_CALL(*this, maxStats()).WillByDefault(Return(1000));
ON_CALL(*this, statsOptions()).WillByDefault(ReturnRef(stats_options_));
Expand Down
1 change: 1 addition & 0 deletions test/mocks/server/mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class MockOptions : public Options {
std::string service_cluster_name_;
std::string service_node_name_;
std::string service_zone_name_;
spdlog::level::level_enum log_level_{spdlog::level::trace};
std::string log_path_;
Stats::StatsOptionsImpl stats_options_;
bool hot_restart_disabled_{};
Expand Down
1 change: 1 addition & 0 deletions test/server/config_validation/config_fuzz_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ DEFINE_PROTO_FUZZER(const envoy::config::bootstrap::v2::Bootstrap& input) {
bootstrap_file << input.DebugString();
options.config_path_ = bootstrap_path;
options.v2_config_only_ = true;
options.log_level_ = Fuzz::Runner::logLevel();

try {
validateConfig(options, Network::Address::InstanceConstSharedPtr(), component_factory);
Expand Down
1 change: 1 addition & 0 deletions test/server/server_fuzz_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ DEFINE_PROTO_FUZZER(const envoy::config::bootstrap::v2::Bootstrap& input) {
bootstrap_file << input.DebugString();
options.config_path_ = bootstrap_path;
options.v2_config_only_ = true;
options.log_level_ = Fuzz::Runner::logLevel();
}

try {
Expand Down

0 comments on commit 132302c

Please sign in to comment.