Skip to content

Commit

Permalink
add context.routing_error_reason to report attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarjog committed Aug 7, 2018
1 parent afc72d7 commit e17d80f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/istio/control/http/report_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions include/istio/utils/attribute_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
2 changes: 2 additions & 0 deletions src/envoy/http/mixer/report_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions src/istio/control/http/attributes_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/istio/control/http/attributes_builder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ attributes {
string_value: "http"
}
}
attributes {
key: "context.routing_error_reason"
value {
string_value: "NR"
}
}
attributes {
key: "destination.principal"
value {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions src/istio/utils/attribute_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit e17d80f

Please sign in to comment.