From 9518f1d045fa58b2402bfbe49335856af7eb53d2 Mon Sep 17 00:00:00 2001
From: Joseph Schorr <josephschorr@users.noreply.github.com>
Date: Wed, 24 May 2017 14:34:29 -0400
Subject: [PATCH] Disable debug logs in superuser panel when under multiple
 instances

They don't work anyway (since logs will be loaded from random instances), so we just disable them
---
 endpoints/api/superuser.py      |  5 ++++-
 static/js/pages/superuser.js    | 16 ++++++++++++++
 static/partials/super-user.html | 38 ++++++++++++++++++---------------
 3 files changed, 41 insertions(+), 18 deletions(-)

diff --git a/endpoints/api/superuser.py b/endpoints/api/superuser.py
index dcecf6ea0..3d3df1fde 100644
--- a/endpoints/api/superuser.py
+++ b/endpoints/api/superuser.py
@@ -3,6 +3,7 @@
 import logging
 import os
 import string
+import socket
 
 import pathvalidate
 
@@ -72,6 +73,7 @@ class SuperUserGetLogsForService(ApiResource):
         abort(400)
 
       return {
+        'instance': socket.gethostname(),
         'logs': '\n'.join(logs)
       }
 
@@ -91,6 +93,7 @@ class SuperUserSystemLogServices(ApiResource):
     """ List the system logs for the current system. """
     if SuperUserPermission().can():
       return {
+        'instance': socket.gethostname(),
         'services': list(get_services())
       }
 
@@ -900,7 +903,7 @@ class SuperUserCustomCertificate(ApiResource):
         abort(400)
 
       logger.debug('Saving custom certificate %s', certpath)
-      cert_full_path = config_provider.get_volume_path(EXTRA_CA_DIRECTORY, certpath) 
+      cert_full_path = config_provider.get_volume_path(EXTRA_CA_DIRECTORY, certpath)
       config_provider.save_volume_file(cert_full_path, uploaded_file)
       logger.debug('Saved custom certificate %s', certpath)
 
diff --git a/static/js/pages/superuser.js b/static/js/pages/superuser.js
index d8b02051b..6663b9335 100644
--- a/static/js/pages/superuser.js
+++ b/static/js/pages/superuser.js
@@ -18,10 +18,12 @@
     // Monitor any user changes and place the current user into the scope.
     UserService.updateUserIn($scope);
 
+    $scope.multipleInstances = false;
     $scope.configStatus = null;
     $scope.requiresRestart = null;
     $scope.logsCounter = 0;
     $scope.changeLog = null;
+    $scope.logsInstance = null;
     $scope.debugServices = null;
     $scope.debugLogs = null;
     $scope.pollChannel = null;
@@ -83,6 +85,13 @@
         });
 
       ApiService.getSystemLogs(null, params, /* background */true).then(function(resp) {
+        if ($scope.logsInstance != null && $scope.logsInstance != resp['instance']) {
+          $scope.multipleInstances = true;
+          callback(false);
+          return;
+        }
+
+        $scope.logsInstance = resp['instance'];
         $scope.debugLogs = resp['logs'];
         callback(true);
       }, errorHandler);
@@ -96,6 +105,13 @@
       $scope.debugService = null;
 
       ApiService.listSystemLogServices().then(function(resp) {
+        if ($scope.logsInstance != null && $scope.logsInstance != resp['instance']) {
+          $scope.multipleInstances = true;
+          callback(false);
+          return;
+        }
+
+        $scope.logsInstance = resp['instance'];
         $scope.debugServices = resp['services'];
       }, ApiService.errorDisplay('Cannot load system logs. Please contact support.'))
     };
diff --git a/static/partials/super-user.html b/static/partials/super-user.html
index 7ade80b23..abc94cd8e 100644
--- a/static/partials/super-user.html
+++ b/static/partials/super-user.html
@@ -87,27 +87,31 @@
 
         <!-- Debugging tab -->
         <cor-tab-pane id="debug">
-          <div class="cor-loader" ng-show="!debugServices"></div>
+          <div class="co-alert co-alert-warning" ng-show="multipleInstances">
+            Debug logs cannot be displayed as <span class="registry-name"></span> is running under multiple containers. To retrieve logs, please use your implementation's custom configured logging solution.
+          </div>
+          <div ng-show="!multipleInstances">
+            <div class="cor-loader" ng-show="!debugServices"></div>
+            <div role="tabpanel" ng-show="debugServices">
+              <!-- Nav tabs -->
+              <ul class="nav nav-tabs" role="tablist">
+                <li role="presentation" ng-repeat="service in debugServices"
+                    ng-class="debugService == service ? 'active' : ''">
+                  <a ng-click="viewSystemLogs(service)">{{ service }}</a>
+                </li>
+              </ul>
 
-          <div role="tabpanel" ng-show="debugServices">
-            <!-- Nav tabs -->
-            <ul class="nav nav-tabs" role="tablist">
-              <li role="presentation" ng-repeat="service in debugServices"
-                  ng-class="debugService == service ? 'active' : ''">
-                <a ng-click="viewSystemLogs(service)">{{ service }}</a>
-              </li>
-            </ul>
+              <div class="system-log-download-panel" ng-if="!debugService">
+                Select a service above to view its local logs
 
-            <div class="system-log-download-panel" ng-if="!debugService">
-              Select a service above to view its local logs
-
-              <div>
-                <a class="btn btn-primary" href="/systemlogsarchive?_csrf_token={{ csrf_token }}" ng-safenewtab>
-                  <i class="fa fa-download fa-lg" style="margin-right: 4px;"></i> Download All Local Logs (.tar.gz)
-                </a>
+                <div>
+                  <a class="btn btn-primary" href="/systemlogsarchive?_csrf_token={{ csrf_token }}" ng-safenewtab>
+                    <i class="fa fa-download fa-lg" style="margin-right: 4px;"></i> Download All Local Logs (.tar.gz)
+                  </a>
+                </div>
               </div>
+              <div class="cor-log-box" logs="debugLogs" ng-show="debugService"></div>
             </div>
-            <div class="cor-log-box" logs="debugLogs" ng-show="debugService"></div>
           </div>
         </cor-tab-pane>