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