From 52fcb291c008606e8e2b3e5ceede2bf7de7f83b1 Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Wed, 15 Nov 2017 15:16:21 +0100 Subject: [PATCH 1/4] Add AutoRefreshTimeInterval setting --- i18n/messages-en.xtb | 2 ++ i18n/messages-ja.xtb | 2 ++ i18n/messages-zh-tw.xtb | 2 ++ i18n/messages-zh.xtb | 2 ++ src/app/backend/settings/api/types.go | 10 +++++--- src/app/externs/backendapi.js | 3 ++- src/app/frontend/chrome/chrome.html | 7 +++--- src/app/frontend/common/settings/service.js | 15 +++++++++++ src/app/frontend/logs/component.js | 28 +++++++++++++++------ src/app/frontend/logs/module.js | 3 +++ src/app/frontend/settings/controller.js | 1 + src/app/frontend/settings/settings.html | 15 +++++++++++ 12 files changed, 74 insertions(+), 16 deletions(-) diff --git a/i18n/messages-en.xtb b/i18n/messages-en.xtb index 1d095a6fa0c6..28d36f54cebe 100644 --- a/i18n/messages-en.xtb +++ b/i18n/messages-en.xtb @@ -879,6 +879,8 @@ Items per page Max number of items that can be displayed on each list page Save + Auto-refresh time interval + Number of seconds between every auto-refresh of logs Shell in in Stateful Set diff --git a/i18n/messages-ja.xtb b/i18n/messages-ja.xtb index ee5725140b52..c45e48a63581 100644 --- a/i18n/messages-ja.xtb +++ b/i18n/messages-ja.xtb @@ -885,6 +885,8 @@ Items per page Max number of items that can be displayed on each list page Save + Auto-refresh time interval + Number of seconds between every auto-refresh of logs Shell in in ステートフルセット diff --git a/i18n/messages-zh-tw.xtb b/i18n/messages-zh-tw.xtb index a93e489bdded..bf9a75bc7dcf 100644 --- a/i18n/messages-zh-tw.xtb +++ b/i18n/messages-zh-tw.xtb @@ -877,6 +877,8 @@ Items per page Max number of items that can be displayed on each list page Save + Auto-refresh time interval + Number of seconds between every auto-refresh of logs 指令列 Stateful Set diff --git a/i18n/messages-zh.xtb b/i18n/messages-zh.xtb index 45c319a2187a..dec7af09b142 100644 --- a/i18n/messages-zh.xtb +++ b/i18n/messages-zh.xtb @@ -879,6 +879,8 @@ Items per page Max number of items that can be displayed on each list page Save + Auto-refresh time interval + Number of seconds between every auto-refresh of logs 命令行 有状态副本集 diff --git a/src/app/backend/settings/api/types.go b/src/app/backend/settings/api/types.go index cdf7e14b8472..3142a355a3d7 100644 --- a/src/app/backend/settings/api/types.go +++ b/src/app/backend/settings/api/types.go @@ -53,8 +53,9 @@ type SettingsManager interface { // Settings is a single instance of settings without context. type Settings struct { - ClusterName string `json:"clusterName"` - ItemsPerPage int `json:"itemsPerPage"` + ClusterName string `json:"clusterName"` + ItemsPerPage int `json:"itemsPerPage"` + AutoRefreshTimeInterval int `json:"autoRefreshTimeInterval"` } // Marshal settings into JSON object. @@ -72,8 +73,9 @@ func Unmarshal(data string) (*Settings, error) { // defaultSettings contains default values for every setting. var defaultSettings = Settings{ - ClusterName: "", - ItemsPerPage: 10, + ClusterName: "", + ItemsPerPage: 10, + AutoRefreshTimeInterval: 5, } // GetDefaultSettings returns settings structure, that should be used if there are no diff --git a/src/app/externs/backendapi.js b/src/app/externs/backendapi.js index 9c756cacd690..75a25e710794 100644 --- a/src/app/externs/backendapi.js +++ b/src/app/externs/backendapi.js @@ -1463,7 +1463,8 @@ backendApi.Controller; /** * @typedef {{ * clusterName: string, - * itemsPerPage: number + * itemsPerPage: number, + * autoRefreshTimeInterval: number * }} */ backendApi.Settings; diff --git a/src/app/frontend/chrome/chrome.html b/src/app/frontend/chrome/chrome.html index 595772bb5a99..857947759315 100644 --- a/src/app/frontend/chrome/chrome.html +++ b/src/app/frontend/chrome/chrome.html @@ -17,12 +17,13 @@
diff --git a/src/app/frontend/common/settings/service.js b/src/app/frontend/common/settings/service.js index e75c96bd5f36..66279b9b9186 100644 --- a/src/app/frontend/common/settings/service.js +++ b/src/app/frontend/common/settings/service.js @@ -89,4 +89,19 @@ export class SettingsService { } return itemsPerPage; } + + /** + * Gets currently loaded auto refresh time interval parameter. To load changes from the backend + * use load() function. + * + * @export + * @return {number} + */ + getAutoRefreshTimeInterval() { + let autoRefreshTimeInterval = 5; + if (this.isInitialized_()) { + autoRefreshTimeInterval = this.global_.autoRefreshTimeInterval; + } + return autoRefreshTimeInterval; + } } diff --git a/src/app/frontend/logs/component.js b/src/app/frontend/logs/component.js index 8481598cbd8a..e091e874b4df 100644 --- a/src/app/frontend/logs/component.js +++ b/src/app/frontend/logs/component.js @@ -37,9 +37,11 @@ export class LogsController { * @param {!angular.$interval} $interval * @param {!angular.$log} $log * @param {!../common/errorhandling/dialog.ErrorDialog} errorDialog + * @param {!../common/settings/service.SettingsService} kdSettingsService * @ngInject */ - constructor(logsService, $sce, $document, $resource, $interval, $log, errorDialog) { + constructor( + logsService, $sce, $document, $resource, $interval, $log, errorDialog, kdSettingsService) { /** @private {!angular.$sce} */ this.sce_ = $sce; @@ -105,6 +107,12 @@ export class LogsController { /** @export {number} Refresh interval in miliseconds. */ this.refreshInterval = 5000; + + /** @private {boolean} */ + this.isIntervalRegistered_ = false; + + /** @private {!../common/settings/service.SettingsService} */ + this.settingsService_ = kdSettingsService; } @@ -114,7 +122,7 @@ export class LogsController { this.stateParams_ = this.$transition$.params(); this.updateUiModel(this.podLogs); this.topIndex = this.podLogs.logs.length; - this.registerIntervalFunction_(); + this.refreshInterval = this.settingsService_.getAutoRefreshTimeInterval() * 1000; } /** @@ -123,12 +131,15 @@ export class LogsController { * @private */ registerIntervalFunction_() { - this.interval_(() => { - if (this.logsService.getFollowing()) { - this.loadNewest(); - this.log_.info('Automatically refreshed logs'); - } - }, this.refreshInterval); + if (!this.isIntervalRegistered_) { + this.interval_(() => { + if (this.logsService.getFollowing()) { + this.loadNewest(); + this.log_.info('Automatically refreshed logs'); + } + }, this.refreshInterval); + this.isIntervalRegistered_ = true; + } } @@ -176,6 +187,7 @@ export class LogsController { * @export */ toggleLogFollow() { + this.registerIntervalFunction_(); this.logsService.setFollowing(); if (this.logsService.getFollowing()) { this.loadNewest(); diff --git a/src/app/frontend/logs/module.js b/src/app/frontend/logs/module.js index a00eb6223956..29bc38bbd45a 100644 --- a/src/app/frontend/logs/module.js +++ b/src/app/frontend/logs/module.js @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +import settingsServiceModule from '../common/settings/module'; + import {logsComponent} from './component'; import {LogsService} from './service'; import stateConfig from './stateconfig'; @@ -26,6 +28,7 @@ export default angular [ 'ngResource', 'ui.router', + settingsServiceModule.name, ]) .service('logsService', LogsService) .component('kdLogs', logsComponent) diff --git a/src/app/frontend/settings/controller.js b/src/app/frontend/settings/controller.js index dbf885c683e0..6c331326cc84 100644 --- a/src/app/frontend/settings/controller.js +++ b/src/app/frontend/settings/controller.js @@ -93,6 +93,7 @@ export class SettingsController { let settings = { clusterName: this.global.clusterName, itemsPerPage: this.global.itemsPerPage, + autoRefreshTimeInterval: this.global.autoRefreshTimeInterval, }; /** @type {!angular.Resource} */ diff --git a/src/app/frontend/settings/settings.html b/src/app/frontend/settings/settings.html index 914768e2c651..9620754635a3 100644 --- a/src/app/frontend/settings/settings.html +++ b/src/app/frontend/settings/settings.html @@ -45,6 +45,21 @@ + + + + +
{{$ctrl.global.autoRefreshTimeInterval}}
+
+
+
Date: Fri, 17 Nov 2017 09:18:36 +0100 Subject: [PATCH 2/4] Apply review suggestions --- src/app/frontend/logs/component.js | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/app/frontend/logs/component.js b/src/app/frontend/logs/component.js index e091e874b4df..2fbf28532cd0 100644 --- a/src/app/frontend/logs/component.js +++ b/src/app/frontend/logs/component.js @@ -108,8 +108,8 @@ export class LogsController { /** @export {number} Refresh interval in miliseconds. */ this.refreshInterval = 5000; - /** @private {boolean} */ - this.isIntervalRegistered_ = false; + /** @private {!angular.$q.Promise|null} */ + this.intervalPromise_ = null; /** @private {!../common/settings/service.SettingsService} */ this.settingsService_ = kdSettingsService; @@ -126,23 +126,23 @@ export class LogsController { } /** - * Registers interval function used to automatically refresh logs. + * Starts and stops interval function used to automatically refresh logs. * * @private */ - registerIntervalFunction_() { - if (!this.isIntervalRegistered_) { - this.interval_(() => { + toggleIntervalFunction_() { + if (this.intervalPromise_) { + this.interval_.cancel(this.intervalPromise_); + this.intervalPromise_ = null; + } else { + this.intervalPromise_ = this.interval_(() => { if (this.logsService.getFollowing()) { this.loadNewest(); - this.log_.info('Automatically refreshed logs'); } }, this.refreshInterval); - this.isIntervalRegistered_ = true; } } - /** * Loads maxLogSize oldest lines of logs. * @export @@ -187,7 +187,7 @@ export class LogsController { * @export */ toggleLogFollow() { - this.registerIntervalFunction_(); + this.toggleIntervalFunction_(); this.logsService.setFollowing(); if (this.logsService.getFollowing()) { this.loadNewest(); @@ -271,9 +271,7 @@ export class LogsController { // add timestamp if needed let showTimestamp = this.logsService.getShowTimestamp(); - let logLine = showTimestamp ? `${line.timestamp} ${escapedContent}` : escapedContent; - - return logLine; + return showTimestamp ? `${line.timestamp} ${escapedContent}` : escapedContent; } /** From c008c4c3ecc23206b906f4407428e2844b7fa362 Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Fri, 17 Nov 2017 09:19:19 +0100 Subject: [PATCH 3/4] Fix gulp serve:prod --- src/app/frontend/logs/component.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/app/frontend/logs/component.js b/src/app/frontend/logs/component.js index 2fbf28532cd0..0139bd6b5106 100644 --- a/src/app/frontend/logs/component.js +++ b/src/app/frontend/logs/component.js @@ -35,13 +35,12 @@ export class LogsController { * @param {!angular.$document} $document * @param {!angular.$resource} $resource * @param {!angular.$interval} $interval - * @param {!angular.$log} $log * @param {!../common/errorhandling/dialog.ErrorDialog} errorDialog * @param {!../common/settings/service.SettingsService} kdSettingsService * @ngInject */ constructor( - logsService, $sce, $document, $resource, $interval, $log, errorDialog, kdSettingsService) { + logsService, $sce, $document, $resource, $interval, errorDialog, kdSettingsService) { /** @private {!angular.$sce} */ this.sce_ = $sce; @@ -54,9 +53,6 @@ export class LogsController { /** @private {!angular.$interval} */ this.interval_ = $interval; - /** @private {!angular.$log} */ - this.log_ = $log; - /** @export {!./service.LogsService} */ this.logsService = logsService; From 27a31a17147908c74e335ce01f5503d283e99e60 Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Fri, 17 Nov 2017 13:24:02 +0100 Subject: [PATCH 4/4] Apply review suggestions --- src/app/frontend/logs/component.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/app/frontend/logs/component.js b/src/app/frontend/logs/component.js index 0139bd6b5106..d1b60faad543 100644 --- a/src/app/frontend/logs/component.js +++ b/src/app/frontend/logs/component.js @@ -39,8 +39,7 @@ export class LogsController { * @param {!../common/settings/service.SettingsService} kdSettingsService * @ngInject */ - constructor( - logsService, $sce, $document, $resource, $interval, errorDialog, kdSettingsService) { + constructor(logsService, $sce, $document, $resource, $interval, errorDialog, kdSettingsService) { /** @private {!angular.$sce} */ this.sce_ = $sce; @@ -111,7 +110,6 @@ export class LogsController { this.settingsService_ = kdSettingsService; } - $onInit() { this.container = this.podLogs.info.containerName; this.pod = this.podLogs.info.podName; @@ -121,6 +119,13 @@ export class LogsController { this.refreshInterval = this.settingsService_.getAutoRefreshTimeInterval() * 1000; } + $onDestroy() { + if (this.intervalPromise_) { + this.interval_.cancel(this.intervalPromise_); + this.intervalPromise_ = null; + } + } + /** * Starts and stops interval function used to automatically refresh logs. * @@ -131,11 +136,7 @@ export class LogsController { this.interval_.cancel(this.intervalPromise_); this.intervalPromise_ = null; } else { - this.intervalPromise_ = this.interval_(() => { - if (this.logsService.getFollowing()) { - this.loadNewest(); - } - }, this.refreshInterval); + this.intervalPromise_ = this.interval_(() => this.loadNewest(), this.refreshInterval); } } @@ -183,11 +184,8 @@ export class LogsController { * @export */ toggleLogFollow() { - this.toggleIntervalFunction_(); this.logsService.setFollowing(); - if (this.logsService.getFollowing()) { - this.loadNewest(); - } + this.toggleIntervalFunction_(); } /**