Skip to content

Commit

Permalink
Make the fix_format and check_format scripts work on Nighthawk code (#…
Browse files Browse the repository at this point in the history
…916)

Fixes #913

Direct changes:
- Modified config.yaml to not exclude the current directory, which was excluding all of NH
- Overrode some settings in config.yaml to move past some code changes
    - Filed #914 and #915 to address these overrides in the future
- Moved include_dir_order from check_format.sh over to the config.yaml where it now needs to live.

Also ran the format script to fix all current code formatting errors.

Signed-off-by: Nathan Perry <[email protected]>
  • Loading branch information
dubious90 authored Sep 23, 2022
1 parent 50dba51 commit 73a7bf6
Show file tree
Hide file tree
Showing 15 changed files with 183 additions and 109 deletions.
7 changes: 4 additions & 3 deletions source/adaptive_load/adaptive_load_controller_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ absl::StatusOr<BenchmarkResult> AdaptiveLoadControllerImpl::PerformAndAnalyzeNig
command_line_options);
Envoy::SystemTime end_time = time_source_.systemTime();
if (!nighthawk_response_or.ok()) {
ENVOY_LOG_MISC(error, "Nighthawk Service error: {}: {}", nighthawk_response_or.status().raw_code(),
ENVOY_LOG_MISC(error, "Nighthawk Service error: {}: {}",
nighthawk_response_or.status().raw_code(),
nighthawk_response_or.status().message());
return nighthawk_response_or.status();
}
Expand All @@ -155,8 +156,8 @@ absl::StatusOr<BenchmarkResult> AdaptiveLoadControllerImpl::PerformAndAnalyzeNig
metrics_evaluator_.AnalyzeNighthawkBenchmark(nighthawk_response, spec,
name_to_custom_plugin_map);
if (!benchmark_result_or.ok()) {
ENVOY_LOG_MISC(error, "Benchmark scoring error: {}: {}", benchmark_result_or.status().raw_code(),
benchmark_result_or.status().message());
ENVOY_LOG_MISC(error, "Benchmark scoring error: {}: {}",
benchmark_result_or.status().raw_code(), benchmark_result_or.status().message());
return benchmark_result_or.status();
}
BenchmarkResult benchmark_result = benchmark_result_or.value();
Expand Down
9 changes: 5 additions & 4 deletions source/client/output_formatter_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ CsvOutputFormatterImpl::formatProto(const nighthawk::client::Output& output) con
}
std::string s_percentile = fmt::format("{:.{}g}", p, 8);
ss << fmt::format("{},{},{},{}", s_percentile, percentile.count(),
Envoy::Protobuf::util::TimeUtil::DurationToMicroseconds(percentile.duration()),
Envoy::Protobuf::util::TimeUtil::DurationToMicroseconds(
percentile.duration()),
percentile.has_duration()
? formatProtoDuration(percentile.duration())
: fmt::format("{}", static_cast<int64_t>(percentile.raw_value())),
Expand All @@ -210,7 +211,7 @@ CsvOutputFormatterImpl::formatProto(const nighthawk::client::Output& output) con
});
ss << std::endl;
}

// Counters
ss << fmt::format("{},{},{}", "Counter", "Value", "Per second") << std::endl;
for (const nighthawk::client::Counter& counter : result.counters()) {
Expand All @@ -226,8 +227,8 @@ CsvOutputFormatterImpl::formatProto(const nighthawk::client::Output& output) con
return ss.str();
}

