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