mblackstock / node-red-contrib-influxdb

Node-RED nodes to save and query data from an influxdb time series database
Other
64 stars 46 forks source link

How to set (increase) query timeout? #134

Closed mt-mrx closed 9 months ago

mt-mrx commented 1 year ago

I have a flux (read) query which needs on my influxdb 2.4 instance ~13 seconds to return the data. At least that's the time the query takes when running it via the influxdb 2.4 data explorer web GUI.

When running the query via the "influxdb in" node I get a timeout.

RequestTimedOutError: Request timed out
    at ClientRequest.<anonymous> (/opt/iobroker/iobroker-data/node-red/node_modules/@influxdata/influxdb-client/src/impl/node/NodeHttpTransport.ts:346:23)
    at ClientRequest.emit (node:events:513:28)
    at Socket.emitRequestTimeout (node:_http_client:814:9)
    at Object.onceWrapper (node:events:627:28)
    at Socket.emit (node:events:525:35)
    at Socket._onTimeout (node:net:526:8)
    at listOnTimeout (node:internal/timers:559:17)
    at processTimers (node:internal/timers:502:7)

I believe there is currently no way to increase the connection/query timeout when using the "influxdb in" node. Is there any other way to increase the (I believe) default 10 seconds timeout?

It would be nice to be able to specify the timeout parameter like the "precision" via a message property and/or "influxdb in" node configuration field.

According to this https://influxdata.github.io/influxdb-client-js/influxdb-client.connectionoptions.html I believe there is a "timeout" parameter when creating the client connection.

thx

Matthias

mt-mrx commented 1 year ago

An ugly workaround, but which fixes my issue at least, is the following code change in the directory /opt/iobroker/iobroker-data/node-red/node_modules of my iobroker installation. However I think it needs to be reapplied every time iobroker/node-red is updated and the module is reinstalled

--- node-red-contrib-influxdb/influxdb.js.orig  2023-05-07 21:49:45.571852400 +0200
+++ node-red-contrib-influxdb/influxdb.js       2023-05-07 22:03:18.672948454 +0200
@@ -58,9 +58,11 @@ module.exports = function (RED) {
                 `${this.credentials.username}:${this.credentials.password}` :
                 this.credentials.token;

+            //2023-05-07: mt-mrx: Increase default query timeout from 10s to 60s
             clientOptions = {
                 url: n.url,
                 rejectUnauthorized: n.rejectUnauthorized,
+                timeout: 60000,
                 token
             }
             this.client = new InfluxDB(clientOptions);
mblackstock commented 9 months ago

added a configuration property for 1.8 and 2.x versions in version 0.7.0

mt-mrx commented 9 months ago

Thanks, just tested it, works fine!