std::string CsvOutputFormatterImpl::formatProtoDuration(
const Envoy::ProtobufWkt::Duration& duration) const {
std::string
CsvOutputFormatterImpl::formatProtoDuration(const Envoy::ProtobufWkt::Duration& duration) const {
int64_t microseconds = Envoy::Protobuf::util::TimeUtil::DurationToMicroseconds(duration);
return fmt::format("{}s {:03}ms {:03}us", (microseconds % 1'000'000'000) / 1'000'000,
(microseconds % 1'000'000) / 1'000, microseconds % 1'000);
Expand Down
11 changes: 7 additions & 4 deletions source/client/output_formatter_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,20 @@ class CsvOutputFormatterImpl : public OutputFormatterImpl {
/**
* Return name associated with the specified stat id.
*
* @param stat_id id that represents a specific stat. Example: "benchmark_http_client.queue_to_connect"
* @param stat_id id that represents a specific stat. Example:
* "benchmark_http_client.queue_to_connect"
* @return name or description (as string) associated with the specified stat id
*/
static std::string statIdtoFriendlyStatName(absl::string_view stat_id);

private:
/**
* Transforms an Envoy::ProtobufWkt::Duration to a human-readable string in the format of "{}s {:03}ms {:03}us".
* Transforms an Envoy::ProtobufWkt::Duration to a human-readable string in the format of "{}s
* {:03}ms {:03}us".
*
* @param duration the Envoy::ProtobufWkt::Duration& to transform
* @return the human-readable string representation of the specified duration. Example: "11s 033ms 190us"
* @return the human-readable string representation of the specified duration. Example: "11s 033ms
* 190us"
*/
std::string formatProtoDuration(const Envoy::ProtobufWkt::Duration& duration) const;
};
Expand Down Expand Up @@ -167,4 +170,4 @@ class FortioPedanticOutputFormatterImpl : public FortioOutputFormatterImpl {
};

} // namespace Client
} // namespace Nighthawk
} // namespace Nighthawk
173 changes: 122 additions & 51 deletions source/client/process_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,59 +103,107 @@ class BootstrapFactory : public Envoy::Logger::Loggable<Envoy::Logger::Id::main>
// Implementation of Envoy::Server::Instance. Only methods used by Envoy's code
// when Nighthawk is running are implemented.
class NighthawkServerInstance : public Envoy::Server::Instance {
public:
NighthawkServerInstance(Envoy::Server::Admin& admin, Envoy::Api::Api& api, Envoy::Event::Dispatcher& dispatcher,
public:
NighthawkServerInstance(Envoy::Server::Admin& admin, Envoy::Api::Api& api,
Envoy::Event::Dispatcher& dispatcher,
Envoy::AccessLog::AccessLogManager& log_manager,
Envoy::Server::Options& options,
Envoy::Runtime::Loader& runtime, Envoy::Singleton::Manager& singleton_manager, Envoy::ThreadLocal::Instance& tls,
Envoy::LocalInfo::LocalInfo& local_info) :
admin_(admin), api_(api), dispatcher_(dispatcher), log_manager_(log_manager),
options_(options),
runtime_(runtime), singleton_manager_(singleton_manager), tls_(tls), local_info_(local_info) {}
Envoy::Server::Options& options, Envoy::Runtime::Loader& runtime,
Envoy::Singleton::Manager& singleton_manager,
Envoy::ThreadLocal::Instance& tls,
Envoy::LocalInfo::LocalInfo& local_info)
: admin_(admin), api_(api), dispatcher_(dispatcher), log_manager_(log_manager),
options_(options), runtime_(runtime), singleton_manager_(singleton_manager), tls_(tls),
local_info_(local_info) {}

Envoy::Server::Admin& admin() override { return admin_; }
Envoy::Api::Api& api() override { return api_; }
Envoy::Upstream::ClusterManager& clusterManager() override { PANIC("NighthawkServerInstance::clusterManager not implemented"); }
Envoy::Upstream::ClusterManager& clusterManager() override {
PANIC("NighthawkServerInstance::clusterManager not implemented");
}
const Envoy::Upstream::ClusterManager& clusterManager() const override {
PANIC("NighthawkServerInstance::clusterManager not implemented");
}
Envoy::Ssl::ContextManager& sslContextManager() override { PANIC("NighthawkServerInstance::sslContextManager not implemented"); }
Envoy::Ssl::ContextManager& sslContextManager() override {
PANIC("NighthawkServerInstance::sslContextManager not implemented");
}
Envoy::Event::Dispatcher& dispatcher() override { return dispatcher_; }
Envoy::Network::DnsResolverSharedPtr dnsResolver() override { PANIC("NighthawkServerInstance::dnsResolver not implemented"); }
void drainListeners() override { PANIC("NighthawkServerInstance::drainListeners not implemented"); }
Envoy::Server::DrainManager& drainManager() override { PANIC("NighthawkServerInstance::drainManager not implemented"); }
Envoy::Network::DnsResolverSharedPtr dnsResolver() override {
PANIC("NighthawkServerInstance::dnsResolver not implemented");
}
void drainListeners() override {
PANIC("NighthawkServerInstance::drainListeners not implemented");
}
Envoy::Server::DrainManager& drainManager() override {
PANIC("NighthawkServerInstance::drainManager not implemented");
}
Envoy::AccessLog::AccessLogManager& accessLogManager() override { return log_manager_; }
void failHealthcheck(bool) override { PANIC("NighthawkServerInstance::failHealthcheck not implemented"); }
bool healthCheckFailed() override { PANIC("NighthawkServerInstance::healthCheckFailed not implemented"); }
Envoy::Server::HotRestart& hotRestart() override { PANIC("NighthawkServerInstance::hotRestart not implemented"); }
Envoy::Init::Manager& initManager() override { PANIC("NighthawkServerInstance::initManager not implemented"); }
Envoy::Server::ListenerManager& listenerManager() override { PANIC("NighthawkServerInstance::listenerManager not implemented"); }
Envoy::MutexTracer* mutexTracer() override { PANIC("NighthawkServerInstance::mutexTracer not implemented"); }
Envoy::Server::OverloadManager& overloadManager() override { PANIC("NighthawkServerInstance::overloadManager not implemented"); }
Envoy::Secret::SecretManager& secretManager() override { PANIC("NighthawkServerInstance::secretManager not implemented"); }
void failHealthcheck(bool) override {
PANIC("NighthawkServerInstance::failHealthcheck not implemented");
}
bool healthCheckFailed() override {
PANIC("NighthawkServerInstance::healthCheckFailed not implemented");
}
Envoy::Server::HotRestart& hotRestart() override {
PANIC("NighthawkServerInstance::hotRestart not implemented");
}
Envoy::Init::Manager& initManager() override {
PANIC("NighthawkServerInstance::initManager not implemented");
}
Envoy::Server::ListenerManager& listenerManager() override {
PANIC("NighthawkServerInstance::listenerManager not implemented");
}
Envoy::MutexTracer* mutexTracer() override {
PANIC("NighthawkServerInstance::mutexTracer not implemented");
}
Envoy::Server::OverloadManager& overloadManager() override {
PANIC("NighthawkServerInstance::overloadManager not implemented");
}
Envoy::Secret::SecretManager& secretManager() override {
PANIC("NighthawkServerInstance::secretManager not implemented");
}
const Envoy::Server::Options& options() override { return options_; }
Envoy::Runtime::Loader& runtime() override { return runtime_; }
Envoy::Server::ServerLifecycleNotifier& lifecycleNotifier() override { PANIC("NighthawkServerInstance::lifecycleNotifier not implemented"); }
Envoy::Server::ServerLifecycleNotifier& lifecycleNotifier() override {
PANIC("NighthawkServerInstance::lifecycleNotifier not implemented");
}
void shutdown() override { PANIC("NighthawkServerInstance::shutdown not implemented"); }
bool isShutdown() override { PANIC("NighthawkServerInstance::isShutdown not implemented"); }
void shutdownAdmin() override { PANIC("NighthawkServerInstance::shutdownAdmin not implemented"); }
Envoy::Singleton::Manager& singletonManager() override { return singleton_manager_; }
time_t startTimeCurrentEpoch() override { PANIC("NighthawkServerInstance::startTimeCurrentEpoch not implemented"); }
time_t startTimeFirstEpoch() override { PANIC("NighthawkServerInstance::startTimeFirstEpoch not implemented"); }
time_t startTimeCurrentEpoch() override {
PANIC("NighthawkServerInstance::startTimeCurrentEpoch not implemented");
}
time_t startTimeFirstEpoch() override {
PANIC("NighthawkServerInstance::startTimeFirstEpoch not implemented");
}
Envoy::Stats::Store& stats() override { PANIC("NighthawkServerInstance::stats not implemented"); }
Envoy::Grpc::Context& grpcContext() override { PANIC("NighthawkServerInstance::grpcContext not implemented"); }
Envoy::Http::Context& httpContext() override { PANIC("NighthawkServerInstance::httpContext not implemented"); }
Envoy::Router::Context& routerContext() override { PANIC("NighthawkServerInstance::routerContext not implemented"); }
Envoy::ProcessContextOptRef processContext() override { PANIC("NighthawkServerInstance::processContext not implemented"); }
Envoy::Grpc::Context& grpcContext() override {
PANIC("NighthawkServerInstance::grpcContext not implemented");
}
Envoy::Http::Context& httpContext() override {
PANIC("NighthawkServerInstance::httpContext not implemented");
}
Envoy::Router::Context& routerContext() override {
PANIC("NighthawkServerInstance::routerContext not implemented");
}
Envoy::ProcessContextOptRef processContext() override {
PANIC("NighthawkServerInstance::processContext not implemented");
}
Envoy::ThreadLocal::Instance& threadLocal() override { return tls_; }
Envoy::LocalInfo::LocalInfo& localInfo() const override { return local_info_; }
Envoy::TimeSource& timeSource() override { PANIC("NighthawkServerInstance::timeSource not implemented"); }
Envoy::TimeSource& timeSource() override {
PANIC("NighthawkServerInstance::timeSource not implemented");
}
void flushStats() override { PANIC("NighthawkServerInstance::flushStats not implemented"); }
Envoy::ProtobufMessage::ValidationContext& messageValidationContext() override {
PANIC("NighthawkServerInstance::messageValidationContext not implemented");
}
Envoy::Server::Configuration::StatsConfig& statsConfig() override { PANIC("NighthawkServerInstance::statsConfig not implemented"); }
envoy::config::bootstrap::v3::Bootstrap& bootstrap() override { PANIC("NighthawkServerInstance::bootstrap not implemented"); }
Envoy::Server::Configuration::StatsConfig& statsConfig() override {
PANIC("NighthawkServerInstance::statsConfig not implemented");
}
envoy::config::bootstrap::v3::Bootstrap& bootstrap() override {
PANIC("NighthawkServerInstance::bootstrap not implemented");
}
Envoy::Server::Configuration::ServerFactoryContext& serverFactoryContext() override {
PANIC("NighthawkServerInstance::serverFactoryContext not implemented");
}
Expand All @@ -166,12 +214,14 @@ class NighthawkServerInstance : public Envoy::Server::Instance {
void setDefaultTracingConfig(const envoy::config::trace::v3::Tracing&) override {
PANIC("NighthawkServerInstance::setDefaultTracingConfig not implemented");
}
bool enableReusePortDefault() override { PANIC("NighthawkServerInstance::enableReusePortDefault not implemented"); }
bool enableReusePortDefault() override {
PANIC("NighthawkServerInstance::enableReusePortDefault not implemented");
}
void setSinkPredicates(std::unique_ptr<Envoy::Stats::SinkPredicates>&&) override {
PANIC("NighthawkServerInstance::setSinkPredicates not implemented");
}

private:
private:
Envoy::Server::Admin& admin_;
Envoy::Api::Api& api_;
Envoy::Event::Dispatcher& dispatcher_;
Expand All @@ -181,12 +231,11 @@ class NighthawkServerInstance : public Envoy::Server::Instance {
Envoy::Singleton::Manager& singleton_manager_;
Envoy::ThreadLocal::Instance& tls_;
Envoy::LocalInfo::LocalInfo& local_info_;

};

// Implementation of Envoy::Server::Configuration::ServerFactoryContext.
class NighthawkServerFactoryContext : public Envoy::Server::Configuration::ServerFactoryContext {
public:
public:
NighthawkServerFactoryContext(Envoy::Server::Instance& server) : server_(server) {}

const Envoy::Server::Options& options() override { return server_.options(); };
Expand All @@ -207,46 +256,66 @@ class NighthawkServerFactoryContext : public Envoy::Server::Configuration::Serve
return Envoy::ProtobufMessage::getStrictValidationVisitor();
};

Envoy::Stats::Scope& scope() override { PANIC("NighthawkServerFactoryContext::scope not implemented"); };
Envoy::Stats::Scope& scope() override {
PANIC("NighthawkServerFactoryContext::scope not implemented");
};

Envoy::Stats::Scope& serverScope() override { PANIC("NighthawkServerFactoryContext::serverScope not implemented"); };
Envoy::Stats::Scope& serverScope() override {
PANIC("NighthawkServerFactoryContext::serverScope not implemented");
};

Envoy::ThreadLocal::SlotAllocator& threadLocal() override { return server_.threadLocal(); }

Envoy::Upstream::ClusterManager& clusterManager() override { PANIC("NighthawkServerFactoryContext::clusterManager not implemented"); };
Envoy::Upstream::ClusterManager& clusterManager() override {
PANIC("NighthawkServerFactoryContext::clusterManager not implemented");
};

Envoy::ProtobufMessage::ValidationContext& messageValidationContext() override {
PANIC("NighthawkServerFactoryContext::messageValidationContext not implemented");
};

Envoy::TimeSource& timeSource() override { PANIC("NighthawkServerFactoryContext::timeSource not implemented"); };
Envoy::TimeSource& timeSource() override {
PANIC("NighthawkServerFactoryContext::timeSource not implemented");
};

Envoy::AccessLog::AccessLogManager& accessLogManager() override { return server_.accessLogManager(); }
Envoy::AccessLog::AccessLogManager& accessLogManager() override {
return server_.accessLogManager();
}

Envoy::Server::ServerLifecycleNotifier& lifecycleNotifier() override {
PANIC("NighthawkServerFactoryContext::lifecycleNotifier not implemented");
};

Envoy::Init::Manager& initManager() override { PANIC("NighthawkServerFactoryContext::initManager not implemented"); };
Envoy::Init::Manager& initManager() override {
PANIC("NighthawkServerFactoryContext::initManager not implemented");
};

Envoy::Grpc::Context& grpcContext() override { PANIC("NighthawkServerFactoryContext::grpcContext not implemented"); };
Envoy::Grpc::Context& grpcContext() override {
PANIC("NighthawkServerFactoryContext::grpcContext not implemented");
};

Envoy::Router::Context& routerContext() override { PANIC("NighthawkServerFactoryContext::routerContext not implemented"); };
Envoy::Router::Context& routerContext() override {
PANIC("NighthawkServerFactoryContext::routerContext not implemented");
};

Envoy::Server::DrainManager& drainManager() override { PANIC("NighthawkServerFactoryContext::drainManager not implemented"); };
Envoy::Server::DrainManager& drainManager() override {
PANIC("NighthawkServerFactoryContext::drainManager not implemented");
};

Envoy::Server::Configuration::StatsConfig& statsConfig() override { PANIC("NighthawkServerFactoryContext::statsConfig not implemented"); }
Envoy::Server::Configuration::StatsConfig& statsConfig() override {
PANIC("NighthawkServerFactoryContext::statsConfig not implemented");
}

envoy::config::bootstrap::v3::Bootstrap& bootstrap() override { PANIC("NighthawkServerFactoryContext::bootstrap not implemented"); }
envoy::config::bootstrap::v3::Bootstrap& bootstrap() override {
PANIC("NighthawkServerFactoryContext::bootstrap not implemented");
}

private:
private:
Envoy::Server::Instance& server_;
};

// Disables the hot restart Envoy functionality.
std::string HotRestartDisabled(bool) {
return "hot restart is disabled";
}
std::string HotRestartDisabled(bool) { return "hot restart is disabled"; }

} // namespace

