You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by tm...@apache.org on 2019/10/30 01:47:35 UTC

[impala] 03/03: IMPALA-9102: Have webserver fall back to --hostname

This is an automated email from the ASF dual-hosted git repository.

tmarshall pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git

commit 5dc5035a794c8a5fbd027b2309e598923f8c60f4
Author: Thomas Tauber-Marshall <tm...@cloudera.com>
AuthorDate: Tue Oct 29 08:52:27 2019 -0700

    IMPALA-9102: Have webserver fall back to --hostname
    
    When the webserver determines its hostname, it first uses the value of
    --webserver_interface. If this is a wildcard address, then it uses the
    value returned by gethostname().
    
    In some setups, gethostname() may return the short name and not the
    fqdn. This is likely undesirable, eg. because this value is used to
    qualify links when Knox proxying is being used, in which case the fqdn
    is required.
    
    In other places in Impala with the same basic issue, we allow users to
    set the desired hostname with the --hostname flag. This patch has the
    webserver fall back to the --hostname flag if --webserver_interface is
    not set. If neither is set, we'll fall back to gethostname().
    
    Testing:
    - Ran existing webserver tests.
    - Manually tested in an environment where gethostname() does not
      return the fqdn
    
    Change-Id: I76d9b8b5286aa7cfc72b0ccd43de8dafda7ff9fe
    Reviewed-on: http://gerrit.cloudera.org:8080/14568
    Tested-by: Impala Public Jenkins <im...@cloudera.com>
    Reviewed-by: Thomas Tauber-Marshall <tm...@cloudera.com>
---
 be/src/service/impala-server.cc | 9 ++-------
 be/src/util/webserver.cc        | 5 ++++-
 be/src/util/webserver.h         | 4 ++--
 3 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/be/src/service/impala-server.cc b/be/src/service/impala-server.cc
index fbd969f..23056f6 100644
--- a/be/src/service/impala-server.cc
+++ b/be/src/service/impala-server.cc
@@ -1797,13 +1797,8 @@ void ImpalaServer::BuildLocalBackendDescriptorInternal(TBackendDescriptor* be_de
 
   Webserver* webserver = ExecEnv::GetInstance()->webserver();
   if (webserver != nullptr) {
-    const TNetworkAddress& webserver_address = webserver->http_address();
-    if (IsWildcardAddress(webserver_address.hostname)) {
-      be_desc->__set_debug_http_address(
-          MakeNetworkAddress(be_desc->ip_address, webserver_address.port));
-    } else {
-      be_desc->__set_debug_http_address(webserver_address);
-    }
+    be_desc->__set_debug_http_address(
+        MakeNetworkAddress(webserver->hostname(), webserver->port()));
     be_desc->__set_secure_webserver(webserver->IsSecure());
   }
 
diff --git a/be/src/util/webserver.cc b/be/src/util/webserver.cc
index a468659..deaf822 100644
--- a/be/src/util/webserver.cc
+++ b/be/src/util/webserver.cc
@@ -117,6 +117,7 @@ DEFINE_bool(webserver_require_spnego, false,
             "Require connections to the web server to authenticate via Kerberos "
             "using SPNEGO.");
 
+DECLARE_string(hostname);
 DECLARE_bool(is_coordinator);
 DECLARE_int64(max_cookie_lifetime_s);
 DECLARE_string(ssl_minimum_version);
@@ -438,7 +439,9 @@ void Webserver::Stop() {
 void Webserver::Init() {
   hostname_ = http_address_.hostname;
   if (IsWildcardAddress(http_address_.hostname)) {
-    if (!GetHostname(&hostname_).ok()) {
+    if (!FLAGS_hostname.empty()) {
+      hostname_ = FLAGS_hostname;
+    } else if (!GetHostname(&hostname_).ok()) {
       hostname_ = http_address_.hostname;
     }
   }
diff --git a/be/src/util/webserver.h b/be/src/util/webserver.h
index 7d619a4..06cae82 100644
--- a/be/src/util/webserver.h
+++ b/be/src/util/webserver.h
@@ -115,13 +115,13 @@ class Webserver {
   /// produce text should use UrlCallback.
   void RegisterUrlCallback(const std::string& path, const RawUrlCallback& callback);
 
-  const TNetworkAddress& http_address() { return http_address_; }
-
   /// True if serving all traffic over SSL, false otherwise
   bool IsSecure() const;
 
   /// Returns the URL to the webserver as a string.
   string url() { return url_; }
+  string hostname() { return hostname_; }
+  int port() { return http_address_.port; }
 
   /// Returns the appropriate MIME type for a given ContentType.
   static const std::string GetMimeType(const ContentType& content_type);