iobroker.influxdb 5.0.2 → 5.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -3
- package/build/lib/Database.js +60 -1
- package/build/lib/Database.js.map +1 -1
- package/build/lib/DatabaseInfluxDB1x.js +13 -9
- package/build/lib/DatabaseInfluxDB1x.js.map +1 -1
- package/build/lib/DatabaseInfluxDB2x.js +15 -12
- package/build/lib/DatabaseInfluxDB2x.js.map +1 -1
- package/build/lib/errors.js +224 -0
- package/build/lib/errors.js.map +1 -0
- package/build/main.js +189 -89
- package/build/main.js.map +1 -1
- package/io-package.json +14 -14
- package/package.json +11 -1
package/build/main.js
CHANGED
|
@@ -11,11 +11,14 @@ const aggregate_1 = require("@iobroker/aggregate");
|
|
|
11
11
|
const DatabaseInfluxDB1x_1 = __importDefault(require("./lib/DatabaseInfluxDB1x"));
|
|
12
12
|
const DatabaseInfluxDB2x_1 = __importDefault(require("./lib/DatabaseInfluxDB2x"));
|
|
13
13
|
const Database_1 = require("./lib/Database");
|
|
14
|
+
const errors_1 = require("./lib/errors");
|
|
14
15
|
const plugin_docker_1 = require("@iobroker/plugin-docker");
|
|
15
16
|
const dataDir = (0, adapter_core_1.getAbsoluteDefaultDataDir)();
|
|
16
17
|
const dockerDefaultToken = Buffer.from('iobroker86645638546565652656').toString('base64');
|
|
17
18
|
/** Maximal number of entries one `getRawEntries` call may return */
|
|
18
19
|
const MAX_RAW_ENTRIES = 2000;
|
|
20
|
+
// While the database stays unreachable, remind about it at most once an hour instead of on every retry
|
|
21
|
+
const REPEATED_ERROR_INTERVAL = 3_600_000;
|
|
19
22
|
/** Oldest timestamp the data browser looks at. The adapter never writes a point before the epoch */
|
|
20
23
|
const MIN_INFLUX_TIME = 0;
|
|
21
24
|
/** Newest timestamp a Flux range may stop at. InfluxDB cannot store anything after it */
|
|
@@ -46,21 +49,6 @@ function isObject(it) {
|
|
|
46
49
|
// [] instanceof Object === true
|
|
47
50
|
return Object.prototype.toString.call(it) === '[object Object]';
|
|
48
51
|
}
|
|
49
|
-
function extractError(error) {
|
|
50
|
-
if (typeof error === 'string') {
|
|
51
|
-
return error;
|
|
52
|
-
}
|
|
53
|
-
if (error instanceof Error) {
|
|
54
|
-
if (Array.isArray(error.errors) && error.errors.length) {
|
|
55
|
-
return error.errors.map((e) => (e.message ? e.message : JSON.stringify(e))).join(', ');
|
|
56
|
-
}
|
|
57
|
-
return error.message;
|
|
58
|
-
}
|
|
59
|
-
if (error === null || error === undefined) {
|
|
60
|
-
return 'null';
|
|
61
|
-
}
|
|
62
|
-
return error.toString();
|
|
63
|
-
}
|
|
64
52
|
function parseBool(value, defaultValue) {
|
|
65
53
|
if (value !== undefined && value !== null && value !== '') {
|
|
66
54
|
return value === true || value === 'true' || value === 1 || value === '1';
|
|
@@ -146,6 +134,12 @@ class InfluxDBAdapter extends adapter_core_1.Adapter {
|
|
|
146
134
|
_finished = false;
|
|
147
135
|
// mapping from ioBroker ID to Alias ID
|
|
148
136
|
_aliasMap = {};
|
|
137
|
+
// IDs (plus the reason) that were already reported as "value can not be stored", see logSkipOnce()
|
|
138
|
+
_warnedValueIDs = new Set();
|
|
139
|
+
// Connection errors already reported, so a database that is switched off does not repeat the same
|
|
140
|
+
// line forever. Keyed by the message: writes, reconnects and pings fail with different texts, and
|
|
141
|
+
// one shared slot would let them cancel each other's throttling out.
|
|
142
|
+
_connectionErrors = new Map();
|
|
149
143
|
// Per-instance cache file (must NOT be a module global, otherwise instances collide in compact mode)
|
|
150
144
|
_cacheFile = (0, node_path_1.join)(dataDir, 'influxdata.json');
|
|
151
145
|
constructor(options = {}) {
|
|
@@ -261,6 +255,93 @@ class InfluxDBAdapter extends adapter_core_1.Adapter {
|
|
|
261
255
|
: this.log.debug(`connected set to ${this._connected}`));
|
|
262
256
|
}
|
|
263
257
|
}
|
|
258
|
+
/**
|
|
259
|
+
* Log a connection error without flooding the log.
|
|
260
|
+
*
|
|
261
|
+
* A database that is simply switched off makes every write and every reconnect fail, so the very same
|
|
262
|
+
* line would otherwise be written hundreds of times per minute (and into syslog as well). The first
|
|
263
|
+
* occurrence is logged as error, repetitions of the identical message go to debug, and once an hour a
|
|
264
|
+
* reminder is logged that the database is still unreachable.
|
|
265
|
+
*
|
|
266
|
+
* @param error error to report
|
|
267
|
+
* @param prefix optional text in front of the error message
|
|
268
|
+
*/
|
|
269
|
+
logConnectionError(error, prefix) {
|
|
270
|
+
const text = `${prefix ? `${prefix}: ` : ''}${(0, errors_1.formatError)(error)}`;
|
|
271
|
+
const now = Date.now();
|
|
272
|
+
const known = this._connectionErrors.get(text);
|
|
273
|
+
if (known) {
|
|
274
|
+
known.count++;
|
|
275
|
+
known.lastSeen = now;
|
|
276
|
+
if (now - known.lastLogged >= REPEATED_ERROR_INTERVAL) {
|
|
277
|
+
known.lastLogged = now;
|
|
278
|
+
this.log.error(`${text} (still failing, ${known.count} attempts)`);
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
this.log.debug(`${text} (attempt ${known.count})`);
|
|
282
|
+
}
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
// an error that stopped occurring is reported in full again when it comes back
|
|
286
|
+
for (const [key, value] of this._connectionErrors) {
|
|
287
|
+
if (now - value.lastSeen >= REPEATED_ERROR_INTERVAL) {
|
|
288
|
+
this._connectionErrors.delete(key);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
this._connectionErrors.set(text, { lastLogged: now, lastSeen: now, count: 1 });
|
|
292
|
+
this.log.error(text);
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Report a value that InfluxDB can not store - once per datapoint and reason.
|
|
296
|
+
*
|
|
297
|
+
* Adapters that deliver `null`, `NaN` or a string for a number datapoint do so on every update (some
|
|
298
|
+
* every two seconds), and the value is skipped every time. Logging that on every state change makes
|
|
299
|
+
* the ioBroker log unusable, so the first occurrence is logged and the repetitions go to debug.
|
|
300
|
+
*
|
|
301
|
+
* @param id datapoint the value belongs to
|
|
302
|
+
* @param error the error thrown by pushHelper()
|
|
303
|
+
*/
|
|
304
|
+
logSkipOnce(id, error) {
|
|
305
|
+
const key = `${error.kind}:${id}`;
|
|
306
|
+
if (this._warnedValueIDs.has(key)) {
|
|
307
|
+
this.log.debug(error.message);
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
this._warnedValueIDs.add(key);
|
|
311
|
+
this.log.info(`${error.message} (this message is logged only once per datapoint)`);
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Log whatever came out of a write: connection errors and unstorable values are throttled, everything
|
|
315
|
+
* else is a real problem and is logged as before.
|
|
316
|
+
*
|
|
317
|
+
* @param id datapoint the value belongs to
|
|
318
|
+
* @param error the caught error
|
|
319
|
+
*/
|
|
320
|
+
logPushError(id, error) {
|
|
321
|
+
if (error instanceof errors_1.UnstorableValueError) {
|
|
322
|
+
this.logSkipOnce(id, error);
|
|
323
|
+
}
|
|
324
|
+
else if ((0, errors_1.isConnectionError)(error)) {
|
|
325
|
+
this.logConnectionError(error, `Cannot write value of ${id}`);
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
this.log.warn(`Cannot write value of ${id}: ${(0, errors_1.formatError)(error)}`);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Log why the buffered points could not be written: an unreachable database is throttled, anything
|
|
333
|
+
* else is a real error.
|
|
334
|
+
*
|
|
335
|
+
* @param error the caught error
|
|
336
|
+
*/
|
|
337
|
+
logBufferError(error) {
|
|
338
|
+
if ((0, errors_1.isConnectionError)(error)) {
|
|
339
|
+
this.logConnectionError(error, 'Cannot store buffered series');
|
|
340
|
+
}
|
|
341
|
+
else {
|
|
342
|
+
this.log.error(`Cannot store buffered series: ${(0, errors_1.formatError)(error)}`);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
264
345
|
reconnect() {
|
|
265
346
|
this.setConnected(false);
|
|
266
347
|
this.stopPing();
|
|
@@ -292,7 +373,7 @@ class InfluxDBAdapter extends adapter_core_1.Adapter {
|
|
|
292
373
|
}
|
|
293
374
|
}
|
|
294
375
|
catch (error) {
|
|
295
|
-
this.
|
|
376
|
+
this.logConnectionError(error, 'Error during ping, attempting reconnect');
|
|
296
377
|
this.reconnect();
|
|
297
378
|
}
|
|
298
379
|
}
|
|
@@ -378,7 +459,7 @@ class InfluxDBAdapter extends adapter_core_1.Adapter {
|
|
|
378
459
|
}
|
|
379
460
|
catch (error) {
|
|
380
461
|
// Ignore issues with creating/altering retention policy, as it might be due to insufficient permissions
|
|
381
|
-
this.log.warn(
|
|
462
|
+
this.log.warn((0, errors_1.formatError)(error));
|
|
382
463
|
}
|
|
383
464
|
if (this.config.dbversion === '2.x') {
|
|
384
465
|
// For 2.x the connection is finalized inside checkMetaDataStorageType (after the
|
|
@@ -395,7 +476,9 @@ class InfluxDBAdapter extends adapter_core_1.Adapter {
|
|
|
395
476
|
}
|
|
396
477
|
}
|
|
397
478
|
catch (error) {
|
|
398
|
-
|
|
479
|
+
// The reconnect loop retries forever, so an unreachable database must not repeat the same
|
|
480
|
+
// line every reconnectInterval - that is what fills the log (and syslog) of a stopped DB.
|
|
481
|
+
this.logConnectionError(error, 'Cannot connect to InfluxDB');
|
|
399
482
|
this.reconnect();
|
|
400
483
|
}
|
|
401
484
|
}
|
|
@@ -418,7 +501,15 @@ class InfluxDBAdapter extends adapter_core_1.Adapter {
|
|
|
418
501
|
}
|
|
419
502
|
}
|
|
420
503
|
catch (error) {
|
|
421
|
-
|
|
504
|
+
if ((0, errors_1.isConnectionError)(error)) {
|
|
505
|
+
// Without this the adapter would stay disconnected: the outer connect() already
|
|
506
|
+
// returned, so nobody else schedules a new attempt.
|
|
507
|
+
this.logConnectionError(error, 'Error checking for metadata storage type');
|
|
508
|
+
this.reconnect();
|
|
509
|
+
}
|
|
510
|
+
else {
|
|
511
|
+
this.log.error(`Error checking for metadata storage type: ${(0, errors_1.formatError)(error)}`);
|
|
512
|
+
}
|
|
422
513
|
}
|
|
423
514
|
}
|
|
424
515
|
async processStartValues() {
|
|
@@ -435,7 +526,7 @@ class InfluxDBAdapter extends adapter_core_1.Adapter {
|
|
|
435
526
|
this.sendTo(msg.from, msg.command, { result }, msg.callback);
|
|
436
527
|
}
|
|
437
528
|
catch (error) {
|
|
438
|
-
this.sendTo(msg.from, msg.command, { error:
|
|
529
|
+
this.sendTo(msg.from, msg.command, { error: (0, errors_1.formatError)(error) }, msg.callback);
|
|
439
530
|
}
|
|
440
531
|
}
|
|
441
532
|
getDockerConfigInflux(config) {
|
|
@@ -582,7 +673,7 @@ class InfluxDBAdapter extends adapter_core_1.Adapter {
|
|
|
582
673
|
if (timeout) {
|
|
583
674
|
clearTimeout(timeout);
|
|
584
675
|
timeout = null;
|
|
585
|
-
return this.sendTo(msg.from, msg.command, { error:
|
|
676
|
+
return this.sendTo(msg.from, msg.command, { error: (0, errors_1.formatError)(error) }, msg.callback);
|
|
586
677
|
}
|
|
587
678
|
}
|
|
588
679
|
if (dockerCreated && dockerManager) {
|
|
@@ -590,7 +681,7 @@ class InfluxDBAdapter extends adapter_core_1.Adapter {
|
|
|
590
681
|
await dockerManager.destroy();
|
|
591
682
|
}
|
|
592
683
|
catch (e) {
|
|
593
|
-
this.log.error(`Cannot stop docker container: ${
|
|
684
|
+
this.log.error(`Cannot stop docker container: ${(0, errors_1.formatError)(e)}`);
|
|
594
685
|
}
|
|
595
686
|
}
|
|
596
687
|
}
|
|
@@ -599,11 +690,13 @@ class InfluxDBAdapter extends adapter_core_1.Adapter {
|
|
|
599
690
|
clearTimeout(timeout);
|
|
600
691
|
timeout = null;
|
|
601
692
|
}
|
|
602
|
-
|
|
693
|
+
// The driver package is loaded lazily, and a missing one shows up as a TypeError here.
|
|
694
|
+
// (Comparing the formatted text would break as soon as the wording changes.)
|
|
695
|
+
if (error instanceof TypeError && error.message.includes('undefined is not a function')) {
|
|
603
696
|
this.sendTo(msg.from, msg.command, { error: 'Node.js DB driver could not be installed.' }, msg.callback);
|
|
604
697
|
return;
|
|
605
698
|
}
|
|
606
|
-
this.sendTo(msg.from, msg.command, { error:
|
|
699
|
+
this.sendTo(msg.from, msg.command, { error: (0, errors_1.formatError)(error) }, msg.callback);
|
|
607
700
|
}
|
|
608
701
|
}
|
|
609
702
|
async destroyDB(msg) {
|
|
@@ -639,7 +732,7 @@ class InfluxDBAdapter extends adapter_core_1.Adapter {
|
|
|
639
732
|
}
|
|
640
733
|
catch (error) {
|
|
641
734
|
// Ignore issues with creating/altering retention policy, as it might be due to insufficient permissions
|
|
642
|
-
this.log.warn(
|
|
735
|
+
this.log.warn((0, errors_1.formatError)(error));
|
|
643
736
|
}
|
|
644
737
|
if (this.config.dbversion === '2.x') {
|
|
645
738
|
await this.checkMetaDataStorageType();
|
|
@@ -648,7 +741,7 @@ class InfluxDBAdapter extends adapter_core_1.Adapter {
|
|
|
648
741
|
}
|
|
649
742
|
}
|
|
650
743
|
catch (error) {
|
|
651
|
-
this.sendTo(msg.from, msg.command, { error:
|
|
744
|
+
this.sendTo(msg.from, msg.command, { error: (0, errors_1.formatError)(error) }, msg.callback);
|
|
652
745
|
}
|
|
653
746
|
}
|
|
654
747
|
async processMessage(msg) {
|
|
@@ -728,7 +821,7 @@ class InfluxDBAdapter extends adapter_core_1.Adapter {
|
|
|
728
821
|
}
|
|
729
822
|
catch (error) {
|
|
730
823
|
if (msg.callback) {
|
|
731
|
-
this.sendTo(msg.from, msg.command, { error:
|
|
824
|
+
this.sendTo(msg.from, msg.command, { error: (0, errors_1.formatError)(error) }, msg.callback);
|
|
732
825
|
}
|
|
733
826
|
}
|
|
734
827
|
}
|
|
@@ -760,9 +853,9 @@ class InfluxDBAdapter extends adapter_core_1.Adapter {
|
|
|
760
853
|
}
|
|
761
854
|
}
|
|
762
855
|
catch (error) {
|
|
763
|
-
this.log.error(`Cannot process message ${msg.command}: ${
|
|
856
|
+
this.log.error(`Cannot process message ${msg.command}: ${(0, errors_1.formatError)(error)}`);
|
|
764
857
|
if (msg.callback) {
|
|
765
|
-
this.sendTo(msg.from, msg.command, { error:
|
|
858
|
+
this.sendTo(msg.from, msg.command, { error: (0, errors_1.formatError)(error) }, msg.callback);
|
|
766
859
|
}
|
|
767
860
|
}
|
|
768
861
|
}
|
|
@@ -920,7 +1013,7 @@ class InfluxDBAdapter extends adapter_core_1.Adapter {
|
|
|
920
1013
|
// store all buffered data every x seconds to not lost the data
|
|
921
1014
|
this._seriesBufferChecker = setInterval(() => {
|
|
922
1015
|
this._seriesBufferFlushPlanned = true;
|
|
923
|
-
void this.storeBufferedSeries().catch(e => this.
|
|
1016
|
+
void this.storeBufferedSeries().catch(e => this.logBufferError(e));
|
|
924
1017
|
}, this.config.seriesBufferFlushInterval * 1000);
|
|
925
1018
|
}
|
|
926
1019
|
}
|
|
@@ -968,7 +1061,7 @@ datasources:
|
|
|
968
1061
|
return;
|
|
969
1062
|
}
|
|
970
1063
|
if (state && state.val === undefined) {
|
|
971
|
-
this.
|
|
1064
|
+
this.logSkipOnce(id, new errors_1.UnstorableValueError('null', `state value undefined received for ${id} which is not allowed. Ignoring.`));
|
|
972
1065
|
return;
|
|
973
1066
|
}
|
|
974
1067
|
if (typeof state.val === 'string' && settings.storageType !== 'String') {
|
|
@@ -1099,7 +1192,7 @@ datasources:
|
|
|
1099
1192
|
await this.pushHelper(id, this._influxDPs[id].skipped);
|
|
1100
1193
|
}
|
|
1101
1194
|
catch (e) {
|
|
1102
|
-
this.
|
|
1195
|
+
this.logPushError(id, e);
|
|
1103
1196
|
}
|
|
1104
1197
|
this._influxDPs[id].skipped = null;
|
|
1105
1198
|
}
|
|
@@ -1121,7 +1214,7 @@ datasources:
|
|
|
1121
1214
|
this._influxDPs[id].lastLogTime = state.ts;
|
|
1122
1215
|
settings.enableDebugLogs &&
|
|
1123
1216
|
this.log.debug(`Value logged ${id}, value=${this._influxDPs[id].state.val}, ts=${this._influxDPs[id].state.ts}`);
|
|
1124
|
-
void this.pushHelper(id).catch(e => this.
|
|
1217
|
+
void this.pushHelper(id).catch(e => this.logPushError(id, e));
|
|
1125
1218
|
if (settings.changesOnly && settings.changesRelogInterval > 0) {
|
|
1126
1219
|
this._influxDPs[id].relogTimeout = setTimeout(_id => this.reLogHelper(_id), settings.changesRelogInterval * 1000, id);
|
|
1127
1220
|
}
|
|
@@ -1135,7 +1228,7 @@ datasources:
|
|
|
1135
1228
|
if (settings.enableDebugLogs) {
|
|
1136
1229
|
this.log.debug(`Value logged ${id}, value=${this._influxDPs[id].state.val}, ts=${this._influxDPs[id].state.ts}`);
|
|
1137
1230
|
}
|
|
1138
|
-
void this.pushHelper(id, state).catch(e => this.
|
|
1231
|
+
void this.pushHelper(id, state).catch(e => this.logPushError(id, e));
|
|
1139
1232
|
if (settings.changesOnly && settings.changesRelogInterval > 0) {
|
|
1140
1233
|
this._influxDPs[id].relogTimeout = setTimeout(_id => this.reLogHelper(_id), settings.changesRelogInterval * 1000, id);
|
|
1141
1234
|
}
|
|
@@ -1167,7 +1260,7 @@ datasources:
|
|
|
1167
1260
|
}
|
|
1168
1261
|
}
|
|
1169
1262
|
catch (error) {
|
|
1170
|
-
this.log.info(`init timed Relog: can not get State for ${_id}: ${
|
|
1263
|
+
this.log.info(`init timed Relog: can not get State for ${_id}: ${(0, errors_1.formatError)(error)}`);
|
|
1171
1264
|
}
|
|
1172
1265
|
}
|
|
1173
1266
|
}
|
|
@@ -1181,13 +1274,14 @@ datasources:
|
|
|
1181
1274
|
}
|
|
1182
1275
|
// Important: We allow also to store "unknown" states, so use fallback here
|
|
1183
1276
|
const _settings = this._influxDPs[_id] || {};
|
|
1277
|
+
// InfluxDB can not handle null or non-finite values. The error is thrown (and not just logged),
|
|
1278
|
+
// because storeState() has to answer with it instead of a silent "success"; the state-change path
|
|
1279
|
+
// catches it and logs it once per datapoint, see logSkipOnce().
|
|
1184
1280
|
if (state.val === null) {
|
|
1185
|
-
|
|
1186
|
-
throw new Error(`null value for ${_id} can not be handled`);
|
|
1281
|
+
throw new errors_1.UnstorableValueError('null', `Skipping null value for ${_id}: InfluxDB can not store null`);
|
|
1187
1282
|
}
|
|
1188
1283
|
if (typeof state.val === 'number' && !isFinite(state.val)) {
|
|
1189
|
-
|
|
1190
|
-
throw new Error(`Non Finite value ${state.val} for ${_id} can not be handled`);
|
|
1284
|
+
throw new errors_1.UnstorableValueError('nonFinite', `Skipping non-finite value (${state.val}) for ${_id}: InfluxDB can not store NaN/Infinity`);
|
|
1191
1285
|
}
|
|
1192
1286
|
if (state.val !== null && (typeof state.val === 'object' || typeof state.val === 'undefined')) {
|
|
1193
1287
|
state.val = JSON.stringify(state.val);
|
|
@@ -1214,8 +1308,7 @@ datasources:
|
|
|
1214
1308
|
state.val = state.val ? 1 : 0;
|
|
1215
1309
|
}
|
|
1216
1310
|
else {
|
|
1217
|
-
|
|
1218
|
-
throw new Error(`do not store value for ${_id} because no number`);
|
|
1311
|
+
throw new errors_1.UnstorableValueError('type', `Skipping value "${state.val}" for ${_id}: not a number, but storageType is "Number"`);
|
|
1219
1312
|
}
|
|
1220
1313
|
}
|
|
1221
1314
|
else if (_settings.storageType === 'Boolean' && typeof state.val !== 'boolean') {
|
|
@@ -1299,14 +1392,14 @@ datasources:
|
|
|
1299
1392
|
}
|
|
1300
1393
|
if (!this._client?.getHostsAvailable()) {
|
|
1301
1394
|
this.setConnected(false);
|
|
1302
|
-
this.log.info('Currently no hosts available, try later');
|
|
1303
1395
|
this._seriesBufferFlushPlanned = false;
|
|
1304
|
-
|
|
1396
|
+
// Points stay in the buffer and the next flush tries again - that is normal operation while
|
|
1397
|
+
// the database is down and must not be logged on every buffered value.
|
|
1398
|
+
throw new errors_1.HostUnavailableError('Currently no host available, try later');
|
|
1305
1399
|
}
|
|
1306
1400
|
if (!this._connected) {
|
|
1307
|
-
this.log.info('Not connected to InfluxDB, try later');
|
|
1308
1401
|
this._seriesBufferFlushPlanned = false;
|
|
1309
|
-
throw new
|
|
1402
|
+
throw new errors_1.HostUnavailableError('Not connected to InfluxDB, try later');
|
|
1310
1403
|
}
|
|
1311
1404
|
if (id) {
|
|
1312
1405
|
const idSeries = this._seriesBuffer[id];
|
|
@@ -1339,7 +1432,9 @@ datasources:
|
|
|
1339
1432
|
await this.writeAllSeriesAtOnce(currentBuffer);
|
|
1340
1433
|
}
|
|
1341
1434
|
this._seriesBufferFlushPlanned = false;
|
|
1342
|
-
this._seriesBufferChecker = setInterval(
|
|
1435
|
+
this._seriesBufferChecker = setInterval(
|
|
1436
|
+
// the rejection must be caught here: an unhandled one terminates the process
|
|
1437
|
+
() => void this.storeBufferedSeries().catch(e => this.logBufferError(e)), this.config.seriesBufferFlushInterval * 1000);
|
|
1343
1438
|
return result;
|
|
1344
1439
|
}
|
|
1345
1440
|
async writeAllSeriesAtOnce(series) {
|
|
@@ -1348,8 +1443,8 @@ datasources:
|
|
|
1348
1443
|
this.setConnected(true);
|
|
1349
1444
|
}
|
|
1350
1445
|
catch (error) {
|
|
1351
|
-
this.
|
|
1352
|
-
|
|
1446
|
+
if (!this._client?.getHostsAvailable() || (0, errors_1.isConnectionError)(error)) {
|
|
1447
|
+
this.logConnectionError(error, 'Error on writeSeries');
|
|
1353
1448
|
this.setConnected(false);
|
|
1354
1449
|
this.log.info('Host not available, move all points back in the Buffer');
|
|
1355
1450
|
// error caused InfluxDB this._client to remove the host from available for now
|
|
@@ -1363,7 +1458,8 @@ datasources:
|
|
|
1363
1458
|
this.reconnect();
|
|
1364
1459
|
}
|
|
1365
1460
|
else {
|
|
1366
|
-
const errorText =
|
|
1461
|
+
const errorText = (0, errors_1.formatError)(error);
|
|
1462
|
+
this.log.warn(`Error on writeSeries: ${errorText}`);
|
|
1367
1463
|
if (errorText && errorText.includes('partial write') && !errorText.includes('field type conflict')) {
|
|
1368
1464
|
this.log.warn('All possible data points were written, others can not really be corrected');
|
|
1369
1465
|
}
|
|
@@ -1400,10 +1496,11 @@ datasources:
|
|
|
1400
1496
|
this.setConnected(true);
|
|
1401
1497
|
}
|
|
1402
1498
|
catch (error) {
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
this.
|
|
1499
|
+
// A connection error hits every point alike - splitting the batch down to single points
|
|
1500
|
+
// would only repeat the same error for each of them and flood the log.
|
|
1501
|
+
if (!this._client?.getHostsAvailable() || (0, errors_1.isConnectionError)(error)) {
|
|
1502
|
+
this.logConnectionError(error, `Error on writePoints for ${seriesId}`);
|
|
1503
|
+
this.log.debug('Host not available, move all points back in the Buffer');
|
|
1407
1504
|
// error caused InfluxDB this._client to remove the host from available for now
|
|
1408
1505
|
this._seriesBuffer[seriesId] ||= [];
|
|
1409
1506
|
for (let i = 0; i < pointsToSend.length; i++) {
|
|
@@ -1417,6 +1514,7 @@ datasources:
|
|
|
1417
1514
|
this.reconnect();
|
|
1418
1515
|
return;
|
|
1419
1516
|
}
|
|
1517
|
+
this.log.warn(`Error on writePoints for ${seriesId}: ${(0, errors_1.formatError)(error)}`);
|
|
1420
1518
|
this.log.warn(`Try to write ${pointsToSend.length} Points separate to find the conflicting one`);
|
|
1421
1519
|
// we found the conflicting id
|
|
1422
1520
|
await this.writePointsForID(seriesId, pointsToSend);
|
|
@@ -1448,13 +1546,14 @@ datasources:
|
|
|
1448
1546
|
}
|
|
1449
1547
|
}
|
|
1450
1548
|
catch (error) {
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1549
|
+
const errorText = (0, errors_1.formatError)(error);
|
|
1550
|
+
if (!this._client?.getHostsAvailable() || (0, errors_1.isConnectionError)(error)) {
|
|
1551
|
+
this.logConnectionError(error, `Error on writePoint for ${pointId}`);
|
|
1454
1552
|
this.reconnect();
|
|
1455
1553
|
await this.addPointToSeriesBuffer(pointId, point);
|
|
1456
1554
|
}
|
|
1457
1555
|
else if (errorText.includes('field type conflict')) {
|
|
1556
|
+
this.log.warn(`Error on writePoint("${JSON.stringify(point)}): ${errorText}"`);
|
|
1458
1557
|
// retry write after type correction for some easy cases
|
|
1459
1558
|
let retry = false;
|
|
1460
1559
|
let adjustType = false;
|
|
@@ -1533,6 +1632,7 @@ datasources:
|
|
|
1533
1632
|
}
|
|
1534
1633
|
}
|
|
1535
1634
|
else {
|
|
1635
|
+
this.log.warn(`Error on writePoint("${JSON.stringify(point)}): ${errorText}"`);
|
|
1536
1636
|
if (!this._errorPoints[pointId]) {
|
|
1537
1637
|
this._errorPoints[pointId] = 1;
|
|
1538
1638
|
}
|
|
@@ -1564,7 +1664,7 @@ datasources:
|
|
|
1564
1664
|
this.log.warn(`Store data for ${fileData.seriesBufferCounter} points and ${Object.keys(fileData.conflictingPoints).length} conflicts`);
|
|
1565
1665
|
}
|
|
1566
1666
|
catch (error) {
|
|
1567
|
-
this.log.warn(`Could not save non-stored data to file: ${
|
|
1667
|
+
this.log.warn(`Could not save non-stored data to file: ${(0, errors_1.formatError)(error)}`);
|
|
1568
1668
|
}
|
|
1569
1669
|
}
|
|
1570
1670
|
this._seriesBufferCounter = 0;
|
|
@@ -1593,7 +1693,7 @@ datasources:
|
|
|
1593
1693
|
this.setConnected(true);
|
|
1594
1694
|
}
|
|
1595
1695
|
catch (error) {
|
|
1596
|
-
this.log.warn(`Error on delete("${query}): ${
|
|
1696
|
+
this.log.warn(`Error on delete("${query}): ${(0, errors_1.formatError)(error)}"`);
|
|
1597
1697
|
throw error;
|
|
1598
1698
|
}
|
|
1599
1699
|
}
|
|
@@ -1631,7 +1731,7 @@ datasources:
|
|
|
1631
1731
|
}
|
|
1632
1732
|
}
|
|
1633
1733
|
catch (error) {
|
|
1634
|
-
this.log.warn(`Error on delete("${
|
|
1734
|
+
this.log.warn(`Error on delete("${(0, errors_1.formatError)(error)}"`);
|
|
1635
1735
|
throw error;
|
|
1636
1736
|
}
|
|
1637
1737
|
}
|
|
@@ -1743,7 +1843,7 @@ datasources:
|
|
|
1743
1843
|
catch (error) {
|
|
1744
1844
|
this.sendTo(msg.from, msg.command, {
|
|
1745
1845
|
success: false,
|
|
1746
|
-
error:
|
|
1846
|
+
error: (0, errors_1.formatError)(error),
|
|
1747
1847
|
connected: !!this._connected,
|
|
1748
1848
|
}, msg.callback);
|
|
1749
1849
|
}
|
|
@@ -1761,7 +1861,7 @@ datasources:
|
|
|
1761
1861
|
catch (error) {
|
|
1762
1862
|
this.sendTo(msg.from, msg.command, {
|
|
1763
1863
|
success: false,
|
|
1764
|
-
error:
|
|
1864
|
+
error: (0, errors_1.formatError)(error),
|
|
1765
1865
|
connected: !!this._connected,
|
|
1766
1866
|
}, msg.callback);
|
|
1767
1867
|
}
|
|
@@ -1800,7 +1900,7 @@ datasources:
|
|
|
1800
1900
|
catch (error) {
|
|
1801
1901
|
this.sendTo(msg.from, msg.command, {
|
|
1802
1902
|
success: false,
|
|
1803
|
-
error:
|
|
1903
|
+
error: (0, errors_1.formatError)(error),
|
|
1804
1904
|
connected: !!this._connected,
|
|
1805
1905
|
}, msg.callback);
|
|
1806
1906
|
}
|
|
@@ -1818,7 +1918,7 @@ datasources:
|
|
|
1818
1918
|
catch (error) {
|
|
1819
1919
|
this.sendTo(msg.from, msg.command, {
|
|
1820
1920
|
success: false,
|
|
1821
|
-
error:
|
|
1921
|
+
error: (0, errors_1.formatError)(error),
|
|
1822
1922
|
connected: !!this._connected,
|
|
1823
1923
|
}, msg.callback);
|
|
1824
1924
|
}
|
|
@@ -1955,7 +2055,7 @@ datasources:
|
|
|
1955
2055
|
catch (error) {
|
|
1956
2056
|
this.sendTo(msg.from, msg.command, {
|
|
1957
2057
|
success: false,
|
|
1958
|
-
error:
|
|
2058
|
+
error: (0, errors_1.formatError)(error),
|
|
1959
2059
|
connected: !!this._connected,
|
|
1960
2060
|
}, msg.callback);
|
|
1961
2061
|
}
|
|
@@ -1977,7 +2077,7 @@ datasources:
|
|
|
1977
2077
|
catch (error) {
|
|
1978
2078
|
this.sendTo(msg.from, msg.command, {
|
|
1979
2079
|
success: false,
|
|
1980
|
-
error:
|
|
2080
|
+
error: (0, errors_1.formatError)(error),
|
|
1981
2081
|
connected: !!this._connected,
|
|
1982
2082
|
}, msg.callback);
|
|
1983
2083
|
}
|
|
@@ -1992,7 +2092,7 @@ datasources:
|
|
|
1992
2092
|
catch (error) {
|
|
1993
2093
|
this.sendTo(msg.from, msg.command, {
|
|
1994
2094
|
success: !error,
|
|
1995
|
-
error:
|
|
2095
|
+
error: (0, errors_1.formatError)(error),
|
|
1996
2096
|
connected: !!this._connected,
|
|
1997
2097
|
}, msg.callback);
|
|
1998
2098
|
}
|
|
@@ -2023,7 +2123,7 @@ datasources:
|
|
|
2023
2123
|
}
|
|
2024
2124
|
}
|
|
2025
2125
|
catch (error) {
|
|
2026
|
-
throw new Error(`Error writing state for ${id}: ${
|
|
2126
|
+
throw new Error(`Error writing state for ${id}: ${(0, errors_1.formatError)(error)}, Data: ${JSON.stringify(state)}`);
|
|
2027
2127
|
}
|
|
2028
2128
|
}
|
|
2029
2129
|
async storeState(msg) {
|
|
@@ -2045,7 +2145,7 @@ datasources:
|
|
|
2045
2145
|
successCount++;
|
|
2046
2146
|
}
|
|
2047
2147
|
catch (error) {
|
|
2048
|
-
errors.push(
|
|
2148
|
+
errors.push((0, errors_1.formatError)(error));
|
|
2049
2149
|
}
|
|
2050
2150
|
}
|
|
2051
2151
|
}
|
|
@@ -2058,7 +2158,7 @@ datasources:
|
|
|
2058
2158
|
successCount++;
|
|
2059
2159
|
}
|
|
2060
2160
|
catch (error) {
|
|
2061
|
-
errors.push(
|
|
2161
|
+
errors.push((0, errors_1.formatError)(error));
|
|
2062
2162
|
}
|
|
2063
2163
|
}
|
|
2064
2164
|
}
|
|
@@ -2070,7 +2170,7 @@ datasources:
|
|
|
2070
2170
|
successCount++;
|
|
2071
2171
|
}
|
|
2072
2172
|
catch (error) {
|
|
2073
|
-
errors.push(
|
|
2173
|
+
errors.push((0, errors_1.formatError)(error));
|
|
2074
2174
|
}
|
|
2075
2175
|
}
|
|
2076
2176
|
else {
|
|
@@ -2144,7 +2244,7 @@ datasources:
|
|
|
2144
2244
|
}
|
|
2145
2245
|
}
|
|
2146
2246
|
catch (error) {
|
|
2147
|
-
this.
|
|
2247
|
+
this.logPushError(id, error);
|
|
2148
2248
|
}
|
|
2149
2249
|
}
|
|
2150
2250
|
this.writeFileBufferToDisk();
|
|
@@ -2470,13 +2570,13 @@ datasources:
|
|
|
2470
2570
|
if (this._client.getHostsAvailable() === 0) {
|
|
2471
2571
|
this.setConnected(false);
|
|
2472
2572
|
}
|
|
2473
|
-
this.log.error(`getHistory: ${
|
|
2474
|
-
(0, aggregate_1.sendResponse)(this, msg, id, options,
|
|
2573
|
+
this.log.error(`getHistory: ${(0, errors_1.formatError)(error)}`);
|
|
2574
|
+
(0, aggregate_1.sendResponse)(this, msg, id, options, (0, errors_1.formatError)(error), startTime);
|
|
2475
2575
|
}
|
|
2476
2576
|
}, storedCount ? 50 : 0);
|
|
2477
2577
|
}
|
|
2478
2578
|
catch (error) {
|
|
2479
|
-
this.log.info(`Error storing buffered series for ${id} before GetHistory: ${
|
|
2579
|
+
this.log.info(`Error storing buffered series for ${id} before GetHistory: ${(0, errors_1.formatError)(error)}`);
|
|
2480
2580
|
}
|
|
2481
2581
|
}
|
|
2482
2582
|
async getHistoryV2(msg) {
|
|
@@ -2643,9 +2743,9 @@ ${this.config.usetags ? ' |> duplicate(column: "_value", as: "value")' : ' |> pi
|
|
|
2643
2743
|
}
|
|
2644
2744
|
}
|
|
2645
2745
|
catch (error) {
|
|
2646
|
-
if (
|
|
2746
|
+
if ((0, errors_1.formatError)(error).includes('type conflict: bool')) {
|
|
2647
2747
|
if (debugLog) {
|
|
2648
|
-
this.log.debug(`${logId} Bool check error: ${
|
|
2748
|
+
this.log.debug(`${logId} Bool check error: ${(0, errors_1.formatError)(error)}`);
|
|
2649
2749
|
}
|
|
2650
2750
|
supportsAggregates = true;
|
|
2651
2751
|
}
|
|
@@ -2653,7 +2753,7 @@ ${this.config.usetags ? ' |> duplicate(column: "_value", as: "value")' : ' |> pi
|
|
|
2653
2753
|
// real error
|
|
2654
2754
|
this.sendTo(msg.from, msg.command, {
|
|
2655
2755
|
result: [],
|
|
2656
|
-
error:
|
|
2756
|
+
error: (0, errors_1.formatError)(error),
|
|
2657
2757
|
sessionId: options.sessionId,
|
|
2658
2758
|
}, msg.callback);
|
|
2659
2759
|
return;
|
|
@@ -2825,12 +2925,12 @@ ${!this.config.usetags ? '|> pivot(rowKey:["_time"], columnKey: ["_field"], valu
|
|
|
2825
2925
|
if (!this._client?.getHostsAvailable()) {
|
|
2826
2926
|
this.setConnected(false);
|
|
2827
2927
|
}
|
|
2828
|
-
this.log.error(`getHistory: ${
|
|
2928
|
+
this.log.error(`getHistory: ${(0, errors_1.formatError)(error)}`);
|
|
2829
2929
|
}
|
|
2830
2930
|
}, storedCount ? 50 : 0);
|
|
2831
2931
|
}
|
|
2832
2932
|
catch (error) {
|
|
2833
|
-
this.log.info(`Error storing buffered series for ${id} before GetHistory: ${
|
|
2933
|
+
this.log.info(`Error storing buffered series for ${id} before GetHistory: ${(0, errors_1.formatError)(error)}`);
|
|
2834
2934
|
}
|
|
2835
2935
|
}
|
|
2836
2936
|
async query(msg) {
|
|
@@ -2880,10 +2980,10 @@ ${!this.config.usetags ? '|> pivot(rowKey:["_time"], columnKey: ["_field"], valu
|
|
|
2880
2980
|
if (!this._client.getHostsAvailable()) {
|
|
2881
2981
|
this.setConnected(false);
|
|
2882
2982
|
}
|
|
2883
|
-
this.log.error(`query: ${
|
|
2983
|
+
this.log.error(`query: ${(0, errors_1.formatError)(error)}`);
|
|
2884
2984
|
this.sendTo(msg.from, msg.command, {
|
|
2885
2985
|
result: [],
|
|
2886
|
-
error:
|
|
2986
|
+
error: (0, errors_1.formatError)(error),
|
|
2887
2987
|
}, msg.callback);
|
|
2888
2988
|
}
|
|
2889
2989
|
}
|
|
@@ -2908,10 +3008,10 @@ ${!this.config.usetags ? '|> pivot(rowKey:["_time"], columnKey: ["_field"], valu
|
|
|
2908
3008
|
}
|
|
2909
3009
|
}
|
|
2910
3010
|
catch (error) {
|
|
2911
|
-
this.log.warn(`Error in received multiQuery: ${
|
|
3011
|
+
this.log.warn(`Error in received multiQuery: ${(0, errors_1.formatError)(error)}`);
|
|
2912
3012
|
this.sendTo(msg.from, msg.command, {
|
|
2913
3013
|
result: [],
|
|
2914
|
-
error:
|
|
3014
|
+
error: (0, errors_1.formatError)(error),
|
|
2915
3015
|
}, msg.callback);
|
|
2916
3016
|
return;
|
|
2917
3017
|
}
|
|
@@ -2947,10 +3047,10 @@ ${!this.config.usetags ? '|> pivot(rowKey:["_time"], columnKey: ["_field"], valu
|
|
|
2947
3047
|
if (!this._client?.getHostsAvailable()) {
|
|
2948
3048
|
this.setConnected(false);
|
|
2949
3049
|
}
|
|
2950
|
-
this.log.error(`queries: ${
|
|
3050
|
+
this.log.error(`queries: ${(0, errors_1.formatError)(error)}`);
|
|
2951
3051
|
return this.sendTo(msg.from, msg.command, {
|
|
2952
3052
|
result: [],
|
|
2953
|
-
error:
|
|
3053
|
+
error: (0, errors_1.formatError)(error),
|
|
2954
3054
|
}, msg.callback);
|
|
2955
3055
|
}
|
|
2956
3056
|
}
|
|
@@ -3091,8 +3191,8 @@ ${!this.config.usetags ? '|> pivot(rowKey:["_time"], columnKey: ["_field"], valu
|
|
|
3091
3191
|
measurements = await this.readMeasurements();
|
|
3092
3192
|
}
|
|
3093
3193
|
catch (error) {
|
|
3094
|
-
this.log.error(`getDatapoints: ${
|
|
3095
|
-
return this.sendTo(msg.from, msg.command, { error:
|
|
3194
|
+
this.log.error(`getDatapoints: ${(0, errors_1.formatError)(error)}`);
|
|
3195
|
+
return this.sendTo(msg.from, msg.command, { error: (0, errors_1.formatError)(error) }, msg.callback);
|
|
3096
3196
|
}
|
|
3097
3197
|
const result = [];
|
|
3098
3198
|
for (const id of measurements.sort((a, b) => a.localeCompare(b))) {
|
|
@@ -3201,8 +3301,8 @@ ${!this.config.usetags ? '|> pivot(rowKey:["_time"], columnKey: ["_field"], valu
|
|
|
3201
3301
|
if (!this._client?.getHostsAvailable()) {
|
|
3202
3302
|
this.setConnected(false);
|
|
3203
3303
|
}
|
|
3204
|
-
this.log.error(`getRawEntries: ${
|
|
3205
|
-
this.sendTo(msg.from, msg.command, { error:
|
|
3304
|
+
this.log.error(`getRawEntries: ${(0, errors_1.formatError)(error)}`);
|
|
3305
|
+
this.sendTo(msg.from, msg.command, { error: (0, errors_1.formatError)(error) }, msg.callback);
|
|
3206
3306
|
}
|
|
3207
3307
|
}
|
|
3208
3308
|
}
|