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

Add Logging View #1080

Merged
merged 42 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
dba3552
Adding log view page to application
mfixstsci Nov 3, 2022
7fc743a
Forgot return in log view
mfixstsci Nov 3, 2022
04e87fa
fixing typo in url
mfixstsci Nov 3, 2022
f690f75
Adding glob import
mfixstsci Nov 3, 2022
eab0061
fixing logic for page to load
mfixstsci Nov 3, 2022
b231a1a
Closing logic
mfixstsci Nov 3, 2022
d424386
Adding log name to context and removing filename filter
mfixstsci Nov 3, 2022
080174e
Adding null case for log name
mfixstsci Nov 3, 2022
0b9115f
fix variable name typo
mfixstsci Nov 3, 2022
837ca01
go extra directory layer for logs in glob
mfixstsci Nov 3, 2022
a16e0ed
Add brackets to log_text variable
mfixstsci Nov 3, 2022
91703b1
Capping main tag and fixing text
mfixstsci Nov 3, 2022
56e8a8b
Trying new way to display log in app
mfixstsci Nov 4, 2022
079c4f1
Fixing typo
mfixstsci Nov 4, 2022
b3ae4f1
Fixing typo in list comprehension
mfixstsci Nov 4, 2022
4c7879f
switch key values for dropdown
mfixstsci Nov 4, 2022
46b6e24
Adding radio and submit buttons
mfixstsci Nov 4, 2022
37c72a9
Adding more fields to log view
mfixstsci Nov 7, 2022
a4239fe
Merge branch 'develop' into create-log-view
mfixstsci Jan 4, 2023
8687faa
Adding autocomplete field
mfixstsci Jan 5, 2023
4b08f9b
Setting dictionary to dev
mfixstsci Jan 5, 2023
7779dcd
adding list attribute to input
mfixstsci Jan 6, 2023
c79651a
Changes in UI
mfixstsci Jan 9, 2023
54a6508
Removing need to provide all logs and only showing logs based on serv…
mfixstsci Jan 9, 2023
e9bc7ca
Updating context, removing server mentions
mfixstsci Jan 9, 2023
4568856
Adding back some context to display log
mfixstsci Jan 9, 2023
c3b51d9
Removing except
mfixstsci Jan 10, 2023
ea7fe55
Adding jquery for validation
mfixstsci Jan 10, 2023
d268372
Enable Submit Button via Javascript
BradleySappington Jan 11, 2023
a367547
Closing form tag
mfixstsci Jan 12, 2023
3d7432f
Adding updates to button value
mfixstsci Jan 22, 2023
41a4e88
Moving server assignment logic
mfixstsci Jan 23, 2023
958d0cb
sort dictionary or logs
mfixstsci Jan 23, 2023
878ed44
Sorting again
mfixstsci Jan 23, 2023
cbdc7d0
Adding reverse kw
mfixstsci Jan 23, 2023
d47bb00
Merge branch 'develop' into create-log-view
mfixstsci Jan 23, 2023
d167cf8
Adding inst keyword to context
mfixstsci Jan 23, 2023
e5972aa
Moving instrument keyword
mfixstsci Jan 23, 2023
22fd5ac
removing typo
mfixstsci Jan 23, 2023
27fa941
Moving import
mfixstsci Jan 23, 2023
33470c2
Testing url logic
mfixstsci Jan 24, 2023
152b850
Removing testing context and adding socket call
mfixstsci Jan 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions jwql/website/apps/jwql/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@
<!--API-->
<li class="nav-item active">
<a class="nav-link" href={{ url('jwql:api') }}>API<span class="sr-only">(current)</span></a>
</li>
<!--Log View-->
<li class="nav-item active">
<a class="nav-link" href={{ url('jwql:log_view') }}>View Logs<span class="sr-only">(current)</span></a>
</li>
<!--Documentation-->
<li class="nav-item active">
Expand Down
73 changes: 73 additions & 0 deletions jwql/website/apps/jwql/templates/log_view.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{% extends "base.html" %}

{% block preamble %}

<title>Monitor Log Viewer - JWQL</title>

{% endblock %}

{% block content %}

<main role="main" class="container">
<h2>Explore JWQL monitoring logs through the web browser.</h2><hr>

