diff --git a/src/envoy/mixer/http_control.cc b/src/envoy/mixer/http_control.cc index 870d70956fb..bbff6b94992 100644 --- a/src/envoy/mixer/http_control.cc +++ b/src/envoy/mixer/http_control.cc @@ -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; @@ -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()); } @@ -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 @@ -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); } diff --git a/src/envoy/mixer/http_control.h b/src/envoy/mixer/http_control.h index bf52e49a81a..65863d950fa 100644 --- a/src/envoy/mixer/http_control.h +++ b/src/envoy/mixer/http_control.h @@ -47,7 +47,7 @@ class HttpControl final : public Logger::Loggable { // 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: diff --git a/src/envoy/mixer/http_filter.cc b/src/envoy/mixer/http_filter.cc index a37ac032ee1..d0796b506dd 100644 --- a/src/envoy/mixer/http_filter.cc +++ b/src/envoy/mixer/http_filter.cc @@ -105,7 +105,7 @@ class Config : public Logger::Loggable { http_control_ = std::make_shared(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); } @@ -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__); } @@ -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; } @@ -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()); });