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
30 changes: 18 additions & 12 deletions test/common/access_log/access_log_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,17 @@ envoy::config::accesslog::v3::AccessLog parseAccessLogFromV3Yaml(const std::stri

class AccessLogImplTest : public Event::TestUsingSimulatedTime, public testing::Test {
public:
AccessLogImplTest() : file_(new MockAccessLogFile()) {
AccessLogImplTest() : stream_info_(time_source_), file_(new MockAccessLogFile()) {
ON_CALL(context_, runtime()).WillByDefault(ReturnRef(runtime_));
ON_CALL(context_, accessLogManager()).WillByDefault(ReturnRef(log_manager_));
ON_CALL(log_manager_, createAccessLog(_)).WillByDefault(Return(file_));
ON_CALL(*file_, write(_)).WillByDefault(SaveArg<0>(&output_));
stream_info_.addBytesReceived(1);
stream_info_.addBytesSent(2);
stream_info_.protocol(Http::Protocol::Http11);
}

NiceMock<MockTimeSystem> time_source_;
Http::TestRequestHeaderMapImpl request_headers_{{":method", "GET"}, {":path", "/"}};
Http::TestResponseHeaderMapImpl response_headers_;
Http::TestResponseTrailerMapImpl response_trailers_;
Expand All @@ -77,7 +81,7 @@ name: accesslog
InstanceSharedPtr log = AccessLogFactory::fromProto(parseAccessLogFromV3Yaml(yaml), context_);

EXPECT_CALL(*file_, write(_));
stream_info_.response_flags_ = StreamInfo::ResponseFlag::UpstreamConnectionFailure;
stream_info_.setResponseFlag(StreamInfo::ResponseFlag::UpstreamConnectionFailure);
request_headers_.addCopy(Http::Headers::get().UserAgent, "user-agent-set");
request_headers_.addCopy(Http::Headers::get().RequestId, "id");
request_headers_.addCopy(Http::Headers::get().Host, "host");
Expand All @@ -104,7 +108,7 @@ name: accesslog
auto cluster = std::make_shared<NiceMock<Upstream::MockClusterInfo>>();
stream_info_.upstream_host_ =
Upstream::makeTestHostDescription(cluster, "tcp://10.0.0.5:1234", simTime());
stream_info_.response_flags_ = StreamInfo::ResponseFlag::DownstreamConnectionTermination;
stream_info_.setResponseFlag(StreamInfo::ResponseFlag::DownstreamConnectionTermination);

log->log(&request_headers_, &response_headers_, &response_trailers_, stream_info_);
EXPECT_EQ("[1999-01-01T00:00:00.000Z] \"GET / HTTP/1.1\" 0 DC 1 2 3 - \"-\" \"-\" \"-\" \"-\" "
Expand All @@ -126,8 +130,8 @@ name: accesslog
InstanceSharedPtr log = AccessLogFactory::fromProto(parseAccessLogFromV3Yaml(yaml), context_);

EXPECT_CALL(*file_, write(_));
stream_info_.route_name_ = "route-test-name";
stream_info_.response_flags_ = StreamInfo::ResponseFlag::UpstreamConnectionFailure;
stream_info_.setRouteName("route-test-name");
stream_info_.setResponseFlag(StreamInfo::ResponseFlag::UpstreamConnectionFailure);
request_headers_.addCopy(Http::Headers::get().UserAgent, "user-agent-set");
request_headers_.addCopy(Http::Headers::get().RequestId, "id");
request_headers_.addCopy(Http::Headers::get().Host, "host");
Expand Down Expand Up @@ -598,7 +602,7 @@ name: accesslog
)EOF";

InstanceSharedPtr log = AccessLogFactory::fromProto(parseAccessLogFromV3Yaml(yaml), context_);
stream_info_.response_code_ = 500;
stream_info_.setResponseCode(500);

{
EXPECT_CALL(*file_, write(_));
Expand Down Expand Up @@ -677,7 +681,8 @@ TEST(AccessLogFilterTest, DurationWithRuntimeKey) {
Http::TestRequestHeaderMapImpl request_headers{{":method", "GET"}, {":path", "/"}};
Http::TestResponseHeaderMapImpl response_headers;
Http::TestResponseTrailerMapImpl response_trailers;
TestStreamInfo stream_info;
NiceMock<MockTimeSystem> time_source;
TestStreamInfo stream_info(time_source);

stream_info.end_time_ = stream_info.startTimeMonotonic() + std::chrono::microseconds(100000);
EXPECT_CALL(runtime.snapshot_, getInteger("key", 1000000)).WillOnce(Return(1));
Expand Down Expand Up @@ -712,10 +717,11 @@ TEST(AccessLogFilterTest, StatusCodeWithRuntimeKey) {
TestUtility::loadFromYaml(filter_yaml, config);
StatusCodeFilter filter(config.status_code_filter(), runtime);

NiceMock<MockTimeSystem> time_source;
Http::TestRequestHeaderMapImpl request_headers{{":method", "GET"}, {":path", "/"}};
Http::TestResponseHeaderMapImpl response_headers;
Http::TestResponseTrailerMapImpl response_trailers;
TestStreamInfo info;
TestStreamInfo info(time_source);

info.response_code_ = 400;
EXPECT_CALL(runtime.snapshot_, getInteger("key", 300)).WillOnce(Return(350));
Expand Down Expand Up @@ -1002,7 +1008,7 @@ name: accesslog
StreamInfo::ResponseFlagUtils::ALL_RESPONSE_STRING_FLAGS) {
UNREFERENCED_PARAMETER(flag_string);

TestStreamInfo stream_info;
TestStreamInfo stream_info(time_source_);
stream_info.setResponseFlag(response_flag);
EXPECT_CALL(*file_, write(_));
log->log(&request_headers_, &response_headers_, &response_trailers_, stream_info);
Expand Down Expand Up @@ -1323,7 +1329,7 @@ name: accesslog
path: /dev/null
)EOF";

TestStreamInfo stream_info;
TestStreamInfo stream_info(time_source_);
ProtobufWkt::Struct metadata_val;
auto& fields_a = *metadata_val.mutable_fields();
auto& struct_b = *fields_a["a"].mutable_struct_value();
Expand Down Expand Up @@ -1359,7 +1365,7 @@ name: accesslog
path: /dev/null
)EOF";

TestStreamInfo stream_info;
TestStreamInfo stream_info(time_source_);
ProtobufWkt::Struct metadata_val;
stream_info.setDynamicMetadata("some.namespace", metadata_val);

Expand Down Expand Up @@ -1406,7 +1412,7 @@ name: accesslog
path: /dev/null
)EOF";

TestStreamInfo stream_info;
TestStreamInfo stream_info(time_source_);
ProtobufWkt::Struct metadata_val;
auto& fields_a = *metadata_val.mutable_fields();
auto& struct_b = *fields_a["a"].mutable_struct_value();
Expand Down
4 changes: 3 additions & 1 deletion test/common/formatter/substitution_formatter_fuzz_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ DEFINE_PROTO_FUZZER(const test::common::substitution::TestCase& input) {
Fuzz::fromHeaders<Http::TestResponseHeaderMapImpl>(input.response_headers());
const auto& response_trailers =
Fuzz::fromHeaders<Http::TestResponseTrailerMapImpl>(input.response_trailers());
const std::unique_ptr<TestStreamInfo> stream_info = Fuzz::fromStreamInfo(input.stream_info());
MockTimeSystem time_system;
const std::unique_ptr<TestStreamInfo> stream_info =
Fuzz::fromStreamInfo(input.stream_info(), time_system);
for (const auto& it : formatters) {
it->format(request_headers, response_headers, response_trailers, *stream_info,
absl::string_view());
Expand Down
19 changes: 12 additions & 7 deletions test/common/formatter/substitution_formatter_speed_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ std::unique_ptr<Envoy::Formatter::StructFormatter> makeStructFormatter(bool type
return std::make_unique<Envoy::Formatter::StructFormatter>(StructLogFormat, typed, false);
}

std::unique_ptr<Envoy::TestStreamInfo> makeStreamInfo() {
auto stream_info = std::make_unique<Envoy::TestStreamInfo>();
std::unique_ptr<Envoy::TestStreamInfo> makeStreamInfo(TimeSource& time_source) {
auto stream_info = std::make_unique<Envoy::TestStreamInfo>(time_source);
stream_info->downstream_connection_info_provider_->setRemoteAddress(
std::make_shared<Envoy::Network::Address::Ipv4Instance>("203.0.113.1"));
return stream_info;
Expand All @@ -57,7 +57,8 @@ std::unique_ptr<Envoy::TestStreamInfo> makeStreamInfo() {

// NOLINTNEXTLINE(readability-identifier-naming)
static void BM_AccessLogFormatter(benchmark::State& state) {
std::unique_ptr<Envoy::TestStreamInfo> stream_info = makeStreamInfo();
MockTimeSystem time_system;
std::unique_ptr<Envoy::TestStreamInfo> stream_info = makeStreamInfo(time_system);
static const char* LogFormat =
"%DOWNSTREAM_REMOTE_ADDRESS_WITHOUT_PORT% %START_TIME(%Y/%m/%dT%H:%M:%S%z %s)% "
"%REQ(:METHOD)% "
Expand All @@ -83,7 +84,8 @@ BENCHMARK(BM_AccessLogFormatter);

// NOLINTNEXTLINE(readability-identifier-naming)
static void BM_StructAccessLogFormatter(benchmark::State& state) {
std::unique_ptr<Envoy::TestStreamInfo> stream_info = makeStreamInfo();
MockTimeSystem time_system;
std::unique_ptr<Envoy::TestStreamInfo> stream_info = makeStreamInfo(time_system);
std::unique_ptr<Envoy::Formatter::StructFormatter> struct_formatter = makeStructFormatter(false);

size_t output_bytes = 0;
Expand All @@ -103,7 +105,8 @@ BENCHMARK(BM_StructAccessLogFormatter);

// NOLINTNEXTLINE(readability-identifier-naming)
static void BM_TypedStructAccessLogFormatter(benchmark::State& state) {
std::unique_ptr<Envoy::TestStreamInfo> stream_info = makeStreamInfo();
MockTimeSystem time_system;
std::unique_ptr<Envoy::TestStreamInfo> stream_info = makeStreamInfo(time_system);
std::unique_ptr<Envoy::Formatter::StructFormatter> typed_struct_formatter =
makeStructFormatter(true);

Expand All @@ -124,7 +127,8 @@ BENCHMARK(BM_TypedStructAccessLogFormatter);

// NOLINTNEXTLINE(readability-identifier-naming)
static void BM_JsonAccessLogFormatter(benchmark::State& state) {
std::unique_ptr<Envoy::TestStreamInfo> stream_info = makeStreamInfo();
MockTimeSystem time_system;
std::unique_ptr<Envoy::TestStreamInfo> stream_info = makeStreamInfo(time_system);
std::unique_ptr<Envoy::Formatter::JsonFormatterImpl> json_formatter = makeJsonFormatter(false);

size_t output_bytes = 0;
Expand All @@ -144,7 +148,8 @@ BENCHMARK(BM_JsonAccessLogFormatter);

// NOLINTNEXTLINE(readability-identifier-naming)
static void BM_TypedJsonAccessLogFormatter(benchmark::State& state) {
std::unique_ptr<Envoy::TestStreamInfo> stream_info = makeStreamInfo();
MockTimeSystem time_system;
std::unique_ptr<Envoy::TestStreamInfo> stream_info = makeStreamInfo(time_system);
std::unique_ptr<Envoy::Formatter::JsonFormatterImpl> typed_json_formatter =
makeJsonFormatter(true);

Expand Down
4 changes: 3 additions & 1 deletion test/common/router/header_parser_fuzz_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ DEFINE_PROTO_FUZZER(const test::common::router::TestCase& input) {
Router::HeaderParserPtr parser =
Router::HeaderParser::configure(input.headers_to_add(), input.headers_to_remove());
Http::TestRequestHeaderMapImpl header_map;
std::unique_ptr<TestStreamInfo> test_stream_info = fromStreamInfo(input.stream_info());
MockTimeSystem time_system_;
std::unique_ptr<TestStreamInfo> test_stream_info =
fromStreamInfo(input.stream_info(), time_system_);
parser->evaluateHeaders(header_map, *test_stream_info);
ENVOY_LOG_MISC(trace, "Success");
} catch (const EnvoyException& e) {
Expand Down
Loading