Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clusters card on home page not tied to underlying API server #110

Open
adamhgriffith-uofu opened this issue Feb 25, 2022 · 4 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@adamhgriffith-uofu
Copy link
Contributor

adamhgriffith-uofu commented Feb 25, 2022

Steps to reproduce

  1. Create a Portal instance where SLATE_API_ENDPOINT = 'https://api.dev.slateci.io' in portal.conf.
  2. Log into the Portal instance.
  3. Note the content of the Clusters card on the home page and how production clusters are listed.
  4. Click Clusters on the left navigation.
  5. Note the correct set of SLATE clusters registered with the development API server.

Suggested fix

Update the Clusters card on the home page to display a subset of the clusters registered with the underlying API server.

Screenshot

Screenshot_2022-06-01_15-53-46

@adamhgriffith-uofu adamhgriffith-uofu added the enhancement New feature or request label Feb 25, 2022
@adamhgriffith-uofu adamhgriffith-uofu added the good first issue Good for newcomers label Jun 1, 2022
@adamhgriffith-uofu adamhgriffith-uofu added bug Something isn't working and removed enhancement New feature or request labels Aug 4, 2022
@adamhgriffith-uofu
Copy link
Contributor Author

This is causing logs noise in the non-production Portal applications when viewing the Dashboard page.

ERROR HIT: 'reachable'
[2022-08-04 14:30:44,774] ERROR in views_error_handling: Thu Aug  4 14:30:44 2022 Traceback occurred:
  File "/home/agriffith/.conda/envs/slate-portal/lib/python3.6/site-packages/flask/app.py", line 1513, in full_dispatch_request
    rv = self.dispatch_request()
n  File "/home/agriffith/.conda/envs/slate-portal/lib/python3.6/site-packages/flask/app.py", line 1499, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
n  File "/home/agriffith/repos/slate-portal/portal/decorators.py", line 34, in decorated_function
    return fn(*args, **kwargs)
n  File "portal/views/views_clusters.py", line 156, in get_cluster_status_xhr
    cluster_status = get_cluster_status(cluster_name)
n  File "portal/views/views_clusters.py", line 171, in get_cluster_status
    cluster_status = cluster_status_query['reachable']

Traceback completed
127.0.0.1 - - [04/Aug/2022 14:30:44] "GET /cluster-status-xhr/uutah-prod HTTP/1.1" 200 -
ERROR HIT: 'reachable'
[2022-08-04 14:30:44,786] ERROR in views_error_handling: Thu Aug  4 14:30:44 2022 Traceback occurred:
  File "/home/agriffith/.conda/envs/slate-portal/lib/python3.6/site-packages/flask/app.py", line 1513, in full_dispatch_request
    rv = self.dispatch_request()
n  File "/home/agriffith/.conda/envs/slate-portal/lib/python3.6/site-packages/flask/app.py", line 1499, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
n  File "/home/agriffith/repos/slate-portal/portal/decorators.py", line 34, in decorated_function
    return fn(*args, **kwargs)
n  File "portal/views/views_clusters.py", line 156, in get_cluster_status_xhr
    cluster_status = get_cluster_status(cluster_name)
n  File "portal/views/views_clusters.py", line 171, in get_cluster_status
    cluster_status = cluster_status_query['reachable']

Traceback completed
127.0.0.1 - - [04/Aug/2022 14:30:44] "GET /cluster-status-xhr/umich-prod HTTP/1.1" 200 -
ERROR HIT: 'reachable'
[2022-08-04 14:30:44,800] ERROR in views_error_handling: Thu Aug  4 14:30:44 2022 Traceback occurred:
  File "/home/agriffith/.conda/envs/slate-portal/lib/python3.6/site-packages/flask/app.py", line 1513, in full_dispatch_request
    rv = self.dispatch_request()
n  File "/home/agriffith/.conda/envs/slate-portal/lib/python3.6/site-packages/flask/app.py", line 1499, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
n  File "/home/agriffith/repos/slate-portal/portal/decorators.py", line 34, in decorated_function
    return fn(*args, **kwargs)
n  File "portal/views/views_clusters.py", line 156, in get_cluster_status_xhr
    cluster_status = get_cluster_status(cluster_name)
n  File "portal/views/views_clusters.py", line 171, in get_cluster_status
    cluster_status = cluster_status_query['reachable']

@adamhgriffith-uofu
Copy link
Contributor Author

Doing more digging, in portal/views.py is the following:

if request.method == 'GET':
        print("Session from dashboard: {}".format(session))
        if session["slate_portal_user"]:
            # single-user mode
            clusters = ["my-cluster"]
        else:
            clusters = ["uutah-prod", "uchicago-prod", "umich-prod"]

        with open('portal/static/news.md', "r") as file:
            news = file.read()
        # This json conversion is for JS to read on the frontend
        clusters_list = json.dumps(clusters)

        return render_template('dashboard.html', clusters=clusters,
                                news=news, clusters_list=clusters_list)

Since clusters is hard-coded this causes issues with the Vue expression in portal/templates/dashboard.html:

new Vue({
	el: '#clusters-card',
	data () {
    return {
      clusters: {},
      loading: true,
      failed: false
    }
	},
	async mounted() {
    let status_results = [];
    await Promise.all(clusters.map(cluster =>
      axios.get('/cluster-status-xhr/' + cluster).then(response => {
        status_results.push([cluster, response.data]);
        })
      ));
    this.clusters = status_results;
		}
  });

where we discover an API call in portal/views/views_clusters.py to clusters that are not registered with the slate_api_endpoint:

@app.route('/cluster-status-xhr/<cluster_name>', methods=['GET'])
@authenticated
def get_cluster_status_xhr(cluster_name):
    """
    - List Clusters Registered on SLATE (json response)
    """
    if request.method == 'GET':
        cluster_status = get_cluster_status(cluster_name)
        # print(cluster_status)
        return jsonify(cluster_status)


def get_cluster_status(cluster_name):
    """
    - Get Clusters and Status on SLATE
    """
    access_token = get_user_access_token(session)
    query = {'token': access_token, 'cache': 'cache'}

    cluster_status_query = requests.get(
            slate_api_endpoint + '/v1alpha3/clusters/' + cluster_name + '/ping', params=query)
    cluster_status_query = cluster_status_query.json()
    cluster_status = cluster_status_query['reachable']
    
    return cluster_status

@adamhgriffith-uofu adamhgriffith-uofu removed the good first issue Good for newcomers label Aug 4, 2022
@adamhgriffith-uofu
Copy link
Contributor Author

I could make the errors go away for right now without "truly" fixing the issue by doing the following in portal/views.py:

if session["slate_portal_user"]:
    # single-user mode
    clusters = ["my-cluster"]
elif slate_api_endpoint == "https://api.dev.slateci.io":
    clusters = ["river-dev-fp"]
elif slate_api_endpoint == "https://api.staging.slateci.io":
    clusters = ["uutah-dev"]
else:
    clusters = ["uutah-prod", "uchicago-prod", "umich-prod"]

@jstidd
Copy link
Contributor

jstidd commented Aug 4, 2022

You're right that the clusters on the card should not be hardcoded, but which clusters do we show? The first 5 in the list? The first five may not be the ones we want to highlight. Maybe it can be split, if in production it shows the main three production sites, but in staging and dev it shows the first five. Just some thoughts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants