Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use envoy new access_log handler for sending Report. #60

Merged
merged 2 commits into from
Feb 1, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
56 changes: 35 additions & 21 deletions src/envoy/prototype/api_manager_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,23 +163,31 @@ class Request : public google::api_manager::Request {
};

class Response : public google::api_manager::Response {
const AccessLog::RequestInfo& request_info_;

public:
Response(const AccessLog::RequestInfo& request_info)
: request_info_(request_info) {}

google::api_manager::utils::Status GetResponseStatus() {
return google::api_manager::utils::Status::OK;
}

std::size_t GetRequestSize() { return 0; }
std::size_t GetRequestSize() { return request_info_.bytesReceived(); }

std::size_t GetResponseSize() { return 0; }
std::size_t GetResponseSize() { return request_info_.bytesSent(); }

google::api_manager::utils::Status GetLatencyInfo(
google::api_manager::service_control::LatencyInfo* info) {
info->request_time_ms = request_info_.duration().count();
return google::api_manager::utils::Status::OK;
}
};

const Http::HeaderMapImpl BadRequest{{Http::Headers::get().Status, "400"}};

class Instance : public Http::StreamFilter,
public Http::AccessLog::Instance,
public Logger::Loggable<Logger::Id::http> {
private:
std::shared_ptr<google::api_manager::ApiManager> api_manager_;
Expand Down Expand Up @@ -207,12 +215,12 @@ class Instance : public Http::StreamFilter,
: api_manager_(config->api_manager()),
state_(NotStarted),
initiating_call_(false) {
log().debug("Called ApiManager::Instance : {}", __func__);
Log().debug("Called ApiManager::Instance : {}", __func__);
}

FilterHeadersStatus decodeHeaders(HeaderMap& headers,
bool end_stream) override {
log().debug("Called ApiManager::Instance : {}", __func__);
Log().debug("Called ApiManager::Instance : {}", __func__);
std::unique_ptr<google::api_manager::Request> request(
new Request(headers, decoder_callbacks_->downstreamAddress(),
getRouteVirtualHost(headers)));
Expand All @@ -227,13 +235,13 @@ class Instance : public Http::StreamFilter,
if (state_ == Complete) {
return FilterHeadersStatus::Continue;
}
log().debug("Called ApiManager::Instance : {} Stop", __func__);
Log().debug("Called ApiManager::Instance : {} Stop", __func__);
return FilterHeadersStatus::StopIteration;
}

FilterDataStatus decodeData(Buffer::Instance& data,
bool end_stream) override {
log().debug("Called ApiManager::Instance : {} ({}, {})", __func__,
Log().debug("Called ApiManager::Instance : {} ({}, {})", __func__,
data.length(), end_stream);
if (state_ == Calling) {
return FilterDataStatus::StopIterationAndBuffer;
Expand All @@ -242,21 +250,21 @@ class Instance : public Http::StreamFilter,
}

FilterTrailersStatus decodeTrailers(HeaderMap& trailers) override {
log().debug("Called ApiManager::Instance : {}", __func__);
Log().debug("Called ApiManager::Instance : {}", __func__);
if (state_ == Calling) {
return FilterTrailersStatus::StopIteration;
}
return FilterTrailersStatus::Continue;
}
void setDecoderFilterCallbacks(
StreamDecoderFilterCallbacks& callbacks) override {
log().debug("Called ApiManager::Instance : {}", __func__);
Log().debug("Called ApiManager::Instance : {}", __func__);
decoder_callbacks_ = &callbacks;
decoder_callbacks_->addResetStreamCallback(
[this]() { state_ = Responded; });
}
void completeCheck(const google::api_manager::utils::Status& status) {
log().debug("Called ApiManager::Instance : check complete {}",
Log().debug("Called ApiManager::Instance : check complete {}",
status.ToJson());
if (!status.ok() && state_ != Responded) {
state_ = Responded;
Expand All @@ -275,31 +283,35 @@ class Instance : public Http::StreamFilter,

virtual FilterHeadersStatus encodeHeaders(HeaderMap& headers,
bool end_stream) override {
log().debug("Called ApiManager::Instance : {}", __func__);
Log().debug("Called ApiManager::Instance : {}", __func__);
return FilterHeadersStatus::Continue;
}
virtual FilterDataStatus encodeData(Buffer::Instance& data,
bool end_stream) override {
log().debug("Called ApiManager::Instance : {}", __func__);
Log().debug("Called ApiManager::Instance : {}", __func__);
return FilterDataStatus::Continue;
}
virtual FilterTrailersStatus encodeTrailers(HeaderMap& trailers) override {
log().debug("Called ApiManager::Instance : {}", __func__);
Log().debug("Called ApiManager::Instance : {}", __func__);
return FilterTrailersStatus::Continue;
}
virtual void setEncoderFilterCallbacks(
StreamEncoderFilterCallbacks& callbacks) override {
log().debug("Called ApiManager::Instance : {}", __func__);
Log().debug("Called ApiManager::Instance : {}", __func__);
encoder_callbacks_ = &callbacks;
}

// note: cannot extend ~ActiveStream for access log, placing it here
~Instance() {
log().debug("Called ApiManager::Instance : {}", __func__);
std::unique_ptr<google::api_manager::Response> response(new Response());
request_handler_->Report(std::move(response),
[this]() { log().debug("Report returns"); });
virtual void log(const HeaderMap* request_headers,
const HeaderMap* response_headers,
const AccessLog::RequestInfo& request_info) override {
Log().debug("Called ApiManager::Instance : {}", __func__);
std::unique_ptr<google::api_manager::Response> response(
new Response(request_info));
request_handler_->Report(std::move(response), []() {});
}
// There are two log() functions. Use this Log() to redirect to base class
// log().
spdlog::logger& Log() { return Logger::Loggable<Logger::Id::http>::log(); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm... you don't need this since log() signature is different, or if you want Log(), then probably we don't even need to inherit Logger::Loggable, just get the logger object from Logger::Registry

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function signature will not help, compiler still complains about the ambiguity of two log functions.

Copy link
Contributor

@kyessenov kyessenov Feb 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this doesn't help with the name confusion. We probably just need to separate debug log away from the filter. Humans should complain about the ambiguity, too!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so just not inherit Logger::Loggable, use Logger::Registry::getLog and completely different name, debug_log or error_log?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, not to use Loggable base class

};
}
}
Expand All @@ -320,8 +332,10 @@ class ApiManagerConfig : public HttpFilterConfigFactory {
new Http::ApiManager::Config(config, server));
return [api_manager_config](
Http::FilterChainFactoryCallbacks& callbacks) -> void {
auto instance = new Http::ApiManager::Instance(api_manager_config);
callbacks.addStreamFilter(Http::StreamFilterPtr{instance});
std::shared_ptr<Http::ApiManager::Instance> instance(
new Http::ApiManager::Instance(api_manager_config));
callbacks.addStreamFilter(Http::StreamFilterPtr(instance));
callbacks.addAccessLogHandler(Http::AccessLog::InstancePtr(instance));
};
}
};
Expand Down
3 changes: 1 addition & 2 deletions src/envoy/prototype/envoy-esp.conf
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,5 @@
]
}
]
},
"tracing_enabled": "true"
}
}
2 changes: 1 addition & 1 deletion src/envoy/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,6 @@ cc_test(
native.new_git_repository(
name = "envoy_git",
remote = "https://github.com/lyft/envoy.git",
commit = "39f42378fa41c10996d4c3ffba534951de30ceb8",
commit = "0bac7508c6803ec315c2228672728281b99149bd",
build_file_content = BUILD,
)