960d43e70b
Container log live-stream review fixes (frontend only): - F1/F2: demux Docker's multiplexed (non-TTY) stream at the BYTE level by frame length, decoding only payloads. Previously the stream was text-decoded whole and cut on '\n' before stripping 8-byte headers, which desynced when a length low-byte was 0x0a or a header byte was >= 0x80. streamContainerLogs now hands the processor raw Uint8Array chunks; createLogStreamProcessor is rewritten to parse frames, concatenate payloads, split lines on 0x0a, and UTF-8-decode complete lines. formatLogs is called without stripHeaders so headers are not stripped twice. Added explicit byte-frame tests. - F3: request timestamps=1 internally and resume reconnects from the parsed RFC3339 timestamp of the last line (not client wall-clock); strip the prefix before display when the user's timestamps toggle is off; dedup the inclusive `since` boundary lines on reconnect. - F4: run the fetch stream URL through dockerMaxAPIVersionInterceptor so it matches the axios getContainerLogs version pinning. - F5: notify on stream error once per reconnect loop, not every 3s retry. - F6: resuming Live no longer wipes the buffer (startStream(false)) and continues from `since`. - F7: service/task logs still poll; documented the re-render limitation (out of scope: issue #2 is container logs). - F8: flush the trailing partial line on the error path too (parity with onEnd). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
89 lines
2.8 KiB
JavaScript
89 lines
2.8 KiB
JavaScript
import moment from 'moment';
|
|
|
|
angular.module('portainer.docker').controller('TaskLogsController', [
|
|
'$scope',
|
|
'$transition$',
|
|
'$interval',
|
|
'TaskService',
|
|
'ServiceService',
|
|
'Notifications',
|
|
function ($scope, $transition$, $interval, TaskService, ServiceService, Notifications) {
|
|
$scope.state = {
|
|
refreshRate: 3,
|
|
lineCount: 100,
|
|
sinceTimestamp: '',
|
|
displayTimestamps: false,
|
|
};
|
|
|
|
$scope.changeLogCollection = function (logCollectionStatus) {
|
|
if (!logCollectionStatus) {
|
|
stopRepeater();
|
|
} else {
|
|
setUpdateRepeater();
|
|
}
|
|
};
|
|
|
|
$scope.$on('$destroy', function () {
|
|
stopRepeater();
|
|
});
|
|
|
|
function stopRepeater() {
|
|
var repeater = $scope.repeater;
|
|
if (angular.isDefined(repeater)) {
|
|
$interval.cancel(repeater);
|
|
}
|
|
}
|
|
|
|
function setUpdateRepeater() {
|
|
var refreshRate = $scope.state.refreshRate;
|
|
$scope.repeater = $interval(function () {
|
|
TaskService.logs($transition$.params().id, 1, 1, $scope.state.displayTimestamps ? 1 : 0, moment($scope.state.sinceTimestamp).unix(), $scope.state.lineCount)
|
|
.then(function success(data) {
|
|
// NOTE: task logs still poll and replace the whole array. Because
|
|
// formatLogs assigns fresh line ids per poll, `track by log.id` in
|
|
// the viewer re-renders every row each poll (a live text selection
|
|
// can collapse). The append-only live stream that fixes this exists
|
|
// only for container logs (issue #2); converting service/task logs
|
|
// to a live stream is out of scope here.
|
|
$scope.logs = data;
|
|
})
|
|
.catch(function error(err) {
|
|
stopRepeater();
|
|
Notifications.error('Failure', err, 'Unable to retrieve task logs');
|
|
});
|
|
}, refreshRate * 1000);
|
|
}
|
|
|
|
function startLogPolling() {
|
|
TaskService.logs($transition$.params().id, 1, 1, $scope.state.displayTimestamps ? 1 : 0, moment($scope.state.sinceTimestamp).unix(), $scope.state.lineCount)
|
|
.then(function success(data) {
|
|
$scope.logs = data;
|
|
setUpdateRepeater();
|
|
})
|
|
.catch(function error(err) {
|
|
stopRepeater();
|
|
Notifications.error('Failure', err, 'Unable to retrieve task logs');
|
|
});
|
|
}
|
|
|
|
function initView() {
|
|
TaskService.task($transition$.params().id)
|
|
.then(function success(data) {
|
|
var task = data;
|
|
$scope.task = task;
|
|
return ServiceService.service(task.ServiceId);
|
|
})
|
|
.then(function success(data) {
|
|
var service = data;
|
|
$scope.service = service;
|
|
startLogPolling();
|
|
})
|
|
.catch(function error(err) {
|
|
Notifications.error('Failure', err, 'Unable to retrieve task details');
|
|
});
|
|
}
|
|
|
|
initView();
|
|
},
|
|
]);
|