Expand Down Expand Up @@ -622,7 +691,9 @@ bool ProcessImpl::runInternal(OutputCollector& collector, const UriPtr& tracing_
std::make_unique<Envoy::Extensions::TransportSockets::Tls::ContextManagerImpl>(
time_system_);

server_ = std::make_unique<NighthawkServerInstance>(admin_, *api_, *dispatcher_, access_log_manager_, envoy_options_, runtime_singleton_->instance(), *singleton_manager_, tls_, *local_info_);
server_ = std::make_unique<NighthawkServerInstance>(
admin_, *api_, *dispatcher_, access_log_manager_, envoy_options_,
runtime_singleton_->instance(), *singleton_manager_, tls_, *local_info_);
server_factory_context_ = std::make_unique<NighthawkServerFactoryContext>(*server_);
cluster_manager_factory_ = std::make_unique<ClusterManagerFactory>(
*server_factory_context_, admin_, Envoy::Runtime::LoaderSingleton::get(), store_root_, tls_,
Expand Down
4 changes: 2 additions & 2 deletions source/client/stream_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

#include <memory>

#include "fmt/ostream.h"

#include "external/envoy/source/common/http/http1/codec_impl.h"
#include "external/envoy/source/common/http/utility.h"
#include "external/envoy/source/common/network/address_impl.h"
#include "external/envoy/source/common/stream_info/stream_info_impl.h"
#include "external/envoy/source/extensions/request_id/uuid/config.h"

#include "fmt/ostream.h"

namespace Nighthawk {
namespace Client {

Expand Down
Loading

0 comments on commit 73a7bf6

Please sign in to comment.