Fix 2.4.2 upgrade notes formatting refs #19330
[arvados.git] / apps / workbench / app / views / jobs / _show_log.html.erb
1 <%# Copyright (C) The Arvados Authors. All rights reserved.
2
3 SPDX-License-Identifier: AGPL-3.0 %>
4
5 <% if !@object.log %>
6
7 <div id="log_graph_div"
8      class="arv-log-event-listener"
9      style="display:none"
10      data-object-uuid="<%= @object.uuid %>"></div>
11
12 <pre id="event_log_div"
13      class="arv-log-event-listener arv-log-event-handler-append-logs arv-job-log-window"
14      data-object-uuid="<%= @object.uuid %>"
15   ><%= @object.stderr_log_lines(Rails.configuration.Workbench.RunningJobLogRecordsToFetch).join("\n") %>
16 </pre>
17
18 <%# Applying a long throttle suppresses the auto-refresh of this
19     partial that would normally be triggered by arv-log-event. %>
20 <div class="arv-log-refresh-control"
21      data-load-throttle="86486400000" <%# 1001 nights %>
22      ></div>
23
24 <% else %>
25
26 <script>
27 (function() {
28 var pagesize = 1000;
29 var logViewer = new List('log-viewer', {
30   valueNames: [ 'id', 'timestamp', 'taskid', 'message', 'type'],
31   page: pagesize
32 });
33
34 logViewer.page_offset = 0;
35 logViewer.on("updated", function() { updatePaging(".log-viewer-paging", logViewer, pagesize) } );
36 $(".log-viewer-page-up").on("click", function() { prevPage(logViewer, pagesize, ".log-viewer-paging"); return false; });
37 $(".log-viewer-page-down").on("click", function() { nextPage(logViewer, pagesize, ".log-viewer-paging"); return false; });
38
39 var taskState = newTaskState();
40
41 var makeFilter = function() {
42   var pass = [];
43   $(".toggle-filter, .radio-filter").each(function(i, e) {
44     if (e.checked) {
45       pass.push(e.id.substr(5));
46     }
47   });
48
49   return (function(item) {
50     var v = false;
51     if (item.values().taskid !== "") {
52       for (a in pass) {
53         if (pass[a] == "all-tasks") { v = true; }
54         else if (pass[a] == "successful-tasks" && taskState[item.values().taskid].outcome == "success") { v = true; }
55         else if (pass[a] == "failed-tasks" && taskState[item.values().taskid].outcome == "failure") { v = true; }
56       }
57     } else {
58       v = true;
59     }
60     for (a in pass) {
61       if (pass[a] == item.values().type) { return v; }
62     }
63     return false;
64   });
65 }
66
67 <% if @object.log and !@object.log.empty? %>
68   <% logcollection = Collection.find @object.log %>
69   <% if logcollection %>
70     var log_size = <%= logcollection.files[0][2] %>
71     var log_maxbytes = <%= Rails.configuration.Workbench.LogViewerMaxBytes %>;
72     var logcollection_url = '<%=j url_for logcollection %>/<%=j logcollection.files[0][1] %>';
73     $("#log-viewer-download-url").attr('href', logcollection_url);
74     $("#log-viewer-download-pane").show();
75     var headers = {};
76     if (log_size > log_maxbytes) {
77       headers['Range'] = 'bytes=0-' + (log_maxbytes - 1);
78     }
79     var ajax_opts = { dataType: 'text', headers: headers };
80     load_log();
81
82     function load_log() {
83         $.ajax(logcollection_url, ajax_opts).done(done).fail(fail);
84     }
85     function done(data, status, jqxhr) {
86         if (jqxhr.getResponseHeader('Content-Type').indexOf('application/json') === 0) {
87             // The browser won't allow a redirect-with-cookie response
88             // because keep-web isn't same-origin with us. Instead, we
89             // assure keep-web it's OK to respond with the content
90             // immediately by setting the token in the request body
91             // instead and adding disposition=attachment.
92             logcollection_url = JSON.parse(data).href;
93             var queryAt = logcollection_url.indexOf('?api_token=');
94             if (queryAt >= 0) {
95                 ajax_opts.method = 'POST';
96                 ajax_opts.data = {
97                     api_token: logcollection_url.slice(queryAt+11),
98                     disposition: 'attachment',
99                 };
100                 logcollection_url = logcollection_url.slice(0, queryAt);
101             }
102             return load_log();
103         }
104         logViewer.filter();
105         addToLogViewer(logViewer, data.split("\n"), taskState);
106         logViewer.filter(makeFilter());
107         content_range_hdr = jqxhr.getResponseHeader('Content-Range');
108         var v = content_range_hdr && content_range_hdr.match(/bytes \d+-(\d+)\/(.+)/);
109         short_log = v && (v[2] == '*' || parseInt(v[1]) + 1 < v[2]);
110         if (jqxhr.status == 206 && short_log) {
111             $("#log-viewer-overview").html(
112                 '<p>Showing only ' + data.length + ' bytes of this log.' +
113                     ' Timing information is unavailable since' +
114                     ' the full log was not retrieved.</p>'
115             );
116         } else {
117             generateJobOverview("#log-viewer-overview", logViewer, taskState);
118         }
119         $("#log-viewer .spinner").detach();
120     }
121     function fail(jqxhr, status, error) {
122         // TODO: tell the user about the error
123         console.log('load_log failed: status='+status+' error='+error);
124         $("#log-viewer .spinner").detach();
125     }
126   <% end %>
127 <% else %>
128   <%# Live log loading not implemented yet. %>
129 <% end %>
130
131 $(".toggle-filter, .radio-filter").on("change", function() {
132   logViewer.filter(makeFilter());
133 });
134
135 $("#filter-all").on("click", function() {
136   $(".toggle-filter").each(function(i, f) { f.checked = true; });
137   logViewer.filter(makeFilter());
138 });
139
140 $("#filter-none").on("click", function() {
141   $(".toggle-filter").each(function(i, f) { f.checked = false; console.log(f); });
142   logViewer.filter(makeFilter());
143 });
144
145 $("#sort-by-time").on("change", function() {
146   logViewer.sort("id", {sortFunction: sortById});
147 });
148
149 $("#sort-by-task").on("change", function() {
150   logViewer.sort("taskid", {sortFunction: sortByTask});
151 });
152
153 $("#sort-by-node").on("change", function() {
154   logViewer.sort("node", {sortFunction: sortByNode});
155 });
156
157 $("#set-show-failed-only").on("click", function() {
158   $("#sort-by-task").prop("checked", true);
159   $("#show-failed-tasks").prop("checked", true);
160   $("#show-crunch").prop("checked", false);
161   $("#show-task-dispatch").prop("checked", true);
162   $("#show-script-print").prop("checked", true);
163   $("#show-crunchstat").prop("checked", false);
164   logViewer.filter(makeFilter());
165   logViewer.sort("taskid", {sortFunction: sortByTask});
166 });
167
168 })();
169
170 </script>
171
172 <div id="log-viewer">
173
174   <h3>Summary</h3>
175   <p id="log-viewer-overview">
176     <% if !logcollection %>
177       The collection containing the job log was not found.
178     <% end %>
179   </p>
180
181   <p id="log-viewer-download-pane" style="display:none">
182     <a id="log-viewer-download-url" href="">Download the full log</a>
183   </p>
184
185   <div class="h3">Log
186
187     <span class="pull-right">
188       <% if @object.andand.tasks_summary.andand[:failed] and @object.tasks_summary[:failed] > 0 %>
189         <button id="set-show-failed-only" class="btn btn-danger">
190           Show failed task diagnostics only
191         </button>
192       <% end %>
193
194       <button id="filter-all" class="btn">
195         Select all
196       </button>
197       <button id="filter-none" class="btn">
198         Select none
199       </button>
200     </span>
201   </div>
202
203   <input class="search pull-right" style="margin-top: 1em" placeholder="Search" />
204
205   <div>
206     <div class="radio-inline log-viewer-button" style="margin-left: 10px">
207       <label><input id="sort-by-time" type="radio" name="sort-radio" checked> Sort by time</label>
208     </div>
209     <div class="radio-inline log-viewer-button">
210       <label><input id="sort-by-node" type="radio" name="sort-radio" > Sort by node</label>
211     </div>
212
213     <div class="radio-inline log-viewer-button">
214       <label><input id="sort-by-task" type="radio" name="sort-radio" > Sort by task</label>
215     </div>
216   </div>
217
218   <div>
219     <div class="radio-inline log-viewer-button" style="margin-left: 10px">
220       <label><input id="show-all-tasks" type="radio" name="show-tasks-group" checked="true" class="radio-filter"> Show all tasks</label>
221     </div>
222     <div class="radio-inline log-viewer-button">
223       <label><input id="show-successful-tasks" type="radio" name="show-tasks-group" class="radio-filter"> Only successful tasks</label>
224     </div>
225     <div class="radio-inline log-viewer-button">
226       <label><input id="show-failed-tasks" type="radio" name="show-tasks-group" class="radio-filter"> Only failed tasks</label>
227     </div>
228   </div>
229
230   <div>
231     <div class="checkbox-inline log-viewer-button" style="margin-left: 10px">
232       <label><input id="show-crunch" type="checkbox" checked="true" class="toggle-filter"> Show crunch diagnostics</label>
233     </div>
234     <div class="checkbox-inline log-viewer-button">
235       <label><input id="show-task-dispatch" type="checkbox" checked="true" class="toggle-filter"> Show task dispatch</label>
236     </div>
237     <div class="checkbox-inline log-viewer-button">
238       <label><input id="show-task-print" type="checkbox" checked="true" class="toggle-filter"> Show task diagnostics</label>
239     </div>
240     <div class="checkbox-inline log-viewer-button">
241       <label><input id="show-crunchstat" type="checkbox" checked="true" class="toggle-filter"> Show compute usage</label>
242     </div>
243
244   </div>
245
246   <div class="smart-scroll" data-smart-scroll-padding-bottom="50" style="margin-bottom: 0px">
247     <table class="log-viewer-table">
248       <thead>
249         <tr>
250           <th class="id" data-sort="id"></th>
251           <th class="timestamp" data-sort="timestamp">Timestamp</th>
252           <th class="node"  data-sort="node">Node</th>
253           <th class="slot"  data-sort="slot">Slot</th>
254           <th class="type" data-sort="type">Log type</th>
255           <th class="taskid"  data-sort="taskid">Task</th>
256           <th class="message" data-sort="message">Message</th>
257         </tr>
258       </thead>
259       <tbody class="list">
260         <tr>
261           <td class="id"></td>
262           <td class="timestamp"></td>
263           <td class="node"></td>
264           <td class="slot"></td>
265           <td class="type"></td>
266           <td class="taskid"></td>
267           <td class="message"></td>
268         </tr>
269       </tbody>
270     </table>
271
272     <% if @object.log and logcollection %>
273       <div class="spinner spinner-32px"></div>
274     <% end %>
275
276   </div>
277
278   <div class="log-viewer-paging-div" style="margin-bottom: -15px">
279     <a href="#" class="log-viewer-page-up"><span class='glyphicon glyphicon-arrow-up'></span></a>
280     <span class="log-viewer-paging"></span>
281     <a href="#" class="log-viewer-page-down"><span class='glyphicon glyphicon-arrow-down'></span></a>
282   </div>
283
284 </div>
285
286 <% end %>