Skip to content

Commit

Permalink
Merge pull request #248 from Yelp/metastatus_dashboards
Browse files Browse the repository at this point in the history
made metastatus read from /etc/paasta to get dashboards
  • Loading branch information
mjksmith committed Feb 11, 2016
2 parents d690327 + 339de0e commit 76e7c72
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 24 deletions.
26 changes: 12 additions & 14 deletions paasta_tools/cli/cmds/metastatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
# limitations under the License.
from paasta_tools.cli.utils import execute_paasta_metastatus_on_remote_master
from paasta_tools.cli.utils import lazy_choices_completer
from paasta_tools.smartstack_tools import DEFAULT_SYNAPSE_PORT
from paasta_tools.utils import list_clusters
from paasta_tools.utils import PaastaColors
from paasta_tools.utils import load_system_paasta_config
from paasta_tools.utils import PaastaNotConfiguredError


def add_subparser(subparsers):
Expand Down Expand Up @@ -73,18 +73,16 @@ def figure_out_clusters_to_inspect(args, all_clusters):

def get_cluster_dashboards(cluster):
"""Returns the direct dashboards for humans to use for a given cluster"""
output = []
output.append("Warning: Dashboards in prod are not directly reachable. "
"See http://y/paasta-troubleshooting for instructions. (search for 'prod dashboards')")
output.append("User Dashboards (Read Only):")
output.append(" Mesos: %s" % PaastaColors.cyan("http://mesos.paasta-%s.yelp/" % cluster))
output.append(" Marathon: %s" % PaastaColors.cyan("http://marathon.paasta-%s.yelp/" % cluster))
output.append(" Chronos: %s" % PaastaColors.cyan("http://chronos.paasta-%s.yelp/" % cluster))
output.append(" Synapse: %s" % PaastaColors.cyan("http://paasta-%s.yelp:%s/" % (cluster, DEFAULT_SYNAPSE_PORT)))
output.append("Admin Dashboards (Read/write, requires secrets):")
output.append(" Mesos: %s" % PaastaColors.cyan("http://paasta-%s.yelp:5050/" % cluster))
output.append(" Marathon: %s" % PaastaColors.cyan("http://paasta-%s.yelp:5052/" % cluster))
output.append(" Chronos: %s" % PaastaColors.cyan("http://paasta-%s.yelp:5053/" % cluster))
SPACER = ' '
try:
dashboards = load_system_paasta_config().get_dashboard_links()[cluster]
except PaastaNotConfiguredError:
output = ['No dashboards configured for %s!' % cluster]
else:
output = ['Dashboards:']
spacing = max((len(label) for label in dashboards.keys())) + 1
for label, url in dashboards.items():
output.append(' %s:%s%s' % (label, SPACER * (spacing - len(label)), url))
return '\n'.join(output)


Expand Down
7 changes: 7 additions & 0 deletions paasta_tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,13 @@ def get_fsm_cluster_map(self):
raise PaastaNotConfiguredError(
'Could not find fsm_cluster_map in configuration directory: %s' % self.directory)

def get_dashboard_links(self):
try:
return self['dashboard_links']
except KeyError:
raise PaastaNotConfiguredError(
'Could not find dashboard_links in configuration directory: %s' % self.directory)


def _run(command, env=os.environ, timeout=None, log=False, stream=False, stdin=None, **kwargs):
"""Given a command, run it. Return a tuple of the return code and any
Expand Down
31 changes: 21 additions & 10 deletions tests/cli/test_cmds_metastatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,20 @@
import mock

from paasta_tools.cli.cmds import metastatus
from paasta_tools.smartstack_tools import DEFAULT_SYNAPSE_PORT
from paasta_tools.utils import SystemPaastaConfig


@mock.patch('paasta_tools.cli.cmds.metastatus.load_system_paasta_config', autospec=True)
@mock.patch('sys.stdout', new_callable=StringIO)
def test_report_cluster_status(mock_stdout):
def test_report_cluster_status(mock_stdout, mock_load_system_paasta_config):
cluster = 'fake_cluster'
mock_load_system_paasta_config.return_value = SystemPaastaConfig({
'dashboard_links': {
'fake_cluster': {
'URL': 'http://paasta-fake_cluster.yelp:5050',
},
},
}, 'fake_directory')
thing_to_patch = 'paasta_tools.cli.cmds.metastatus.execute_paasta_metastatus_on_remote_master'
with mock.patch(thing_to_patch) as mock_execute_paasta_metastatus_on_remote_master:
mock_execute_paasta_metastatus_on_remote_master.return_value = 'mock_status'
Expand All @@ -42,11 +50,14 @@ def test_figure_out_clusters_to_inspect_respects_the_user():


def test_get_cluster_dashboards():
output_text = metastatus.get_cluster_dashboards('fake-cluster')
assert 'http://paasta-fake-cluster.yelp:5050' in output_text
assert 'http://paasta-fake-cluster.yelp:5052' in output_text
assert 'http://paasta-fake-cluster.yelp:5053' in output_text
assert 'http://paasta-fake-cluster.yelp:%s' % DEFAULT_SYNAPSE_PORT in output_text
assert 'http://chronos.paasta-fake-cluster.yelp/' in output_text
assert 'http://mesos.paasta-fake-cluster.yelp/' in output_text
assert 'http://marathon.paasta-fake-cluster.yelp/' in output_text
with mock.patch('paasta_tools.cli.cmds.metastatus.load_system_paasta_config',
autospec=True) as mock_load_system_paasta_config:
mock_load_system_paasta_config.return_value = SystemPaastaConfig({
'dashboard_links': {
'fake_cluster': {
'URL': 'http://paasta-fake_cluster.yelp:5050',
},
},
}, 'fake_directory')
output_text = metastatus.get_cluster_dashboards('fake_cluster')
assert 'URL: http://paasta-fake_cluster.yelp:5050' in output_text

0 comments on commit 76e7c72

Please sign in to comment.