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