<p align="justify">
This page allows users to load monitoring logs into the web browsers. This feature
obtains logs from all JWQL servers (ops, dev, and test).

<br><br>
</p>

<hr>
<form action="" method="post" id="logForm">
{{ csrf_input }}

<!--LOG SELECT DROPDOWN-->
<h4>Select JWQL Monitoring Log</h4>
<div class="col-6 mx-auto text-left mt-5">
<input id="log_select" type="text" list="logs" placeholder="Log Name" class="form-control">
<datalist id="logs">
{% for log_name in all_logs %}
<option id="{{ log_name }}" value="{{ log_name }}"></option>
{% endfor %}
</datalist>
</div>

<br>

<button id="log_submit" name="log_submit" class="btn btn-primary" onclick="GetSelectedTextValue()" type="submit" style="float: left;" disabled>Submit</button>
<br><br><br>

<!-- If log is passed, render log. -->
<!-- Log is not rendered when coming from home/monitor views -->
{% if log_text %}
<h4> {{ log_name|safe }} </h4><hr>
<!-- Show Logs here -->
<pre>
{{ log_text }}
</pre>
{% endif %}

<script type="text/javascript">
function GetSelectedTextValue() {
var log_value = document.getElementById("log_select").value;
document.getElementById("log_submit").value = log_value;
}
</script>

<script type="text/javascript">
const idInputField = document.getElementById('log_select');
var logsList = document.getElementById("logs");
idInputField.addEventListener('input', function () {
if (logsList.options.namedItem(this.value) != null) {
document.getElementById("log_submit").disabled = false;
} else {
document.getElementById("log_submit").disabled = true;
}
});
</script>

</form>
</main>

{% endblock %}
1 change: 1 addition & 0 deletions jwql/website/apps/jwql/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
path('edb/', views.engineering_database, name='edb'),
path('jwqldb/', views.jwqldb_table_viewer, name='jwqldb'),
path('jwqldb/<str:tablename_param>', views.jwqldb_table_viewer, name='jwqldb_table_viewer'),
path('log_view/', views.log_view, name='log_view'),
path('query_submit/', views.query_submit, name='query_submit'),
re_path(r'^(?P<inst>({}))/$'.format(instruments), views.instrument, name='instrument'),
re_path(r'^(?P<inst>({}))/archive/$'.format(instruments), views.archived_proposals, name='archive'),
Expand Down
45 changes: 45 additions & 0 deletions jwql/website/apps/jwql/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from collections import defaultdict
from copy import deepcopy
import csv
import glob
import logging
import os
import operator
Expand Down Expand Up @@ -746,6 +747,50 @@ def jwqldb_table_viewer(request, tablename_param=None):
return render(request, template, context)


def log_view(request):
"""Access JWQL monitoring logs from the web app.

Parameters
----------
request : HttpRequest object
Incoming request from the webpage

Returns
-------
HttpResponse object
Outgoing response sent to the webpage
"""

template = 'log_view.html'
log_path = get_config()['log_dir']
log_name = request.POST.get('log_submit', None)

full_uri = request.build_absolute_uri()

if 'dljwql' in full_uri:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this is something that would be useful to have as its own general function somewhere, or is there not enough use for it to warrant a separate function?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this was causing the issue with the production logs being show on the test server. I went ahead and changed it to use the socket library to get the hostname of the machine rather than the URL.

server = 'dev'
elif 'tljwql' in full_uri:
server = 'test'
else:
server = 'ops'

full_log_paths = sorted(glob.glob(os.path.join(log_path, server, '*', '*')), reverse=True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you may need more tests to verify you are on the correct server. "pljwql" is showing up on the test server.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead and used a different library for this portion of the app. I have it working successfully now!

full_log_paths = [log for log in full_log_paths if not os.path.basename(log).startswith('.')]
log_dictionary = {os.path.basename(path): path for path in full_log_paths}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dictionary comprehension! I had forgotten that was a thing. :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was super useful here.


if log_name:
with open(log_dictionary[log_name]) as f:
log_text = f.read()
else:
log_text = None

context = {'inst': '',
'all_logs': log_dictionary,
'log_text': log_text,
'log_name': log_name}

return render(request, template, context)

def not_found(request, *kwargs):
"""Generate a ``not_found`` page

Expand Down