Skip to content

Commit b957d65

Browse files
Create a DataTable for displaying transform logs (#75)
Why these changes are being introduced: * These changes are required in order to display the individual log files retrieved from each container. How this addresses that need: * Add a new route that renders a transform log in plain text * Update run route to retrieve tranform log filenames from new 'logs' directory * Update run.html Side effects of this change: * None Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/TIMX-368
1 parent 2eda03c commit b957d65

File tree

8 files changed

+51
-38
lines changed

8 files changed

+51
-38
lines changed

abdiff/webapp/app.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ def run(run_timestamp: str) -> str:
8282
run_directory = get_run_directory(run_timestamp)
8383
run_data = read_run_json(run_directory)
8484

85-
# load transform logs
86-
try:
87-
with open(Path(run_directory) / "transformed/logs.txt") as f:
88-
transform_logs = f.read()
89-
except FileNotFoundError:
90-
transform_logs = "'logs.txt' not found for transform logs"
85+
# get filenames of transform logs
86+
transform_logs = [
87+
os.path.basename(log_filepath)
88+
for log_filepath in glob.glob(f"{run_directory}/logs/*")
89+
]
9190

9291
return render_template(
9392
"run.html",
93+
run_timestamp=run_timestamp,
9494
run_data=run_data,
9595
run_json=json.dumps(run_data),
9696
transform_logs=transform_logs,
@@ -99,6 +99,17 @@ def run(run_timestamp: str) -> str:
9999
modified_fields=sorted(run_data["metrics"]["summary"]["fields_with_diffs"]),
100100
)
101101

102+
@app.route("/run/<run_timestamp>/log/<log_filename>")
103+
def transform_log(run_timestamp: str, log_filename: str) -> Response:
104+
run_directory = get_run_directory(run_timestamp)
105+
106+
try:
107+
with open(Path(run_directory) / "logs" / log_filename) as f:
108+
transform_logs = f.read()
109+
except FileNotFoundError:
110+
transform_logs = f"Log file '{log_filename}' not found."
111+
return Response(transform_logs, mimetype="text/plain")
112+
102113
@app.route("/run/<run_timestamp>/records/data", methods=["POST"])
103114
def records_data(run_timestamp: str) -> Response:
104115
"""Endpoint to provide data for Records table in Run view.

abdiff/webapp/templates/run.html

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,27 @@ <h3>Details</h3>
2121
</div>
2222

2323
<div class="row">
24-
<h3 data-bs-toggle="collapse" data-bs-target="#collapseLogs" role="button" aria-expanded="false" aria-controls="collapseLogs">Transform Logs ⤵</h3>
25-
<div class="collapse" id="collapseLogs">
26-
<pre><code>{{transform_logs}}</code></pre>
27-
</div>
24+
<h3>Transform Logs</h3>
25+
{% if transform_logs %}
26+
<table id="transformLogsTable" class="table">
27+
<thead>
28+
<tr>
29+
<th>Transform Log Filename</th>
30+
<th>Actions</th>
31+
</tr>
32+
</thead>
33+
<tbody>
34+
{% for log_filename in transform_logs %}
35+
<tr>
36+
<td>{{log_filename}}</td>
37+
<td><a href="/run/{{run_timestamp}}/log/{{log_filename}}" target="blank">View Log</a></td>
38+
</tr>
39+
{% endfor %}
40+
</tbody>
41+
</table>
42+
{% else %}
43+
<span>No transform logs were found.</span>
44+
{% endif %}
2845
</div>
2946

3047
<div class="row">
@@ -90,6 +107,9 @@ <h3>Records</h3>
90107
</script>
91108
<script src="{{ url_for('static', filename='jquery-3.6.0.min.js') }}"></script>
92109
<script src="{{ url_for('static', filename='jquery.dataTables.min.js') }}"></script>
110+
<script>
111+
new DataTable('#transformLogsTable');
112+
</script>
93113
<script>
94114
$(document).ready(function() {
95115
var table = $('#recordsTable').DataTable( {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This text file represents a transform log file.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This text file represents a transform log file.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This text file represents a transform log file.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This text file represents a transform log file.

tests/fixtures/jobs/example-job-1/runs/2024-01-01_12-00-00/transformed/logs.txt

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/test_webapp.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,12 @@ def test_run_route_load_transformation_logs(
5656
_response = webapp_client.get(f"/run/{webapp_run_timestamp}")
5757
args, kwargs = mock_render.call_args
5858

59-
assert (
60-
"docker_image: transmogrifier-best-job-008e20c:latest | source: alma | "
61-
"input_file: s3://timdex-extract-prod-300442551476/alma/alma-2024-08-29-daily"
62-
"-extracted-records-to-index.xml" in kwargs["transform_logs"]
63-
)
64-
assert (
65-
"docker_image: transmogrifier-best-job-395e612:latest | source: alma | "
66-
"input_file: s3://timdex-extract-prod-300442551476/alma/alma-2024-08-29-daily"
67-
"-extracted-records-to-index.xml" in kwargs["transform_logs"]
68-
)
59+
assert set(kwargs["transform_logs"]) == {
60+
"alma-2024-08-29-daily-aaaaaa123456-logs.txt",
61+
"alma-2024-08-29-daily-bbbbbb123456-logs.txt",
62+
"dspace-2024-10-14-daily-cccccc123456-logs.txt",
63+
"dspace-2024-10-14-daily-dddddd123456-logs.txt",
64+
}
6965

7066

7167
def test_shutdown_route_success(caplog, webapp_client):

0 commit comments

Comments
 (0)