Commit 6a175390 authored by Meera Srinivasan's avatar Meera Srinivasan Committed by Commit Bot

Added hostname to HeartbeatRequest + populated the field if the user's

email address is @google.com.

Change-Id: I35a217fbec4995125afb42cce4332c507fdbd78b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2276811
Commit-Queue: Joe Downing <joedow@chromium.org>
Reviewed-by: default avatarJoe Downing <joedow@chromium.org>
Reviewed-by: default avatarGary Kacmarcik <garykac@chromium.org>
Cr-Commit-Position: refs/heads/master@{#785862}
parent f4bdfb51
...@@ -10,11 +10,14 @@ ...@@ -10,11 +10,14 @@
#include <utility> #include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/hash/md5.h"
#include "base/rand_util.h" #include "base/rand_util.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/stringize_macros.h" #include "base/strings/stringize_macros.h"
#include "base/system/sys_info.h" #include "base/system/sys_info.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "build/build_config.h"
#include "net/base/network_interfaces.h"
#include "remoting/base/constants.h" #include "remoting/base/constants.h"
#include "remoting/base/grpc_support/grpc_async_unary_request.h" #include "remoting/base/grpc_support/grpc_async_unary_request.h"
#include "remoting/base/grpc_support/grpc_authenticated_executor.h" #include "remoting/base/grpc_support/grpc_authenticated_executor.h"
...@@ -22,6 +25,7 @@ ...@@ -22,6 +25,7 @@
#include "remoting/base/grpc_support/grpc_util.h" #include "remoting/base/grpc_support/grpc_util.h"
#include "remoting/base/logging.h" #include "remoting/base/logging.h"
#include "remoting/base/service_urls.h" #include "remoting/base/service_urls.h"
#include "remoting/host/host_config.h"
#include "remoting/host/host_details.h" #include "remoting/host/host_details.h"
#include "remoting/host/server_log_entry_host.h" #include "remoting/host/server_log_entry_host.h"
#include "remoting/proto/remoting/v1/directory_service.grpc.pb.h" #include "remoting/proto/remoting/v1/directory_service.grpc.pb.h"
...@@ -129,7 +133,8 @@ void HeartbeatSender::HeartbeatClientImpl::CancelPendingRequests() { ...@@ -129,7 +133,8 @@ void HeartbeatSender::HeartbeatClientImpl::CancelPendingRequests() {
HeartbeatSender::HeartbeatSender(Delegate* delegate, HeartbeatSender::HeartbeatSender(Delegate* delegate,
const std::string& host_id, const std::string& host_id,
SignalStrategy* signal_strategy, SignalStrategy* signal_strategy,
OAuthTokenGetter* oauth_token_getter) OAuthTokenGetter* oauth_token_getter,
bool is_googler)
: delegate_(delegate), : delegate_(delegate),
host_id_(host_id), host_id_(host_id),
signal_strategy_(signal_strategy), signal_strategy_(signal_strategy),
...@@ -141,6 +146,7 @@ HeartbeatSender::HeartbeatSender(Delegate* delegate, ...@@ -141,6 +146,7 @@ HeartbeatSender::HeartbeatSender(Delegate* delegate,
signal_strategy_->AddListener(this); signal_strategy_->AddListener(this);
OnSignalStrategyStateChange(signal_strategy_->GetState()); OnSignalStrategyStateChange(signal_strategy_->GetState());
is_googler_ = is_googler;
} }
HeartbeatSender::~HeartbeatSender() { HeartbeatSender::~HeartbeatSender() {
...@@ -350,7 +356,13 @@ apis::v1::HeartbeatRequest HeartbeatSender::CreateHeartbeatRequest() { ...@@ -350,7 +356,13 @@ apis::v1::HeartbeatRequest HeartbeatSender::CreateHeartbeatRequest() {
heartbeat.set_host_os_version(GetHostOperatingSystemVersion()); heartbeat.set_host_os_version(GetHostOperatingSystemVersion());
heartbeat.set_host_cpu_type(base::SysInfo::OperatingSystemArchitecture()); heartbeat.set_host_cpu_type(base::SysInfo::OperatingSystemArchitecture());
heartbeat.set_is_initial_heartbeat(!initial_heartbeat_sent_); heartbeat.set_is_initial_heartbeat(!initial_heartbeat_sent_);
// Only set the hostname if the user's email is @google.com and they are using
// a Linux OS.
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
if (is_googler_) {
heartbeat.set_hostname(base::MD5String(net::GetHostName()));
}
#endif
return heartbeat; return heartbeat;
} }
......
...@@ -74,7 +74,8 @@ class HeartbeatSender final : public SignalStrategy::Listener { ...@@ -74,7 +74,8 @@ class HeartbeatSender final : public SignalStrategy::Listener {
HeartbeatSender(Delegate* delegate, HeartbeatSender(Delegate* delegate,
const std::string& host_id, const std::string& host_id,
SignalStrategy* signal_strategy, SignalStrategy* signal_strategy,
OAuthTokenGetter* oauth_token_getter); OAuthTokenGetter* oauth_token_getter,
bool is_googler);
~HeartbeatSender() override; ~HeartbeatSender() override;
// Sets host offline reason for future heartbeat, and initiates sending a // Sets host offline reason for future heartbeat, and initiates sending a
...@@ -139,6 +140,8 @@ class HeartbeatSender final : public SignalStrategy::Listener { ...@@ -139,6 +140,8 @@ class HeartbeatSender final : public SignalStrategy::Listener {
bool initial_heartbeat_sent_ = false; bool initial_heartbeat_sent_ = false;
bool is_googler_ = false;
// Fields to send and indicate completion of sending host-offline-reason. // Fields to send and indicate completion of sending host-offline-reason.
std::string host_offline_reason_; std::string host_offline_reason_;
base::OnceCallback<void(bool success)> host_offline_reason_ack_callback_; base::OnceCallback<void(bool success)> host_offline_reason_ack_callback_;
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "base/threading/sequenced_task_runner_handle.h" #include "base/threading/sequenced_task_runner_handle.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "build/build_config.h"
#include "remoting/base/fake_oauth_token_getter.h" #include "remoting/base/fake_oauth_token_getter.h"
#include "remoting/proto/remoting/v1/directory_service.grpc.pb.h" #include "remoting/proto/remoting/v1/directory_service.grpc.pb.h"
#include "remoting/signaling/fake_signal_strategy.h" #include "remoting/signaling/fake_signal_strategy.h"
...@@ -56,7 +57,8 @@ constexpr base::TimeDelta kTestHeartbeatDelay = ...@@ -56,7 +57,8 @@ constexpr base::TimeDelta kTestHeartbeatDelay =
void ValidateHeartbeat(const apis::v1::HeartbeatRequest& request, void ValidateHeartbeat(const apis::v1::HeartbeatRequest& request,
bool expected_is_initial_heartbeat = false, bool expected_is_initial_heartbeat = false,
const std::string& expected_host_offline_reason = {}) { const std::string& expected_host_offline_reason = {},
bool is_googler = false) {
ASSERT_TRUE(request.has_host_version()); ASSERT_TRUE(request.has_host_version());
if (expected_host_offline_reason.empty()) { if (expected_host_offline_reason.empty()) {
ASSERT_FALSE(request.has_host_offline_reason()); ASSERT_FALSE(request.has_host_offline_reason());
...@@ -70,15 +72,25 @@ void ValidateHeartbeat(const apis::v1::HeartbeatRequest& request, ...@@ -70,15 +72,25 @@ void ValidateHeartbeat(const apis::v1::HeartbeatRequest& request,
ASSERT_TRUE(request.has_host_os_name()); ASSERT_TRUE(request.has_host_os_name());
ASSERT_TRUE(request.has_host_cpu_type()); ASSERT_TRUE(request.has_host_cpu_type());
ASSERT_EQ(expected_is_initial_heartbeat, request.is_initial_heartbeat()); ASSERT_EQ(expected_is_initial_heartbeat, request.is_initial_heartbeat());
bool is_linux = false;
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
is_linux = true;
#endif
if (is_googler && is_linux) {
ASSERT_TRUE(request.has_hostname());
} else {
ASSERT_FALSE(request.has_hostname());
}
} }
decltype(auto) DoValidateHeartbeatAndRespondOk( decltype(auto) DoValidateHeartbeatAndRespondOk(
bool expected_is_initial_heartbeat = false, bool expected_is_initial_heartbeat = false,
const std::string& expected_host_offline_reason = {}) { const std::string& expected_host_offline_reason = {},
bool is_googler = false) {
return [=](const apis::v1::HeartbeatRequest& request, return [=](const apis::v1::HeartbeatRequest& request,
HeartbeatResponseCallback callback) { HeartbeatResponseCallback callback) {
ValidateHeartbeat(request, expected_is_initial_heartbeat, ValidateHeartbeat(request, expected_is_initial_heartbeat,
expected_host_offline_reason); expected_host_offline_reason, is_googler);
apis::v1::HeartbeatResponse response; apis::v1::HeartbeatResponse response;
response.set_set_interval_seconds(kGoodIntervalSeconds); response.set_set_interval_seconds(kGoodIntervalSeconds);
std::move(callback).Run(grpc::Status::OK, response); std::move(callback).Run(grpc::Status::OK, response);
...@@ -112,7 +124,8 @@ class HeartbeatSenderTest : public testing::Test { ...@@ -112,7 +124,8 @@ class HeartbeatSenderTest : public testing::Test {
signal_strategy_->Disconnect(); signal_strategy_->Disconnect();
heartbeat_sender_ = std::make_unique<HeartbeatSender>( heartbeat_sender_ = std::make_unique<HeartbeatSender>(
&mock_delegate_, kHostId, signal_strategy_.get(), &oauth_token_getter_); &mock_delegate_, kHostId, signal_strategy_.get(), &oauth_token_getter_,
false);
auto heartbeat_client = std::make_unique<MockHeartbeatClient>(); auto heartbeat_client = std::make_unique<MockHeartbeatClient>();
mock_client_ = heartbeat_client.get(); mock_client_ = heartbeat_client.get();
heartbeat_sender_->client_ = std::move(heartbeat_client); heartbeat_sender_->client_ = std::move(heartbeat_client);
...@@ -138,6 +151,8 @@ class HeartbeatSenderTest : public testing::Test { ...@@ -138,6 +151,8 @@ class HeartbeatSenderTest : public testing::Test {
HeartbeatSender* heartbeat_sender() { return heartbeat_sender_.get(); } HeartbeatSender* heartbeat_sender() { return heartbeat_sender_.get(); }
void set_is_googler() { heartbeat_sender()->is_googler_ = true; }
const net::BackoffEntry& GetBackoff() const { const net::BackoffEntry& GetBackoff() const {
return heartbeat_sender_->backoff_; return heartbeat_sender_->backoff_;
} }
...@@ -308,4 +323,11 @@ TEST_F(HeartbeatSenderTest, RemoteCommand) { ...@@ -308,4 +323,11 @@ TEST_F(HeartbeatSenderTest, RemoteCommand) {
signal_strategy_->Connect(); signal_strategy_->Connect();
} }
TEST_F(HeartbeatSenderTest, GooglerHostname) {
set_is_googler();
EXPECT_CALL(*mock_client_, Heartbeat(_, _))
.WillOnce(DoValidateHeartbeatAndRespondOk(true, "", true));
signal_strategy_->Connect();
}
} // namespace remoting } // namespace remoting
...@@ -199,6 +199,10 @@ const char kHostOfflineReasonPolicyChangeRequiresRestart[] = ...@@ -199,6 +199,10 @@ const char kHostOfflineReasonPolicyChangeRequiresRestart[] =
"POLICY_CHANGE_REQUIRES_RESTART"; "POLICY_CHANGE_REQUIRES_RESTART";
const char kHostOfflineReasonRemoteRestartHost[] = "REMOTE_RESTART_HOST"; const char kHostOfflineReasonRemoteRestartHost[] = "REMOTE_RESTART_HOST";
// The default email domain for Googlers. Used to determine whether the host's
// email address is Google-internal or not.
constexpr char kGooglerEmailDomain[] = "@google.com";
} // namespace } // namespace
namespace remoting { namespace remoting {
...@@ -1402,8 +1406,14 @@ void HostProcess::InitializeSignaling() { ...@@ -1402,8 +1406,14 @@ void HostProcess::InitializeSignaling() {
ftl_signal_strategy.get(), ftl_signal_strategy.get(),
base::BindOnce(&HostProcess::OnAuthFailed, base::Unretained(this))); base::BindOnce(&HostProcess::OnAuthFailed, base::Unretained(this)));
ftl_signaling_connector_->Start(); ftl_signaling_connector_->Start();
// Check if the host owner's email is Google-internal.
bool is_googler = base::EndsWith(host_owner_, kGooglerEmailDomain,
base::CompareCase::INSENSITIVE_ASCII);
heartbeat_sender_ = std::make_unique<HeartbeatSender>( heartbeat_sender_ = std::make_unique<HeartbeatSender>(
this, host_id_, ftl_signal_strategy.get(), oauth_token_getter_.get()); this, host_id_, ftl_signal_strategy.get(), oauth_token_getter_.get(),
is_googler);
signal_strategy_ = std::move(ftl_signal_strategy); signal_strategy_ = std::move(ftl_signal_strategy);
} }
......
...@@ -74,6 +74,9 @@ message HeartbeatRequest { ...@@ -74,6 +74,9 @@ message HeartbeatRequest {
// Indicates whether this request is the first heartbeat from a host instance. // Indicates whether this request is the first heartbeat from a host instance.
optional bool is_initial_heartbeat = 11; optional bool is_initial_heartbeat = 11;
// A hash of the local hostname of the machine.
optional string hostname = 12;
} }
// Sent in response to a HeartbeatRequest. // Sent in response to a HeartbeatRequest.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment