Skip to content

Commit e562a1b

Browse files
JimmyCYJistio-merge-robot
authored andcommitted
Support Mixer TCP filter to send string type of attribute connection.event. (#1371)
Automatic merge from submit-queue. Support Mixer TCP filter to send string type of attribute "connection.event" **What this PR does / why we need it**: Mixer need to keep tracking of TCP connection creation rate. Support Mixer TCP filter to send attribute "connection.event". In Check() call, "connection.event" is set to "open" In periodical Report() call, "connection.event" is set to "continue" In final Report() call, "connection.event" is set to "close" **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #1369 **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
1 parent 2f2a7ec commit e562a1b

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

src/istio/control/attribute_names.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const char AttributeName::kConnectionDuration[] = "connection.duration";
5656
const char AttributeName::kConnectionMtls[] = "connection.mtls";
5757
// Downstream TCP connection id.
5858
const char AttributeName::kConnectionId[] = "connection.id";
59+
const char AttributeName::kConnectionEvent[] = "connection.event";
5960

6061
// Context attributes
6162
const char AttributeName::kContextProtocol[] = "context.protocol";

src/istio/control/attribute_names.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ struct AttributeName {
5757
static const char kConnectionDuration[];
5858
static const char kConnectionMtls[];
5959
static const char kConnectionId[];
60+
// Record TCP connection status: open, continue, close
61+
static const char kConnectionEvent[];
6062

6163
// Context attributes
6264
static const char kContextProtocol[];

src/istio/control/tcp/attributes_builder.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
namespace istio {
2222
namespace control {
2323
namespace tcp {
24+
namespace {
25+
// Connection events for TCP connection.
26+
const std::string kConnectionOpen("open");
27+
const std::string kConnectionContinue("continue");
28+
const std::string kConnectionClose("close");
29+
} // namespace
2430

2531
void AttributesBuilder::ExtractCheckAttributes(CheckData* check_data) {
2632
utils::AttributesBuilder builder(&request_->attributes);
@@ -43,6 +49,7 @@ void AttributesBuilder::ExtractCheckAttributes(CheckData* check_data) {
4349
builder.AddTimestamp(AttributeName::kContextTime,
4450
std::chrono::system_clock::now());
4551
builder.AddString(AttributeName::kContextProtocol, "tcp");
52+
builder.AddString(AttributeName::kConnectionEvent, kConnectionOpen);
4653

4754
// Get unique downstream connection ID, which is <uuid>-<connection id>.
4855
std::string connection_id = check_data->GetConnectionId();
@@ -71,10 +78,12 @@ void AttributesBuilder::ExtractReportAttributes(
7178
request_->check_status.error_code());
7279
builder.AddString(AttributeName::kCheckErrorMessage,
7380
request_->check_status.ToString());
81+
builder.AddString(AttributeName::kConnectionEvent, kConnectionClose);
7482
}
7583
} else {
7684
last_report_info->received_bytes = info.received_bytes;
7785
last_report_info->send_bytes = info.send_bytes;
86+
builder.AddString(AttributeName::kConnectionEvent, kConnectionContinue);
7887
}
7988

8089
std::string dest_ip;

src/istio/control/tcp/attributes_builder_test.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ namespace tcp {
3636
namespace {
3737

3838
const char kCheckAttributes[] = R"(
39+
attributes {
40+
key: "connection.event"
41+
value {
42+
string_value: "open"
43+
}
44+
}
3945
attributes {
4046
key: "context.protocol"
4147
value {
@@ -82,6 +88,12 @@ attributes {
8288
)";
8389

8490
const char kReportAttributes[] = R"(
91+
attributes {
92+
key: "connection.event"
93+
value {
94+
string_value: "close"
95+
}
96+
}
8597
attributes {
8698
key: "check.error_code"
8799
value {
@@ -148,6 +160,12 @@ attributes {
148160
)";
149161

150162
const char kDeltaOneReportAttributes[] = R"(
163+
attributes {
164+
key: "connection.event"
165+
value {
166+
string_value: "continue"
167+
}
168+
}
151169
attributes {
152170
key: "connection.received.bytes"
153171
value {
@@ -194,6 +212,12 @@ attributes {
194212
)";
195213

196214
const char kDeltaTwoReportAttributes[] = R"(
215+
attributes {
216+
key: "connection.event"
217+
value {
218+
string_value: "continue"
219+
}
220+
}
197221
attributes {
198222
key: "connection.received.bytes"
199223
value {

0 commit comments

Comments
 (0)