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

Add context.proxy_error_code to http report attributes #1897

Merged
merged 1 commit into from
Aug 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
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 kContextProxyErrorCode[];

// Check error code and message.
static const char kCheckErrorCode[];
Expand Down
3 changes: 3 additions & 0 deletions src/envoy/http/mixer/report_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#pragma once

#include "common/request_info/utility.h"
#include "envoy/http/header_map.h"
#include "envoy/request_info/request_info.h"
#include "include/istio/control/http/controller.h"
Expand Down Expand Up @@ -88,6 +89,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::kContextProxyErrorCode,
info.response_flags);
}

} // namespace http
Expand Down
8 changes: 8 additions & 0 deletions src/istio/control/http/attributes_builder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,12 @@ attributes {
}
}
}
attributes {
key: "context.proxy_error_code"
value {
string_value: "NR"
}
}
)";

void ClearContextTime(const std::string &name, RequestContext *request) {
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 Expand Up @@ -600,6 +607,7 @@ TEST(AttributesBuilderTest, TestReportAttributesWithDestIP) {
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(testing::Return(false));

Expand Down
1 change: 1 addition & 0 deletions src/istio/utils/attribute_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const char AttributeName::kConnectionEvent[] = "connection.event";
// Context attributes
const char AttributeName::kContextProtocol[] = "context.protocol";
const char AttributeName::kContextTime[] = "context.time";
const char AttributeName::kContextProxyErrorCode[] = "context.proxy_error_code";

// Check error code and message.
const char AttributeName::kCheckErrorCode[] = "check.error_code";
Expand Down