From e17d80fcaa403c344622db326677785f12f32ab1 Mon Sep 17 00:00:00 2001 From: Mandar U Jog Date: Tue, 7 Aug 2018 08:11:55 -0700 Subject: [PATCH] add context.routing_error_reason to report attributes --- include/istio/control/http/report_data.h | 1 + include/istio/utils/attribute_names.h | 1 + src/envoy/http/mixer/report_data.h | 2 ++ src/istio/control/http/attributes_builder.cc | 3 +++ src/istio/control/http/attributes_builder_test.cc | 7 +++++++ src/istio/utils/attribute_names.cc | 2 ++ 6 files changed, 16 insertions(+) diff --git a/include/istio/control/http/report_data.h b/include/istio/control/http/report_data.h index 3876f336ac3..23ad4b27777 100644 --- a/include/istio/control/http/report_data.h +++ b/include/istio/control/http/report_data.h @@ -40,6 +40,7 @@ class ReportData { uint64_t response_body_size; std::chrono::nanoseconds duration; int response_code; + std::string response_flags; }; virtual void GetReportInfo(ReportInfo* info) const = 0; diff --git a/include/istio/utils/attribute_names.h b/include/istio/utils/attribute_names.h index 462f957ed46..1313d24f48f 100644 --- a/include/istio/utils/attribute_names.h +++ b/include/istio/utils/attribute_names.h @@ -75,6 +75,7 @@ struct AttributeName { // Context attributes static const char kContextProtocol[]; static const char kContextTime[]; + static const char kContextRoutingErrorReason[]; // Check error code and message. static const char kCheckErrorCode[]; diff --git a/src/envoy/http/mixer/report_data.h b/src/envoy/http/mixer/report_data.h index 8b625d4b4c8..dbcea04653b 100644 --- a/src/envoy/http/mixer/report_data.h +++ b/src/envoy/http/mixer/report_data.h @@ -88,6 +88,8 @@ class ReportData : public ::istio::control::http::ReportData { // responseCode is for the backend response. If it is not valid, the request // is rejected by Envoy. Set the response code for such requests as 500. data->response_code = info_.responseCode().value_or(500); + + data->response_flags = RequestInfo::ResponseFlagUtils::toShortString(info_); } bool GetDestinationIpPort(std::string *str_ip, int *port) const override { diff --git a/src/istio/control/http/attributes_builder.cc b/src/istio/control/http/attributes_builder.cc index 4d8a2589d32..7d48cc023ae 100644 --- a/src/istio/control/http/attributes_builder.cc +++ b/src/istio/control/http/attributes_builder.cc @@ -226,6 +226,9 @@ void AttributesBuilder::ExtractReportAttributes(ReportData *report_data) { builder.AddString(utils::AttributeName::kResponseGrpcMessage, grpc_status.message); } + + builder.AddString(utils::AttributeName::kContextRoutingErrorReason, + info.response_flags); } } // namespace http diff --git a/src/istio/control/http/attributes_builder_test.cc b/src/istio/control/http/attributes_builder_test.cc index d2f5d3d8274..b352634ebfd 100644 --- a/src/istio/control/http/attributes_builder_test.cc +++ b/src/istio/control/http/attributes_builder_test.cc @@ -65,6 +65,12 @@ attributes { string_value: "http" } } +attributes { + key: "context.routing_error_reason" + value { + string_value: "NR" + } +} attributes { key: "destination.principal" value { @@ -547,6 +553,7 @@ TEST(AttributesBuilderTest, TestReportAttributes) { info->request_total_size = 240; info->duration = std::chrono::nanoseconds(1); info->response_code = 404; + info->response_flags = "NR"; })); EXPECT_CALL(mock_data, GetGrpcStatus(_)) .WillOnce(Invoke([](ReportData::GrpcStatus *status) -> bool { diff --git a/src/istio/utils/attribute_names.cc b/src/istio/utils/attribute_names.cc index 5a701de1171..7429a9ed9f0 100644 --- a/src/istio/utils/attribute_names.cc +++ b/src/istio/utils/attribute_names.cc @@ -70,6 +70,8 @@ const char AttributeName::kConnectionEvent[] = "connection.event"; // Context attributes const char AttributeName::kContextProtocol[] = "context.protocol"; const char AttributeName::kContextTime[] = "context.time"; +const char AttributeName::kContextRoutingErrorReason[] = + "context.routing_error_reason"; // Check error code and message. const char AttributeName::kCheckErrorCode[] = "check.error_code";