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