Skip to content

Commit

Permalink
Store check_status_code in class Instance.
Browse files Browse the repository at this point in the history
  • Loading branch information
chowchow316 committed Feb 22, 2017
1 parent 8488133 commit 766d038
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
15 changes: 12 additions & 3 deletions src/envoy/mixer/http_control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const std::string kAttrNameResponseSize = "response.size";
const std::string kAttrNameResponseTime = "response.time";
const std::string kAttrNameOriginIp = "origin.ip";
const std::string kAttrNameOriginHost = "origin.host";
const std::string kResponseStatusCode = "response.status.code";

Attributes::Value StringValue(const std::string& str) {
Attributes::Value v;
Expand Down Expand Up @@ -113,7 +114,7 @@ void FillResponseHeaderAttributes(const HeaderMap& header_map,
}

void FillRequestInfoAttributes(const AccessLog::RequestInfo& info,
Attributes* attr) {
int check_status_code, Attributes* attr) {
if (info.bytesReceived() >= 0) {
attr->attributes[kAttrNameRequestSize] = Int64Value(info.bytesReceived());
}
Expand All @@ -124,6 +125,13 @@ void FillRequestInfoAttributes(const AccessLog::RequestInfo& info,
attr->attributes[kAttrNameResponseTime] =
Int64Value(info.duration().count());
}
if (info.responseCode().valid()) {
attr->attributes[kResponseStatusCode] =
StringValue(std::to_string(info.responseCode().value()));
} else {
attr->attributes[kResponseStatusCode] =
StringValue(std::to_string(check_status_code));
}
}

} // namespace
Expand Down Expand Up @@ -155,11 +163,12 @@ void HttpControl::Check(HttpRequestDataPtr request_data, HeaderMap& headers,
void HttpControl::Report(HttpRequestDataPtr request_data,
const HeaderMap* response_headers,
const AccessLog::RequestInfo& request_info,
DoneFunc on_done) {
int check_status, DoneFunc on_done) {
// Use all Check attributes for Report.
// Add additional Report attributes.
FillResponseHeaderAttributes(*response_headers, &request_data->attributes);
FillRequestInfoAttributes(request_info, &request_data->attributes);
FillRequestInfoAttributes(request_info, check_status,
&request_data->attributes);
log().debug("Send Report: {}", request_data->attributes.DebugString());
mixer_client_->Report(request_data->attributes, on_done);
}
Expand Down
2 changes: 1 addition & 1 deletion src/envoy/mixer/http_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class HttpControl final : public Logger::Loggable<Logger::Id::http> {
// Make mixer report call.
void Report(HttpRequestDataPtr request_data,
const HeaderMap* response_headers,
const AccessLog::RequestInfo& request_info,
const AccessLog::RequestInfo& request_info, int check_status_code,
::istio::mixer_client::DoneFunc on_done);

private:
Expand Down
12 changes: 7 additions & 5 deletions src/envoy/mixer/http_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class Config : public Logger::Loggable<Logger::Id::http> {

http_control_ =
std::make_shared<HttpControl>(mixer_server, std::move(attributes));
log().debug("Called Mixer::Config contructor with mixer_server: ",
log().debug("Called Mixer::Config constructor with mixer_server: ",
mixer_server);
}

Expand All @@ -126,12 +126,14 @@ class Instance : public Http::StreamFilter, public Http::AccessLog::Instance {
StreamEncoderFilterCallbacks* encoder_callbacks_;

bool initiating_call_;
int check_status_code_;

public:
Instance(ConfigPtr config)
: http_control_(config->http_control()),
state_(NotStarted),
initiating_call_(false) {
initiating_call_(false),
check_status_code_(HttpCode(StatusCode::UNKNOWN)) {
Log().debug("Called Mixer::Instance : {}", __func__);
}

Expand Down Expand Up @@ -190,8 +192,8 @@ class Instance : public Http::StreamFilter, public Http::AccessLog::Instance {
status.ToString());
if (!status.ok() && state_ != Responded) {
state_ = Responded;
Utility::sendLocalReply(*decoder_callbacks_,
Code(HttpCode(status.error_code())),
check_status_code_ = HttpCode(status.error_code());
Utility::sendLocalReply(*decoder_callbacks_, Code(check_status_code_),
status.ToString());
return;
}
Expand Down Expand Up @@ -229,7 +231,7 @@ class Instance : public Http::StreamFilter, public Http::AccessLog::Instance {
// The class may be gone when it is called.
// Log() is a static function so it is OK.
http_control_->Report(request_data_, response_headers, request_info,
[](const Status& status) {
check_status_code_, [](const Status& status) {
Log().debug("Report returns status: {}",
status.ToString());
});
Expand Down

0 comments on commit 766d038

Please sign in to comment.