Make metrics gathering timeout configurable

When reducing the collection interval in Prometheus it may be necessary
to to reduce the metrics gathering timeout to ensure it's less than the
interval.  Add config options to adjust the timeouts used for metrics
gathering so that these can be set accordingly.
This commit is contained in:
Hornwitser committed 2020-12-28 07:03:32 +01:00
1 parent 699e3994df
commit 6eef4bd300
9 files changed
+63 -9

No files matched your search

+16 -1
View File
@@ -7,7 +7,7 @@ Clusterio.
Installation
============
------------
Run the following commands in the folder Clusterio is installed to:
@@ -16,3 +16,18 @@ Run the following commands in the folder Clusterio is installed to:
Substitute clusteriomaster with clusterioslave or clusterioctl if this a
dedicate slave or ctl installation respectively.
Instance Configuration
----------------------
### statistics_exporter.command_timeout
Timeout in seconds to wait for the statitics gathering command to the
Factorio server return the result. If the timeout is exceeded the
previous collected results are returned instead. Normally the command
returns immediatly with the data, but if the RCON interface is
overloaded then the command may take too long to timely answer the
metrics collection request.
Defaults to `1`.
+13
View File
@@ -1,8 +1,21 @@
"use strict";
const libConfig = require("@clusterio/lib/config");
class InstanceConfigGroup extends libConfig.PluginConfigGroup {}
InstanceConfigGroup.groupName = "statistics_exporter";
InstanceConfigGroup.define({
name: "command_timeout",
title: "Command Timeout",
description: "Timeout in seconds of the metrics command before returning results from the previous invocation.",
type: "number",
initial_value: 1,
});
InstanceConfigGroup.finalize();
module.exports = {
name: "statistics_exporter",
title: "Prometheus Statistics Export",
description: "Exports statistics to Prometheus",
instanceEntrypoint: "instance",
InstanceConfigGroup,
};
+4 -3
View File
@@ -73,11 +73,12 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
}
async onMetrics() {
// Wait up to 5 seconds for the metrics to be collected. It may
// Wait configured timeout for the metrics to be collected. It may
// take a long time for the command to go through if the command
// stream is overloaded. Should this take more than 5 seconds the
// stream is overloaded. Should the timeout be exceeded the
// previous values for the metrics will end up being sent to master.
await libHelpers.timeout(this.gatherMetrics(), 5e3);
let timeout = this.instance.config.get("statistics_exporter.command_timeout") * 1000;
await libHelpers.timeout(this.gatherMetrics(), timeout);
}
}
+3 -1
View File
@@ -9,8 +9,10 @@ const info = require("../info");
describe("statistics_exporter plugin", function() {
describe("class InstancePlugin", function() {
let instancePlugin;
let mockInstance = new mock.MockInstance();
mockInstance.mockConfigEntries.set("statistics_exporter.command_timeout", 1);
before(async function() {
instancePlugin = new instance.InstancePlugin(info, new mock.MockInstance());
instancePlugin = new instance.InstancePlugin(info, mockInstance);
await instancePlugin.init();
});