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