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