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