From 58ab322d5e59a1a376a222312cef0bc4376c1e6a Mon Sep 17 00:00:00 2001 From: Allan Zimmermann Date: Tue, 26 Apr 2022 13:05:24 +0200 Subject: [PATCH 1/4] add skip collection for house keeping --- OpenFlow/src/Config.ts | 2 ++ OpenFlow/src/Messages/Message.ts | 42 +++++++++++++++++++++++++++----- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/OpenFlow/src/Config.ts b/OpenFlow/src/Config.ts index d3193378..f85203a8 100644 --- a/OpenFlow/src/Config.ts +++ b/OpenFlow/src/Config.ts @@ -59,6 +59,7 @@ export class Config { Config.auto_hourly_housekeeping = Config.parseBoolean(Config.getEnv("auto_hourly_housekeeping", "false")); Config.housekeeping_update_usage_hourly = Config.parseBoolean(Config.getEnv("housekeeping_update_usage_hourly", "false")); Config.housekeeping_update_usersize_hourly = Config.parseBoolean(Config.getEnv("housekeeping_update_usersize_hourly", "true")); + Config.housekeeping_skip_collections = Config.getEnv("housekeeping_skip_collections", ""); Config.workitem_queue_monitoring_enabled = Config.parseBoolean(Config.getEnv("workitem_queue_monitoring_enabled", "true")); Config.workitem_queue_monitoring_interval = parseInt(Config.getEnv("workitem_queue_monitoring_interval", (30 * 1000).toString())); // 30 sec @@ -237,6 +238,7 @@ export class Config { public static auto_hourly_housekeeping: boolean = Config.parseBoolean(Config.getEnv("auto_hourly_housekeeping", "true")); public static housekeeping_update_usage_hourly: boolean = Config.parseBoolean(Config.getEnv("housekeeping_update_usage_hourly", "false")); public static housekeeping_update_usersize_hourly: boolean = Config.parseBoolean(Config.getEnv("housekeeping_update_usersize_hourly", "true")); + public static housekeeping_skip_collections: string = Config.getEnv("housekeeping_skip_collections", ""); public static workitem_queue_monitoring_enabled: boolean = Config.parseBoolean(Config.getEnv("workitem_queue_monitoring_enabled", "true")); public static workitem_queue_monitoring_interval: number = parseInt(Config.getEnv("workitem_queue_monitoring_interval", (30 * 1000).toString())); // 30 sec diff --git a/OpenFlow/src/Messages/Message.ts b/OpenFlow/src/Messages/Message.ts index c19f8c78..8a29d54e 100644 --- a/OpenFlow/src/Messages/Message.ts +++ b/OpenFlow/src/Messages/Message.ts @@ -138,7 +138,7 @@ export class Message { await this.GetNoderedInstance(span); break; case "housekeeping": - await this.Housekeeping(false, false, false, span); + await this.Housekeeping(span); break; case "updateworkitemqueue": await this.UpdateWorkitemQueue(span); @@ -656,10 +656,7 @@ export class Message { if (Config.enable_openflow_amqp) { cli.Send(await QueueClient.SendForProcessing(this, this.priority)); } else { - // await this.Housekeeping(false, false, false, span); - Message.lastHouseKeeping = null; - var msg = JSON.parse(this.data); - await this.Housekeeping(msg.skipnodered, msg.skipcalculatesize, msg.skipupdateusersize, span); + await this.Housekeeping(span); cli.Send(this); } break; @@ -3559,7 +3556,33 @@ export class Message { if (diffminutes < 60) return false; return true; } - public async Housekeeping(skipNodered: boolean, skipCalculateSize: boolean, skipUpdateUserSize: boolean, parent: Span): Promise { + private async Housekeeping(parent: Span): Promise { + this.Reply(); + const span: Span = Logger.otel.startSubSpan("message.GetNoderedInstance", parent); + let msg: any; + try { + msg = JSON.parse(this.data); + Message.lastHouseKeeping = null; + if (NoderedUtil.IsNullEmpty(msg.skipnodered)) msg.skipnodered = false; + if (NoderedUtil.IsNullEmpty(msg.skipcalculatesize)) msg.skipcalculatesize = false; + if (NoderedUtil.IsNullEmpty(msg.skipupdateusersize)) msg.skipupdateusersize = false; + await this._Housekeeping(msg.skipnodered, msg.skipcalculatesize, msg.skipupdateusersize, span); + } catch (error) { + span?.recordException(error); + this.data = ""; + await handleError(null, error); + if (msg !== null && msg !== undefined) msg.error = error.message ? error.message : error; + } + try { + this.data = JSON.stringify(msg); + } catch (error) { + span?.recordException(error); + this.data = ""; + await handleError(null, error); + } + Logger.otel.endSpan(span); + } + public async _Housekeeping(skipNodered: boolean, skipCalculateSize: boolean, skipUpdateUserSize: boolean, parent: Span): Promise { if (Message.lastHouseKeeping == null) { Message.lastHouseKeeping = new Date(); Message.lastHouseKeeping.setDate(Message.lastHouseKeeping.getDate() - 1); @@ -3764,8 +3787,15 @@ export class Message { collections = collections.filter(x => x.name.indexOf("system.") === -1); let totalusage = 0; let index = 0; + let skip_collections = []; + if (!NoderedUtil.IsNullEmpty(Config.housekeeping_skip_collections)) skip_collections = Config.housekeeping_skip_collections.split(",") for (let col of collections) { if (col.name == "fs.chunks") continue; + if (skip_collections.indexOf(col.name) > -1) { + Logger.instanse.debug("[housekeeping][" + col.name + "] skipped due to housekeeping_skip_collections setting"); + continue; + } + index++; let aggregates: any = [ { From 603eb04c6394d31b76764bae1cf5294badf8b7c1 Mon Sep 17 00:00:00 2001 From: Allan Zimmermann Date: Tue, 26 Apr 2022 13:05:43 +0200 Subject: [PATCH 2/4] add drop collection and settings for housekeeping --- OpenFlowNodeRED/src/nodered/nodes/api.html | 62 +++++++++++++++++++ OpenFlowNodeRED/src/nodered/nodes/api.ts | 2 + .../src/nodered/nodes/api_nodes.ts | 39 +++++++++++- 3 files changed, 101 insertions(+), 2 deletions(-) diff --git a/OpenFlowNodeRED/src/nodered/nodes/api.html b/OpenFlowNodeRED/src/nodered/nodes/api.html index 6f2f0b12..7ffe2b70 100644 --- a/OpenFlowNodeRED/src/nodered/nodes/api.html +++ b/OpenFlowNodeRED/src/nodered/nodes/api.html @@ -1796,8 +1796,67 @@ + + + +