diff --git a/packages/ctl/ctl.js b/packages/ctl/ctl.js index b4cfaf90..62ffd2bd 100755 --- a/packages/ctl/ctl.js +++ b/packages/ctl/ctl.js @@ -112,7 +112,8 @@ class Control extends libLink.Link { } async debugWsMessageEventHandler(message) { - print("WS", message.data.direction, message.data.content); + // eslint-disable-next-line no-console + console.log("WS", message.data.direction, message.data.content); } async shutdown() { @@ -186,6 +187,7 @@ async function startControl() { level: args.logLevel, format: new libLoggingUtils.TerminalFormat(), })); + libLoggingUtils.handleUnhandledErrors(logger); logger.verbose(`Loading available plugins from ${args.pluginList}`); let pluginList = new Map(); diff --git a/packages/lib/command.js b/packages/lib/command.js index f0738e8b..85b0f864 100644 --- a/packages/lib/command.js +++ b/packages/lib/command.js @@ -142,7 +142,7 @@ class CommandTree { * * @param {module:lib/link.Link} client - link to master server to query slave on. * @param {string} slaveName - string with name or id of slave. - * @returns {number} slave ID. + * @returns {Promise} slave ID. * @static */ async function resolveSlave(client, slaveName) { @@ -174,7 +174,7 @@ async function resolveSlave(client, slaveName) { * * @param {module:lib/link.Link} client - link to master server to query instance on. * @param {string} instanceName - string with name or id of instance. - * @returns {number} instance ID. + * @returns {Promise} instance ID. * @static */ async function resolveInstance(client, instanceName) { @@ -239,7 +239,7 @@ async function resolveModPack(client, modPackName) { * * @param {module:lib/link.Link} client - link to master server to query role on. * @param {string} roleName - string with name or id of role. - * @returns {Object} Role info. + * @returns {Promise} Role info. * @static */ async function retrieveRole(client, roleName) { diff --git a/packages/lib/factorio/export.js b/packages/lib/factorio/export.js index 22c74de9..f30d33bf 100644 --- a/packages/lib/factorio/export.js +++ b/packages/lib/factorio/export.js @@ -67,7 +67,7 @@ async function loadZip(server, modVersions, mod) { * The server to load the file from. * @param {Map} modVersions - Mapping of mod to version used. * @param {string} modPath - Factorio style path to the file to load. - * @returns {?Buffer} The content of the file or null if not found. + * @returns {Promise} The content of the file or null if not found. * @memberof module:lib/factorio * @private * @inner @@ -255,7 +255,7 @@ function filterItems(prototypes) { * @param {Map} modVersions - * Mapping of mod name to versions to get icons from. * @param {Array} items - Array of item prototypes. - * @return {{itemSheet: Jimp, itemData: Map}} + * @return {Promise<{itemSheet: Jimp, itemData: Map}>} * Item spritesheet and metadata. * @memberof module:lib/factorio * @private @@ -327,7 +327,7 @@ async function exportItems(server, modVersions, items) { * Mapping of mod name to version to export locale from. * @param {Array} modOrder - Load order of the mods. * @param {string} languageCode - Language to export locale for. - * @returns {Map} merged locale information + * @returns {Promise>} merged locale information * @memberof module:lib/factorio * @private * @inner @@ -379,7 +379,7 @@ async function exportLocale(server, modVersions, modOrder, languageCode) { * * @param {module:lib/factorio.FactorioServer} server - * The server to export the data from. - * @returns {JSZip} zip file with exported data. + * @returns {Promise} zip file with exported data. * @memberof module:lib/factorio */ async function exportData(server) { diff --git a/packages/lib/factorio/server.js b/packages/lib/factorio/server.js index a199f04e..d6d07345 100644 --- a/packages/lib/factorio/server.js +++ b/packages/lib/factorio/server.js @@ -86,7 +86,7 @@ function versionOrder(a, b) { * @param {string} targetVersion - * Version to look for, supports the special value "latest" for the * latest version available. - * @returns {Array} Array with path to data dir and version found. + * @returns {Promise} Array with path to data dir and version found. * @memberof module:lib/factorio * @private * @inner @@ -163,7 +163,7 @@ function randomDynamicPort() { * the given length. * * @param {number} length - the length of the password to generate. - * @return {string} password of the given length + * @return {Promise} password of the given length * @memberof module:lib/factorio * @private * @inner @@ -699,6 +699,16 @@ class FactorioServer extends events.EventEmitter { this._server.stderr.pipe(stderr); } + _resetState() { + this._state = "init"; + this._server = null; + this._rconClient = null; + this._rconReady = false; + this._gameReady = false; + this._unexpected = []; + this._runningAutosave = null; + } + _watchExit() { this._server.on("exit", (code, signal) => { if (this._state !== "stopping") { @@ -736,15 +746,21 @@ class FactorioServer extends events.EventEmitter { this._rconClient.end().catch(() => {}); } - // Reset server state - this._state = "init"; - this._server = null; - this._rconClient = null; - this._rconReady = false; - this._gameReady = false; - this._unexpected = []; - this._runningAutosave = null; + this._resetState(); + this.emit("exit"); + }); + this._server.on("error", err => { + if (err.code === "EACCES") { + this.emit("error", new libErrors.EnvironmentError("Unable to run server: Permission denied")); + } else { + this.emit("error", new libErrors.EnvironmentError(`Unexpected error:\n${err.stack}`)); + } + if (this._rconClient) { + this._rconClient.end().catch(() => {}); + } + + this._resetState(); this.emit("exit"); }); } @@ -805,6 +821,11 @@ class FactorioServer extends events.EventEmitter { if (code !== 0) { throw new Error(`Factorio exited with status ${code}`); } + } catch (err) { + if (err.code === "EACCES") { + throw new libErrors.EnvironmentError("Unable to run server: Permission denied"); + } + throw err; } finally { this._state = "init"; } @@ -902,7 +923,7 @@ class FactorioServer extends events.EventEmitter { * @param {boolean} expectEmpty - * if true throw if the response is not empty. Useful for detecting * errors that might have been sent in response. - * @returns {string} response from server. + * @returns {Promise} response from server. */ async sendRcon(message, expectEmpty) { this._check(["running", "stopping"]); @@ -1036,7 +1057,7 @@ class FactorioServer extends events.EventEmitter { * Ensures achievements are disabled on the save that's running. This is * necessary in order to run any commands at all. * - * @returns {boolean} + * @returns {Promise} * True if acheivements got disabled and false if they already where * disabled. */ @@ -1104,7 +1125,7 @@ class FactorioServer extends events.EventEmitter { * * Loads server-settings.example.json from the data dir. * - * @returns {object} the parsed server-settings. + * @returns {Promise} the parsed server-settings. */ async exampleSettings() { return JSON.parse(await fs.readFile(this.dataPath("server-settings.example.json"), "utf-8")); diff --git a/packages/lib/file_ops.js b/packages/lib/file_ops.js index be007912..2d869e41 100644 --- a/packages/lib/file_ops.js +++ b/packages/lib/file_ops.js @@ -5,6 +5,7 @@ const fs = require("fs-extra"); const path = require("path"); const crypto = require("crypto"); // needed for getTempFile + /** * Returns the newest file in a directory * @@ -12,7 +13,7 @@ const crypto = require("crypto"); // needed for getTempFile * @param {function(string): boolean} filter - * Optional function to filter out files to ignore. Should return true * if the file is to be considered. - * @returns {?string} + * @returns {Promise} * Name of the file with the newest timestamp or null if the * directory contains no files. */ @@ -32,6 +33,38 @@ async function getNewestFile(directory, filter = (name) => true) { return newestFile; } +/** + * Returns the total size of all files in a directory + * + * Sums up the file size of all files in the given directory if it exists. + * Error reading the size of files are ignored, and error reading the + * directory will result in 0 being returned. + * + * @param {string} directory - The directory to sum files in. + * @returns {Promise} The size in bytes of all files in the directory. + */ +async function directorySize(directory) { + let dirEntries; + try { + dirEntries = await fs.readdir(directory, { withFileTypes: true }); + } catch (err) { + if (err.code === "ENOENT") { + return 0; + } + throw err; + } + let statTasks = []; + for (let entry of dirEntries) { + if (entry.isFile()) { + statTasks.push(fs + .stat(path.join(directory, entry.name)) + .then(stat => stat.size, _ => 0) + ); + } + } + return (await Promise.all(statTasks)).reduce((a, v) => a + v, 0); +} + /** * Modifies name in case it already exisist at the given directory * @@ -47,8 +80,8 @@ async function getNewestFile(directory, filter = (name) => true) { * @param {string} directory - directory to check in. * @param {string} name - file name to check for, may have extension. * @param {string} extension - dot extension used for the file name. - * @returns {string} modified name with extension that likely does not exist - * in the folder + * @returns {Promise} modified name with extension that likely does + * not exist in the folder */ async function findUnusedName(directory, name, extension = "") { if (extension && name.endsWith(extension)) { @@ -103,8 +136,19 @@ async function getTempFile(prefix, suffix, tmpdir) { * @param {object|string} options - see fs.writeFile, `flag` must not be set. */ async function safeOutputFile(file, data, options={}) { + let directory = path.dirname(file); + if (!await fs.pathExists(directory)) { + await fs.mkdirs(directory); + } let temporary = `${file}.tmp`; - await fs.outputFile(temporary, data, options); + let fd = await fs.open(temporary, "w"); + try { + await fs.writeFile(fd, data, options); + await fs.fsync(fd); + } finally { + await fs.close(fd); + } + await fs.rename(temporary, file); } @@ -193,6 +237,7 @@ function cleanFilename(name) { module.exports = { getNewestFile, + directorySize, findUnusedName, getTempFile, safeOutputFile, diff --git a/packages/lib/helpers.js b/packages/lib/helpers.js index 3738666e..9069a198 100644 --- a/packages/lib/helpers.js +++ b/packages/lib/helpers.js @@ -63,7 +63,7 @@ async function timeout(promise, time, timeoutResult) { * returns all the data which was read from the stream. * * @param {Readable} stream - byte stream to read to the end. - * @returns {Buffer} content of the stream. + * @returns {Promise} content of the stream. * @static */ async function readStream(stream) { diff --git a/packages/lib/link/messages.js b/packages/lib/link/messages.js index 3da48aec..21a063db 100644 --- a/packages/lib/link/messages.js +++ b/packages/lib/link/messages.js @@ -255,7 +255,7 @@ class Request extends Message { * * @param {module:lib/link.Link} link - Link to send request over. * @param {Object} data - Data to send with the request. - * @returns {object} response data + * @returns {Promise} response data */ async send(link, data = {}) { // XXX validate link target/source? diff --git a/packages/lib/logging.js b/packages/lib/logging.js index e55fa73e..4c1ecff2 100644 --- a/packages/lib/logging.js +++ b/packages/lib/logging.js @@ -32,9 +32,14 @@ class ConsoleTransport extends Transport { super(options); this.errorLevels = new Set(options.errorLevels || ["fatal", "error"]); this.warnLevels = new Set(options.warnLevels || ["warn"]); + this.filter = options.filter || (() => true); } log(info, callback) { + if (!this.filter(info)) { + return callback(); + } + /* eslint-disable no-console */ if (this.errorLevels.has(info[LEVEL])) { console.error(info[MESSAGE]); @@ -44,7 +49,7 @@ class ConsoleTransport extends Transport { console.log(info[MESSAGE]); } /* eslint-enable no-console */ - callback(); + return callback(); } } @@ -58,13 +63,11 @@ class WebConsoleFormat { transform(info, options) { let src = " "; - if (info.slave_id) { - let slaveName = info.slave_id; - src += `s:${slaveName} - `; + if (info.slave_id !== undefined) { + src += `s:${info.slave_name} - `; } - if (info.instance_id) { - let instanceName = info.instance_id; - src += `i:${instanceName}`; + if (info.instance_id !== undefined) { + src += `i:${info.instance_name}`; } if (info.plugin) { src += `${info.plugin}: `; @@ -79,6 +82,59 @@ class WebConsoleFormat { } } +/** + * Filter object for logs + * @typedef {Object} module:lib/logging~LogFilter + * @property {string} [max_level] - + * Maximum log level to include. Higher levels are more verbose. + * @property {boolean} [all] - + * Include log entries from master, all slaves and all instances. + * @property {boolean} [master] - + * Include log entries from the master server. + * @property {Array} [slave_ids] - + * Include log entries for the given slaves and instances of those + * slaves by id. + * @property {Array} [instance_ids] - + * Include log entries for the given instances by id. + */ + +/** + * Create log filter by level and source. + * + * @param {module:lib/logging~LogFilter} filter - + * Filter to filter log entries by. + * @returns {function(object): boolean} + * filter returning true for log entries that match it. + * @static + */ +function logFilter({ all, master, slave_ids, instance_ids, max_level }) { + return info => { + // Note: reversed to filter out undefined levels + if (max_level && !(levels[info.level] <= levels[max_level])) { + return false; + } + + if (all) { + return true; + } + if (master && info.slave_id === undefined) { + return true; + } + if ( + slave_ids + && info.slave_id !== undefined + && info.instance_id === undefined + && slave_ids.includes(info.slave_id) + ) { + return true; + } + if (instance_ids && info.instance_id !== undefined && instance_ids.includes(info.instance_id)) { + return true; + } + return false; + }; +} + const logger = winston.createLogger({ level: "verbose", levels, @@ -90,5 +146,6 @@ module.exports = { WebConsoleFormat, colors, levels, + logFilter, logger, }; diff --git a/packages/lib/logging_utils.js b/packages/lib/logging_utils.js index 37e818e7..5117a421 100644 --- a/packages/lib/logging_utils.js +++ b/packages/lib/logging_utils.js @@ -18,7 +18,7 @@ const chalk = require("chalk"); const libLink = require("./link"); const libErrors = require("./errors"); const libFileOps = require("./file_ops"); -const { levels, logger } = require("./logging"); +const { levels, logFilter, logger } = require("./logging"); const libStream = require("./stream"); const finished = util.promisify(stream.finished); @@ -140,21 +140,6 @@ class LinkTransport extends Transport { } const logFileGlob = /^[a-z]+-(\d{4}-\d{2}-\d{2})\.log$/; -/** - * Filter object for logs - * @typedef {Object} module:lib/logging_utils~LogFilter - * @property {string} [max_level] - - * Maximum log level to include. Higher levels are more verbose. - * @property {boolean} [all] - - * Include log entries from master, all slaves and all instances. - * @property {boolean} [master] - - * Include log entries from the master server. - * @property {Array} [slave_ids] - - * Include log entries for the given slaves and instances of those - * slaves by id. - * @property {Array} [instance_ids] - - * Include log entries for the given instances by id. - */ /** * Keeps an index over a log directory to speed up queries to it @@ -205,7 +190,7 @@ class LogIndex { * module:lib/logging_utils.LogIndex#save}. * * @param {string} logDirectory - Path to directory to load from. - * @returns {module:lib/logging_utils.LogIndex} loaded or created log index. + * @returns {Promise} loaded or created log index. */ static async load(logDirectory) { try { @@ -289,7 +274,7 @@ class LogIndex { * * @param {string} file - * Name of file in the log directory to check for. - * @param {module:lib/logging_utils~LogFilter} filter - + * @param {module:lib/logging~LogFilter} filter - * Filter to check index if file contains entries for. * @returns {boolean} * true if the file may contain entries included by the filter. @@ -326,43 +311,6 @@ class LogIndex { } } -/** - * Create log filter by level and source. - * - * @param {module:lib/logging_utils~LogFilter} filter - - * Filter to filter log entries by. - * @returns {function(object): boolean} - * filter returning true for log entries that match it. - * @static - */ -function logFilter({ all, master, slave_ids, instance_ids, max_level }) { - return info => { - // Note: reversed to filter out undefined levels - if (max_level && !(levels[info.level] <= levels[max_level])) { - return false; - } - - if (all) { - return true; - } - if (master && info.slave_id === undefined) { - return true; - } - if ( - slave_ids - && info.slave_id !== undefined - && info.instance_id === undefined - && slave_ids.includes(info.slave_id) - ) { - return true; - } - if (instance_ids && info.instance_id !== undefined && instance_ids.includes(info.instance_id)) { - return true; - } - return false; - }; -} - /** * Filter object for querying logs * @typedef {Object} module:lib/logging_utils~QueryLogFilter @@ -391,7 +339,7 @@ function logFilter({ all, master, slave_ids, instance_ids, max_level }) { * Filter to limit logs by. * @param {module:lib/logging_utils.LogIndex=} index - * Index to speed up query with. - * @returns {Array} log entries matching the filter + * @returns {Promise>} log entries matching the filter */ async function queryLog(logDirectory, filter, index) { let files = (await fs.readdir(logDirectory)).filter(entry => logFileGlob.test(entry)); @@ -510,12 +458,25 @@ async function migrateLogs(log, directory, pattern) { } } +function handleUnhandledErrors() { + /* eslint-disable node/no-process-exit */ + process.on("uncaughtException", err => { + logger.fatal(`Uncaught exception:\n${err.stack}`); + process.exit(1); + }); + process.on("unhandledRejection", (reason, promise) => { + logger.fatal(`Unhandled rejection:\n${reason.stack ? reason.stack : reason}`); + process.exit(1); + }); + /* eslint-enable node/no-process-exit */ +} + module.exports = { TerminalFormat, LinkTransport, LogIndex, - logFilter, + handleUnhandledErrors, queryLog, migrateLogs, diff --git a/packages/lib/plugin.js b/packages/lib/plugin.js index ac2d3ffb..4b56b976 100644 --- a/packages/lib/plugin.js +++ b/packages/lib/plugin.js @@ -812,7 +812,7 @@ function attachPluginMessages(link, plugin) { * Mapping of plugin names to plugins to invoke the hook on. * @param {string} hook - Name of hook to invoke. * @param {...*} args - Arguments to pass on to the hook. - * @returns {Array} Non-empty return values from the hooks. + * @returns {Promise} Non-empty return values from the hooks. */ async function invokeHook(plugins, hook, ...args) { let results = []; diff --git a/packages/lib/plugin_loader.js b/packages/lib/plugin_loader.js index f06e332d..6ec0310a 100644 --- a/packages/lib/plugin_loader.js +++ b/packages/lib/plugin_loader.js @@ -6,6 +6,7 @@ "use strict"; const libErrors = require("./errors"); +const libPlugin = require("./plugin"); const path = require("path"); @@ -18,7 +19,7 @@ const path = require("path"); * * @param {Map} pluginList - * Mapping of plugin name to require path for the plugins to load. - * @returns {Array} Array of plugin info modules. + * @returns {Promise>} Array of plugin info modules. * @static */ async function loadPluginInfos(pluginList) { @@ -48,18 +49,33 @@ async function loadPluginInfos(pluginList) { return plugins; } +function loadPluginClass(entrypointName, className, pluginClass, pluginInfo) { + let resolvedPath = path.posix.join(pluginInfo.requirePath, pluginInfo[entrypointName]); + let entrypoint = require(resolvedPath); + if (!entrypoint[className]) { + throw new libErrors.PluginError(pluginInfo.name, + new Error(`Expected ${resolvedPath} to export a class named ${className}`) + ); + } + if (!(entrypoint[className].prototype instanceof pluginClass)) { + throw new libErrors.PluginError(pluginInfo.name, + new Error(`Expected ${className} exported from ${resolvedPath} to be a subclass of ${pluginClass.name}`) + ); + } + return entrypoint[className]; +} + /** * Load master plugin class of a plugin * * @param {Object} pluginInfo - * Plugin info object returned from {@link * module:lib/plugin_loader.loadPluginInfos} to load class from. - * @returns {function} plugin class + * @returns {Promise} plugin class * @static */ async function loadMasterPluginClass(pluginInfo) { - let entrypoint = require(path.posix.join(pluginInfo.requirePath, pluginInfo.masterEntrypoint)); - return entrypoint.MasterPlugin; + return loadPluginClass("masterEntrypoint", "MasterPlugin", libPlugin.BaseMasterPlugin, pluginInfo); } /** @@ -68,12 +84,11 @@ async function loadMasterPluginClass(pluginInfo) { * @param {Object} pluginInfo - * Plugin info object returned from {@link * module:lib/plugin_loader.loadPluginInfos} to load class from. - * @returns {function} plugin class + * @returns {Promise} plugin class * @static */ async function loadInstancePluginClass(pluginInfo) { - let entrypoint = require(path.posix.join(pluginInfo.requirePath, pluginInfo.instanceEntrypoint)); - return entrypoint.InstancePlugin; + return loadPluginClass("instanceEntrypoint", "InstancePlugin", libPlugin.BaseInstancePlugin, pluginInfo); } /** @@ -82,12 +97,11 @@ async function loadInstancePluginClass(pluginInfo) { * @param {Object} pluginInfo - * Plugin info object returned from {@link * module:lib/plugin_loader.loadPluginInfos} to load class from. - * @returns {function} plugin class + * @returns {Promise} plugin class * @static */ async function loadControlPluginClass(pluginInfo) { - let entrypoint = require(path.posix.join(pluginInfo.requirePath, pluginInfo.controlEntrypoint)); - return entrypoint.ControlPlugin; + return loadPluginClass("controlEntrypoint", "ControlPlugin", libPlugin.BaseControlPlugin, pluginInfo); } module.exports = { diff --git a/packages/lib/prometheus.js b/packages/lib/prometheus.js index cc167625..aa96efa9 100644 --- a/packages/lib/prometheus.js +++ b/packages/lib/prometheus.js @@ -9,9 +9,8 @@ * The ordinary use case of instrumenting a code base should be covered by * {@link module:lib/prometheus.Counter}, {@link * module:lib/prometheus.Gauge}, {@link module:lib/prometheus.Histogram} and - * {@link module:lib/prometheus.exposition}. Note that the summary - * collector is not implemented. See documentation for each of the listed - * interfaces for more information. + * {@link module:lib/prometheus.exposition}. See documentation for each of + * the listed interfaces for more information. * * @example * const { Counter, exposition } = require("@clusterio/lib/prometheus"); @@ -802,7 +801,7 @@ class GaugeChild extends ValueCollectorChild { * to avoid having the time of many collectors add up to too much. * * Like with the Counter the Gauge also supports labels. When using labels - * the methods for changing the value of the counter is not longer usable + * the methods for changing the value of the counter is no longer usable * directly on the counter itself, instead a child counter with label values * set has to be retrieved with the `.labels()` method. For example: * @@ -919,6 +918,232 @@ class Gauge extends ValueCollector { } } +/** + * Child Summary holding the sum and count for a single label set. + */ +class SummaryChild { + constructor(collector, key) { + this._sumValues = collector._sumValues; + this._countValues = collector._countValues; + this._key = key; + + this._sumValues.set(key, 0); + this._countValues.set(key, 0); + } + + /** + * Sum of all observations for label set + * @type {number} + */ + get sum() { + return this._sumValues.get(this._key); + } + + /** + * Count of observations for label set + * @type {number} + */ + get count() { + return this._countValues.get(this._key); + } + + /** + * Observe a given value and increment matching buckets for label set + * + * @param {number} value - number to count into summary. + */ + observe(value) { + this._sumValues.set(this._key, this._sumValues.get(this._key) + value); + this._countValues.set(this._key, this._countValues.get(this._key) + 1); + } + + /** + * Start a timer for observing a duration for label set + * + * @returns {function()} + * function that when called will store the duration in seconds from + * when the timer was started into the metric. + */ + startTimer() { + let start = process.hrtime.bigint(); + return () => { + let end = process.hrtime.bigint(); + this.observe(Number(end - start) / 1e9); + }; + } +} + +/** + * Summary metric + * + * Sample observations into a count and sum. This is useful when you have + * an operation that reports a metric that you want insight into the rate + * and average size of values for. A common case for this is request + * duration, for example: + * + * ```js + * const requestDuration = new Summary( + * "app_request_duration_seconds", + * "Time to process app requests", + * ); + * + * async function handleRequest(...) { + * const observeDuration = requestDuration.startTimer(); + * try { + * // Do async stuff. + * } finally { + * observeDuration(); + * } + * } + * ``` + * + * Note that reporting quantiles is note supported. This makes the Summary + * less insightful than the Histogram while using less resources. + * + * The `.startTimer()` method provides a convenient interface for adding + * observed durations to the summary. Other types of values can be added to + * a summary with the `.observe()` method. + * + * Like with the Counter and Gauge the Summary collector also supports + * labels. When using labels the methods for observing values into the + * summary is no longer usable directly on the counter itself, instead a + * child summary with label values set has to be retrieved with the + * `.labels()` method. For example: + * + * ```js + * const requestDuration = new Summary( + * "app_request_duration_seconds", + * "Time to process app requests", + * { labels: ["endpoint"] } + * ); + * + * async function handleRequest(endpoint, ...) { + * const observeDuration = requestDuration.labels(endpoint).startTimer(); + * try { + * // Do async stuff. + * } finally { + * observeDuration(); + * } + * } + * ``` + * + * When using labels the summary is no longer initalized with a default + * value, and this may cause issues with aggregating and querying the + * summary in Prometheus. When dynamically setting labels it is recommended + * where possible to initialize all possible combinations of label values + * that will be used. This is done by calling `.labels()` for each + * combination, for example: + * + * ```js + * for (let endpoint of ["/status", "/api", ...) { + * requestDuration.labels(endpoint); + * } + * ``` + * + * Note that every combination of label values used creates two new time + * series that need to be stored and processed. You should carefully + * evaluate which labels you actually need as resource usage for a metric + * increases exponentially with the number of labels used. + * + * @static + */ +class Summary extends LabeledCollector { + /** + * Create optionally labeled summary + * + * @param {string} name - Name of the metric. + * @param {string} help - Help text for metric. + * @param {Object=} options - options for collector. + * @param {Array=} options.labels - + * Labels for this metric, defaults to no labels. + * @param {boolean=} options.register - + * If true registers this collector with the default registry. + * Defaults to true. + * @param {function()=} options.callback - + * Possibly async function that is called when the metric is + * collected. The collector being collected is passed as the + * argument. + */ + constructor(name, help, options = {}) { + super("summary", name, help, options, SummaryChild); + + this._sumValues = new Map(); + this._countValues = new Map(); + this._defaultChild = this.metric.labels.length ? null : this.labels({}); + } + + async* collect() { + if (this.callback) { await this.callback(this); } + yield { + metric: this.metric, + samples: new Map([ + ["_sum", this._sumValues], + ["_count", this._countValues], + ]), + }; + } + + /** + * Sum of all observations for label set + * + * Note: Only available if this is an unlabeled collector. + * @type {number} + */ + get sum() { + return this._defaultChild.sum; + } + + /** + * Count of observations for label set + * + * Note: Only available if this is an unlabeled collector. + * @type {number} + */ + get count() { + return this._defaultChild.count; + } + + /** + * Observe a given value and increment matching buckets + * + * Note: Only works if this is an unlabeled collector. + * @param {number} value - number to count into histogram buckets. + */ + observe(value) { + this._defaultChild.observe(value); + } + + /** + * Start a timer for observing a duration + * + * Note: Only works if this is an unlabeled collector. + * @returns {function()} + * function that when called will store the duration in seconds from + * when the timer was started into the metric. + */ + startTimer() { + return this._defaultChild.startTimer(); + } + + remove(...labels) { + let key = super.remove(...labels); + this._sumValues.delete(key); + this._countValues.delete(key); + } + + removeAll(labels) { + super.removeAll(labels); + removeMatchingLabels(this._sumValues, labels); + removeMatchingLabels(this._countValues, labels); + } + + clear() { + super.clear(); + this._sumValues = new Map(); + this._countValues = new Map(); + } +} + function formatValue(value) { if (value === Infinity) { return "+Inf"; @@ -1047,7 +1272,7 @@ class HistogramChild { * * Like with the Counter and Gauge the Histogram collector also supports * labels. When using labels the methods for observing values into the - * histogram is not longer usable directly on the counter itself, instead a + * histogram is no longer usable directly on the counter itself, instead a * child histogram with label values set has to be retrieved with the * `.labels()` method. For example: * @@ -1567,6 +1792,7 @@ defaultCollectors.processStartTimeSeconds.setToCurrentTime(); module.exports = { Counter, Gauge, + Summary, Histogram, CollectorRegistry, Collector, diff --git a/packages/lib/users.js b/packages/lib/users.js index 4f3fa0e8..00b90de9 100644 --- a/packages/lib/users.js +++ b/packages/lib/users.js @@ -618,16 +618,19 @@ definePermission({ name: "core.user.get", title: "Get user", description: "Get the details of a user in the cluster.", + grantByDefault: true, }); definePermission({ name: "core.user.list", title: "List users", description: "Get the full list of users in the cluster.", + grantByDefault: true, }); definePermission({ name: "core.user.subscribe", title: "Subscribe to user updates", description: "Subscribe to be notified on updates on the details and status of users.", + grantByDefault: true, }); definePermission({ name: "core.user.create", diff --git a/packages/master/master.js b/packages/master/master.js index 39214a98..b1a21cc9 100755 --- a/packages/master/master.js +++ b/packages/master/master.js @@ -38,6 +38,7 @@ const libLoggingUtils = require("@clusterio/lib/logging_utils"); const Master = require("./src/Master"); const UserManager = require("./src/UserManager"); +const version = require("./package").version; // globals let master; @@ -283,6 +284,13 @@ async function initialize() { format: new libLoggingUtils.TerminalFormat(), })); } + libLoggingUtils.handleUnhandledErrors(logger); + + let command = parameters.args._[0]; + if (command === "run") { + logger.info(`Starting Clusterio master ${version}`); + parameters.shouldRun = true; + } logger.info(`Loading available plugins from ${parameters.args.pluginList}`); let pluginList = new Map(); @@ -295,7 +303,6 @@ async function initialize() { } // If the command is plugin management we don't try to load plugins - let command = parameters.args._[0]; if (command === "plugin") { await libSharedCommands.handlePluginCommand(parameters.args, pluginList, parameters.args.pluginList); return parameters; @@ -336,15 +343,11 @@ async function initialize() { await libSharedCommands.handleConfigCommand( parameters.args, parameters.masterConfig, parameters.masterConfigPath ); - return parameters; } else if (command === "bootstrap") { await handleBootstrapCommand(parameters.args, parameters.masterConfig); - return parameters; } - // If we get here the command was run - parameters.shouldRun = true; return parameters; } @@ -353,9 +356,6 @@ async function startup() { // and as the process name in ps/top on linux. process.title = "clusterioMaster"; - // add better stack traces on promise rejection - process.on("unhandledRejection", err => logger.error(`Unhandled rejection:\n${err.stack}`)); - let { args, shouldRun, clusterLogger, pluginInfos, masterConfigPath, masterConfig } = await initialize(); if (!shouldRun) { return; diff --git a/packages/master/src/ControlConnection.js b/packages/master/src/ControlConnection.js index 9856b33b..f695156e 100644 --- a/packages/master/src/ControlConnection.js +++ b/packages/master/src/ControlConnection.js @@ -9,7 +9,7 @@ const libData = require("@clusterio/lib/data"); const libErrors = require("@clusterio/lib/errors"); const libHelpers = require("@clusterio/lib/helpers"); const libLink = require("@clusterio/lib/link"); -const { logger } = require("@clusterio/lib/logging"); +const { logFilter, logger } = require("@clusterio/lib/logging"); const libLoggingUtils = require("@clusterio/lib/logging_utils"); const libPlugin = require("@clusterio/lib/plugin"); const libPrometheus = require("@clusterio/lib/prometheus"); @@ -289,7 +289,7 @@ class ControlConnection extends BaseConnection { async updateInstanceConfig(instance) { let slaveId = instance.config.get("instance.assigned_slave"); - if (slaveId) { + if (slaveId !== null) { let connection = this._master.wsServer.slaveConnections.get(slaveId); if (connection) { await libLink.messages.assignInstance.send(connection, { @@ -356,6 +356,9 @@ class ControlConnection extends BaseConnection { instance_id, serialized_config: instance.config.serialize("slave"), }); + } else { + instance.status = "unassigned"; + this._master.instanceUpdated(instance); } } @@ -671,7 +674,7 @@ class ControlConnection extends BaseConnection { this.logTransport = new libLoggingUtils.LinkTransport({ link: this }); this._master.clusterLogger.add(this.logTransport); } - this.logTransport.filter = libLoggingUtils.logFilter(this.logSubscriptions); + this.logTransport.filter = logFilter(this.logSubscriptions); } else if (this.logTransport) { this._master.clusterLogger.remove(this.logTransport); diff --git a/packages/master/src/Master.js b/packages/master/src/Master.js index 2bb3ccb7..6fb10989 100644 --- a/packages/master/src/Master.js +++ b/packages/master/src/Master.js @@ -6,7 +6,7 @@ const fs = require("fs-extra"); const http = require("http"); const https = require("https"); const path = require("path"); - +const stream = require("stream"); const libConfig = require("@clusterio/lib/config"); const libData = require("@clusterio/lib/data"); @@ -26,9 +26,15 @@ const UserManager = require("./UserManager"); const WsServer = require("./WsServer"); -const hitCounter = new libPrometheus.Counter( - "clusterio_master_http_hits_total", - "How many HTTP requests in total have been received" +const endpointDurationSummary = new libPrometheus.Summary( + "clusterio_master_http_endpoint_duration_seconds", + "Time it took to respond to a an HTTP request", + { labels: ["route"] } +); + +const logSizeGauge = new libPrometheus.Gauge( + "clusterio_master_log_bytes", + "Size of all log files currently stored on the master." ); /** @@ -130,6 +136,19 @@ class Master { } } + /** + * Get the total size of the logs stored + * + * @returns {Promise} size in bytes of stored log files. + */ + async logSize() { + return (await Promise.all([ + libFileOps.directorySize(path.join(this.logDirectory, "cluster")), + libFileOps.directorySize(path.join(this.logDirectory, "master")), + libFileOps.directorySize(path.join(this.logDirectory, "slave")), + ])).reduce((a, v) => a + v, 0); + } + async _startInternal(args) { this.logDirectory = args.logDirectory; this.clusterLogIndex = await libLoggingUtils.LogIndex.load(path.join(this.logDirectory, "cluster")); @@ -138,6 +157,7 @@ class Master { err => logger.error(`Error building cluster log index:\n${err.stack}`) ); }, 600e3); + logSizeGauge.callback = async () => { logSizeGauge.set(await this.logSize()); }; // Start webpack development server if enabled if (args.dev || args.devPlugin) { @@ -464,7 +484,7 @@ class Master { * @param {module:lib/logging_utils~QueryLogFilter} filter - * Filter to limit entries with. Note that only the master log can * be queried from this function. - * @returns {Array} log entries matching the filter + * @returns {Promise>} log entries matching the filter */ async queryMasterLog(filter) { return await libLoggingUtils.queryLog( @@ -477,7 +497,7 @@ class Master { * * @param {module:lib/logging_utils~QueryLogFilter} filter - * Filter to limit entries with. - * @returns {Array} log entries matching the filter + * @returns {Promise>} log entries matching the filter */ async queryClusterLog(filter) { return await libLoggingUtils.queryLog( @@ -487,7 +507,15 @@ class Master { static addAppRoutes(app, pluginInfos) { app.use((req, res, next) => { - hitCounter.inc(); + let start = process.hrtime.bigint(); + stream.finished(res, () => { + let routePath = "static"; + if (req.route && req.route.path) { + routePath = req.route.path; + } + let end = process.hrtime.bigint(); + endpointDurationSummary.labels(routePath).observe(Number(end - start) / 1e9); + }); next(); }); app.use(compression()); @@ -783,7 +811,7 @@ class Master { * @param {object} data - Data to pass with the request. * @param {number} data.instance_id - * ID of instance to send this request towards - * @returns {object} data returned from the request. + * @returns {Promise} data returned from the request. */ async forwardRequestToInstance(request, data) { let instance = this.getRequestInstance(data.instance_id); diff --git a/packages/master/src/metrics.js b/packages/master/src/metrics.js index eb753828..ad400eed 100644 --- a/packages/master/src/metrics.js +++ b/packages/master/src/metrics.js @@ -1,9 +1,14 @@ // Shared metrics "use strict"; const libPrometheus = require("@clusterio/lib/prometheus"); +const util = require("util"); exports.endpointHitCounter = new libPrometheus.Counter( "clusterio_master_http_endpoint_hits_total", "How many requests a particular HTTP endpoint has gotten", - { labels: ["route"] } + { labels: ["route"], register: false } +); + +exports.endpointHitCounter.labels = util.deprecate( + exports.endpointHitCounter.labels, "incrementing endpointHitCounter is no longer needed and has no effect" ); diff --git a/packages/master/src/routes.js b/packages/master/src/routes.js index 4e48f1f5..e9af7ff3 100644 --- a/packages/master/src/routes.js +++ b/packages/master/src/routes.js @@ -19,8 +19,6 @@ const libPlugin = require("@clusterio/lib/plugin"); const libPrometheus = require("@clusterio/lib/prometheus"); const { logger } = require("@clusterio/lib/logging"); -const { endpointHitCounter } = require("./metrics"); - const finished = util.promisify(nodeStream.finished); @@ -41,8 +39,6 @@ function mergeSamples(destinationResult, sourceResult) { // Prometheus polling endpoint async function getMetrics(req, res, next) { - endpointHitCounter.labels(req.route.path).inc(); - let results = []; let pluginResults = await libPlugin.invokeHook(req.app.locals.master.plugins, "onMetrics"); for (let metricIterator of pluginResults) { @@ -181,7 +177,6 @@ function validateUserToken(req, res, next) { // Handle an uploaded export package. async function uploadExport(req, res) { - endpointHitCounter.labels(req.route.path).inc(); if (req.get("Content-Type") !== "application/zip") { res.sendStatus(415); return; @@ -340,7 +335,6 @@ async function uploadSave(req, res) { res.status(403).json({ request_errors: [err.message] }); return; } - endpointHitCounter.labels(req.route.path).inc(); let contentType = req.get("Content-Type"); let match = contentTypeRegExp.exec(contentType); @@ -479,7 +473,6 @@ async function uploadMod(req, res) { res.status(403).json({ request_errors: [err.message] }); return; } - endpointHitCounter.labels(req.route.path).inc(); let contentType = req.get("Content-Type"); let match = contentTypeRegExp.exec(contentType); diff --git a/packages/slave/slave.js b/packages/slave/slave.js index 8f9f70e7..d52a3d00 100755 --- a/packages/slave/slave.js +++ b/packages/slave/slave.js @@ -27,7 +27,7 @@ const libPluginLoader = require("@clusterio/lib/plugin_loader"); const libErrors = require("@clusterio/lib/errors"); const libConfig = require("@clusterio/lib/config"); const libSharedCommands = require("@clusterio/lib/shared_commands"); -const { ConsoleTransport, levels, logger } = require("@clusterio/lib/logging"); +const { ConsoleTransport, FilteredTransport, levels, logger } = require("@clusterio/lib/logging"); const libLoggingUtils = require("@clusterio/lib/logging_utils"); const Slave = require("./src/Slave"); @@ -126,8 +126,15 @@ async function startSlave() { logger.add(new ConsoleTransport({ level: args.logLevel, format: new libLoggingUtils.TerminalFormat(), + filter: info => info.instance_id === undefined, })); } + libLoggingUtils.handleUnhandledErrors(logger); + + let command = args._[0]; + if (command === "run") { + logger.info(`Starting Clusterio slave ${version}`); + } // add better stack traces on promise rejection process.on("unhandledRejection", err => logger.error(`Unhandled rejection:\n${err.stack}`)); @@ -143,7 +150,6 @@ async function startSlave() { } // If the command is plugin management we don't try to load plugins - let command = args._[0]; if (command === "plugin") { await libSharedCommands.handlePluginCommand(args, pluginList, args.pluginList); return; diff --git a/packages/slave/src/Instance.js b/packages/slave/src/Instance.js index 2d33aad9..8f1965b5 100644 --- a/packages/slave/src/Instance.js +++ b/packages/slave/src/Instance.js @@ -16,7 +16,7 @@ const libPluginLoader = require("@clusterio/lib/plugin_loader"); const libErrors = require("@clusterio/lib/errors"); const libPrometheus = require("@clusterio/lib/prometheus"); const libLuaTools = require("@clusterio/lib/lua_tools"); -const { logger } = require("@clusterio/lib/logging"); +const libLogging = require("@clusterio/lib/logging"); const instanceRconCommandDuration = new libPrometheus.Histogram( @@ -53,7 +53,7 @@ const instanceFactorioAutosaveSize = new libPrometheus.Gauge( ); function applyAsConfig(name) { - return async function action(instance, value) { + return async function action(instance, value, logger) { if (name === "tags" && value instanceof Array) { // Replace spaces with non-break spaces and delimit by spaces. // This does change the defined tags, but there doesn't seem to @@ -83,7 +83,7 @@ const serverSettingsActions = { "game_password": applyAsConfig("password"), "require_user_verification": applyAsConfig("require-user-verification"), "tags": applyAsConfig("tags"), - "visibility": async (instance, value) => { + "visibility": async (instance, value, logger) => { for (let scope of ["lan", "public", "steam"]) { try { let enabled = Boolean(value[scope]); @@ -116,7 +116,7 @@ class Instance extends libLink.Link { */ this.id = this.config.get("instance.id"); - this.logger = logger.child({ + this.logger = libLogging.logger.child({ instance_id: this.id, instance_name: this.name, }); @@ -193,7 +193,7 @@ class Instance extends libLink.Link { /** * Mod pack currently running on this instance - * @type {module:lib/data.ModPack>} + * @type {module:lib/data.ModPack} */ this.activeModPack = undefined; @@ -538,7 +538,7 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " "); * entries from the given settings object. * * @param {Object} overrides - Server settings to override. - * @returns {Object} + * @returns {Promise} * server example settings with the given settings applied over it. */ async resolveServerSettings(overrides) { @@ -580,7 +580,6 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " "); * @param {String} factorioDir - Path to factorio installation. */ static async create(instanceDir, factorioDir) { - logger.info(`Creating ${instanceDir}`); await fs.ensureDir(path.join(instanceDir, "script-output")); await fs.ensureDir(path.join(instanceDir, "saves")); } @@ -649,7 +648,7 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " "); // Write mod-list.json await fs.outputFile(this.path("mods", "mod-list.json"), JSON.stringify({ - mods: [{ name: "base" }, ...this.activeModPack.mods.values()].map(m => ({ name: m.name, enabled: true })), + mods: [...this.activeModPack.mods.values()], }, null, 2)); // Write mod-settings.dat @@ -699,10 +698,10 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " "); * * Creates a new save if no save is passed and patches it with modules. * - * @param {String|null} saveName - + * @param {string|null} saveName - * Save to prepare from the instance saves directory. Creates a new * save if null. - * @returns {String} Name of the save prepared. + * @returns {Promise} Name of the save prepared. */ async prepareSave(saveName) { // Use latest save if no save was specified @@ -757,7 +756,12 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " "); throw new Error(`Module for plugin ${pluginName} is missing module.json`); } - let module = JSON.parse(await fs.readFile(moduleJsonPath)); + let module; + try { + module = JSON.parse(await fs.readFile(moduleJsonPath)); + } catch (err) { + throw new Error(`Loading module/module.json in plugin ${pluginName} failed: ${err.message}`); + } if (module.name !== pluginName) { throw new Error(`Expected name of module for plugin ${pluginName} to match the plugin name`); } @@ -875,7 +879,7 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " "); for (let [key, action] of Object.entries(serverSettingsActions)) { if (current[key] !== undefined && !util.isDeepStrictEqual(current[key], previous[key])) { - await action(this, current[key]); + await action(this, current[key], this.logger); } } } diff --git a/packages/slave/src/Slave.js b/packages/slave/src/Slave.js index c8b85f57..4bb2f14c 100644 --- a/packages/slave/src/Slave.js +++ b/packages/slave/src/Slave.js @@ -41,7 +41,7 @@ function checkRequestSaveName(name) { * instanceInfo objects. * * @param {string} instancesDir - Directory containing instances - * @returns {Map} + * @returns {Promise>} * mapping between instance id and information about this instance. * @private */ @@ -307,7 +307,7 @@ class Slave extends libLink.Link { let instanceInfo = this.instanceInfos.get(instance_id); if (instanceInfo) { instanceInfo.config.update(serialized_config, true, "master"); - logger.verbose(`Updated config for ${instanceInfo.path}`); + logger.verbose(`Updated config for ${instanceInfo.path}`, this.instanceLogMeta(instance_id, instanceInfo)); } else { instanceInfo = this.discoveredInstanceInfos.get(instance_id); @@ -320,6 +320,7 @@ class Slave extends libLink.Link { let instanceDir = await this._createNewInstanceDir(instanceConfig.get("instance.name")); + logger.info(`Creating ${instanceDir}`); await Instance.create(instanceDir, this.config.get("slave.factorio_directory")); instanceInfo = { path: instanceDir, @@ -367,6 +368,14 @@ class Slave extends libLink.Link { } } + instanceLogMeta(instanceId, instanceInfo) { + instanceInfo = instanceInfo || this.instanceInfos.get(instanceId); + if (!instanceInfo) { + return { instance_id: instanceId, instance_name: String(instanceId) }; + } + return { instance_id: instanceId, instance_name: instanceInfo.config.get("instance.name") }; + } + getRequestInstanceInfo(instanceId) { let instanceInfo = this.instanceInfos.get(instanceId); if (!instanceInfo) { @@ -379,7 +388,7 @@ class Slave extends libLink.Link { * Initialize and connect an unloaded instance * * @param {number} instanceId - ID of instance to initialize. - * @returns {module:slave/slave~InstanceConnection} connection to instance. + * @returns {Promise} connection to instance. */ async _connectInstance(instanceId) { let instanceInfo = this.getRequestInstanceInfo(instanceId); @@ -427,14 +436,30 @@ class Slave extends libLink.Link { async startInstanceRequestHandler(message, request) { let instanceId = message.data.instance_id; - let instanceConnection = await this._connectInstance(instanceId); - return await request.send(instanceConnection, message.data); + try { + let instanceConnection = await this._connectInstance(instanceId); + return await request.send(instanceConnection, message.data); + } catch (err) { + if (!(err instanceof libErrors.RequestError)) { + logger.error(`Error starting instance:\n${err.stack}`, this.instanceLogMeta(instanceId)); + throw new libErrors.RequestError(err.message); + } + throw err; + } } async loadScenarioRequestHandler(message, request) { let instanceId = message.data.instance_id; - let instanceConnection = await this._connectInstance(instanceId); - return await request.send(instanceConnection, message.data); + try { + let instanceConnection = await this._connectInstance(instanceId); + return await request.send(instanceConnection, message.data); + } catch (err) { + if (!(err instanceof libErrors.RequestError)) { + logger.error(`Error starting instance:\n${err.stack}`, this.instanceLogMeta(instanceId)); + throw new libErrors.RequestError(err.message); + } + throw err; + } } async listSavesRequestHandler(message, request) { @@ -452,8 +477,16 @@ class Slave extends libLink.Link { async createSaveRequestHandler(message, request) { let instanceId = message.data.instance_id; - let instanceConnection = await this._connectInstance(instanceId); - await request.send(instanceConnection, message.data); + try { + let instanceConnection = await this._connectInstance(instanceId); + await request.send(instanceConnection, message.data); + } catch (err) { + if (!(err instanceof libErrors.RequestError)) { + logger.error(`Error creating save:\n${err.stack}`, this.instanceLogMeta(instanceId)); + throw new libErrors.RequestError(err.message); + } + throw err; + } } async renameSaveRequestHandler(message) { @@ -629,13 +662,21 @@ class Slave extends libLink.Link { url, method: "PUT", core: { ca: this.tlsCa }, data: content, - }).catch(err => logger.error(`Error pushing save to master:\n${err.stack}`)); + }).catch(err => logger.error(`Error pushing save to master:\n${err.stack}`, this.instanceLogMeta(instance_id))); } async exportDataRequestHandler(message, request) { let instanceId = message.data.instance_id; - let instanceConnection = await this._connectInstance(instanceId); - await request.send(instanceConnection, message.data); + try { + let instanceConnection = await this._connectInstance(instanceId); + await request.send(instanceConnection, message.data); + } catch (err) { + if (!(err instanceof libErrors.RequestError)) { + logger.error(`Error exporting data:\n${err.stack}`, this.instanceLogMeta(instanceId)); + throw new libErrors.RequestError(err.message); + } + throw err; + } } async stopInstance(instanceId) { @@ -691,7 +732,8 @@ class Slave extends libLink.Link { }); } catch (err) { logger.error( - `Error during auto startup for ${instanceInfo.config.get("instance.name")}:\n${err.stack}` + `Error during auto startup for ${instanceInfo.config.get("instance.name")}:\n${err.stack}`, + this.instanceLogMeta(instanceId, instanceInfo) ); } } diff --git a/packages/web_ui/src/components/AssignInstanceModal.jsx b/packages/web_ui/src/components/AssignInstanceModal.jsx index 00e4b047..8035a7eb 100644 --- a/packages/web_ui/src/components/AssignInstanceModal.jsx +++ b/packages/web_ui/src/components/AssignInstanceModal.jsx @@ -28,6 +28,10 @@ export default function AssignInstanceModal(props) { return; } + if (slaveId === "null") { + slaveId = null; + } + setApplying(true); libLink.messages.assignInstanceCommand.send(control, { instance_id: props.id, @@ -67,9 +71,12 @@ export default function AssignInstanceModal(props) { the instance. Note that reassigning an instance from one slave to another will not move the server save over. -
+