This is an automated email from the ASF dual-hosted git repository. bbannier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mesos.git
commit 5656c26796bb135a3258916685ec037b093b8192 Author: Benjamin Bannier <[email protected]> AuthorDate: Wed Jul 31 13:46:34 2019 +0200 Stored last time a drain request was sent in the agent. This information can be used to calculate an approximate time when draining an agent would be finished, e.g., by comparing `DrainConfig.max_grace_period` and the field `estimated_drain_start_time` added here, both obtained from the agent API simultaneously. This information is necessarily approximate as the agent might e.g., fail over before it has finished draining which would reset the timeout; for that specific case the master would send the drain request again so after some time the value calculated from the agent API would be in line with the expected true value. Review: https://reviews.apache.org/r/71183/ --- include/mesos/agent/agent.proto | 1 + include/mesos/v1/agent/agent.proto | 1 + src/slave/http.cpp | 13 +++++++++++++ src/slave/slave.cpp | 2 ++ src/slave/slave.hpp | 4 ++++ 5 files changed, 21 insertions(+) diff --git a/include/mesos/agent/agent.proto b/include/mesos/agent/agent.proto index 3cb622d..030ed61 100644 --- a/include/mesos/agent/agent.proto +++ b/include/mesos/agent/agent.proto @@ -571,6 +571,7 @@ message Response { optional SlaveInfo slave_info = 1; optional DrainConfig drain_config = 2; + optional TimeInfo estimated_drain_start_time = 3; } // Lists information about all resource providers known to the agent diff --git a/include/mesos/v1/agent/agent.proto b/include/mesos/v1/agent/agent.proto index 4324ad6..be7db86 100644 --- a/include/mesos/v1/agent/agent.proto +++ b/include/mesos/v1/agent/agent.proto @@ -571,6 +571,7 @@ message Response { optional AgentInfo agent_info = 1; optional DrainConfig drain_config = 2; + optional TimeInfo estimated_drain_start_time = 3; } // Lists information about all resource providers known to the agent diff --git a/src/slave/http.cpp b/src/slave/http.cpp index d9f113d..4d68ce7 100644 --- a/src/slave/http.cpp +++ b/src/slave/http.cpp @@ -1337,6 +1337,13 @@ Future<Response> Http::state( writer->field( "drain_config", JSON::Protobuf(slave->drainConfig.get())); + + if (slave->estimatedDrainStartTime.isSome()) { + writer->field( + "estimated_drain_start_time_seconds", + static_cast<int64_t>( + slave->estimatedDrainStartTime->secs())); + } } const Resources& totalResources = slave->totalResources; @@ -1853,6 +1860,12 @@ Future<Response> Http::getAgent( if (slave->drainConfig.isSome()) { response.mutable_get_agent()->mutable_drain_config()->CopyFrom( slave->drainConfig.get()); + + if (slave->estimatedDrainStartTime.isSome()) { + response.mutable_get_agent() + ->mutable_estimated_drain_start_time() + ->set_nanoseconds(Seconds(slave->estimatedDrainStartTime->secs()).ns()); + } } return OK(serialize(acceptType, evolve(response)), diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp index 9c14784..74eb457 100644 --- a/src/slave/slave.cpp +++ b/src/slave/slave.cpp @@ -1009,6 +1009,7 @@ void Slave::drain( << "Failed to checkpoint DrainConfig"; drainConfig = drainSlaveMessage.config(); + estimatedDrainStartTime = Clock::now(); const Option<DurationInfo> maxGracePeriod = drainConfig->has_max_grace_period() @@ -9810,6 +9811,7 @@ void Slave::updateDrainStatus() } drainConfig = None(); + estimatedDrainStartTime = None(); } diff --git a/src/slave/slave.hpp b/src/slave/slave.hpp index 556d8ea..a17bbee 100644 --- a/src/slave/slave.hpp +++ b/src/slave/slave.hpp @@ -914,6 +914,10 @@ private: // drain the agent. If NONE, the agent is not currently draining. Option<DrainConfig> drainConfig; + // Time when this agent was last asked to drain. This field + // is empty if the agent is not currently draining. + Option<process::Time> estimatedDrainStartTime; + // Check whether draining is finished and possibly remove // both in-memory and persisted drain configuration. void updateDrainStatus();
