This is an automated email from the ASF dual-hosted git repository.
bmahler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git
The following commit(s) were added to refs/heads/master by this push:
new ed0d79674 Exported container ephemeral ports range in
ResourceStatistics.
ed0d79674 is described below
commit ed0d79674be903f06bee23b956a784f87d71e99c
Author: Ilya Pronin <[email protected]>
AuthorDate: Fri Jan 26 15:50:16 2018 -0800
Exported container ephemeral ports range in ResourceStatistics.
Adds the container's ephemeral port range to ResourceStatistics in
a new field net_ephemeral_ports, which stores the inclusive range.
---
include/mesos/mesos.proto | 3 ++
include/mesos/v1/mesos.proto | 3 ++
.../mesos/isolators/network/port_mapping.cpp | 12 ++++++
src/tests/containerizer/port_mapping_tests.cpp | 43 ++++++++++++++++++++++
4 files changed, 61 insertions(+)
diff --git a/include/mesos/mesos.proto b/include/mesos/mesos.proto
index 5c65071c8..2aad66d67 100644
--- a/include/mesos/mesos.proto
+++ b/include/mesos/mesos.proto
@@ -1939,6 +1939,9 @@ message ResourceStatistics {
optional RateStatistics net_rate_statistics = 54;
+ // Inclusive ephemeral ports range of the container.
+ optional Value.Range net_ephemeral_ports = 55;
+
// The kernel keeps track of RTT (round-trip time) for its TCP
// sockets. RTT is a way to tell the latency of a container.
optional double net_tcp_rtt_microsecs_p50 = 22;
diff --git a/include/mesos/v1/mesos.proto b/include/mesos/v1/mesos.proto
index 17fe7552f..d4ab6f35f 100644
--- a/include/mesos/v1/mesos.proto
+++ b/include/mesos/v1/mesos.proto
@@ -1903,6 +1903,9 @@ message ResourceStatistics {
optional RateStatistics net_rate_statistics = 54;
+ // Inclusive ephemeral ports range of the container.
+ optional Value.Range net_ephemeral_ports = 55;
+
// The kernel keeps track of RTT (round-trip time) for its TCP
// sockets. RTT is a way to tell the latency of a container.
optional double net_tcp_rtt_microsecs_p50 = 22;
diff --git a/src/slave/containerizer/mesos/isolators/network/port_mapping.cpp
b/src/slave/containerizer/mesos/isolators/network/port_mapping.cpp
index c316b7dba..e01db95ed 100644
--- a/src/slave/containerizer/mesos/isolators/network/port_mapping.cpp
+++ b/src/slave/containerizer/mesos/isolators/network/port_mapping.cpp
@@ -4233,6 +4233,18 @@ Future<ResourceStatistics>
PortMappingIsolatorProcess::usage(
}
}
+ // Include ephemeral ports range of the container. Check for an
+ // empty interval, because the container may have no ephemeral ports
+ // if it was only partially isolated due to agent crash.
+ //
+ // Note: Interval::upper() is exclusive, however, net_ephemeral_ports::end is
+ // inclusive, so we substract from Interval::upper().
+ if (info->ephemeralPorts != Interval<uint16_t>()) {
+ Value::Range* const ports = result.mutable_net_ephemeral_ports();
+ ports->set_begin(info->ephemeralPorts.lower());
+ ports->set_end(info->ephemeralPorts.upper() - 1);
+ }
+
// Retrieve the socket information from inside the container.
PortMappingStatistics statistics;
statistics.flags.pid = info->pid.get();
diff --git a/src/tests/containerizer/port_mapping_tests.cpp
b/src/tests/containerizer/port_mapping_tests.cpp
index f2c1e9e78..d96d0c5c5 100644
--- a/src/tests/containerizer/port_mapping_tests.cpp
+++ b/src/tests/containerizer/port_mapping_tests.cpp
@@ -2113,6 +2113,35 @@ bool HasTCPRetransSegs(const ResourceStatistics&
statistics)
}
+Try<Interval<uint16_t>> getEphemeralPortRange(pid_t pid)
+{
+ Try<string> out = os::shell(
+ "ip netns exec " + stringify(pid) +
+ " cat /proc/sys/net/ipv4/ip_local_port_range");
+ if (out.isError()) {
+ return Error("Failed to read ip_local_port_range: " + out.error());
+ }
+
+ vector<string> ports = strings::split(strings::trim(out.get()), "\t");
+ if (ports.size() != 2) {
+ return Error("Unexpected ip_local_port_range format: " + out.get());
+ }
+
+ Try<uint16_t> begin = numify<uint16_t>(ports[0]);
+ if (begin.isError()) {
+ return Error("Failed to parse begin of ip_local_port_range: " + ports[0]);
+ }
+
+ Try<uint16_t> end = numify<uint16_t>(ports[1]);
+ if (end.isError()) {
+ return Error("Failed to parse end of ip_local_port_range: " + ports[1]);
+ }
+
+ return (Bound<uint16_t>::closed(begin.get()),
+ Bound<uint16_t>::closed(end.get()));
+}
+
+
// Test that RTT can be returned properly from usage(). This test is
// very similar to SmallEgressLimitTest in its setup.
TEST_F(PortMappingIsolatorTest, ROOT_NC_PortMappingStatistics)
@@ -2231,6 +2260,20 @@ TEST_F(PortMappingIsolatorTest,
ROOT_NC_PortMappingStatistics)
if (usage->has_net_tcp_rtt_microsecs_p50() &&
usage->has_net_tcp_active_connections()) {
EXPECT_GT(usage->net_tcp_active_connections(), 0);
+
+ // Test that requested number of ephemeral ports is reported.
+ ASSERT_TRUE(usage->has_net_ephemeral_ports());
+ const Value::Range& ephemeralPorts = usage->net_ephemeral_ports();
+ EXPECT_EQ(flags.ephemeral_ports_per_container,
+ ephemeralPorts.end() - ephemeralPorts.begin() + 1u);
+
+ // Test that reported ports range is same as the one inside the
+ // container.
+ Try<Interval<uint16_t>> ports = getEphemeralPortRange(pid.get());
+ ASSERT_SOME(ports);
+ EXPECT_EQ(ports->lower(), ephemeralPorts.begin());
+ EXPECT_EQ(ports->upper() - 1u, ephemeralPorts.end());
+
break;
}
} while (waited < Seconds(5));