mblackstock / node-red-contrib-influxdb

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

Writes to output node timing out #114

Closed tcurdt closed 2 years ago

tcurdt commented 2 years ago

I am trying to write into influxdb:2.1.1-alpine but getting a timeout and cannot figure out the reason why.

From the nodered/node-red:2.2.1-16 container curl http://influxdb:8086 works just fine. This suggests network connectivity is OK.

This is how I started the influxdb container:

  influxdb:
    container_name: influxdb
    image: influxdb:2.1.1-alpine
    restart: unless-stopped
    volumes:
      - influxdb_data:/var/lib/influxdb2
    environment:
      - DOCKER_INFLUXDB_INIT_USERNAME=my-user
      - DOCKER_INFLUXDB_INIT_PASSWORD=my-password
      - DOCKER_INFLUXDB_INIT_ORG=my-org
      - DOCKER_INFLUXDB_INIT_BUCKET=my-bucket
      - DOCKER_INFLUXDB_INIT_RETENTION=14d
      - INFLUXD_STORAGE_WAL_FSYNC_DELAY=15m
    ports:
      - 127.0.0.1:8086:8086
    networks:
      - compose

I am using the token from influx auth list - which is also provided in the example available through the UI.

const {InfluxDB} = require('@influxdata/influxdb-client')
const token = 'vWpmm3Ru38H9Jp2AzSB4v5qVMNMC4_vI_3aLwvH6QtBgakl_80oTxDcTUmytKhFRdWZcjocQ5ixvG9RIgz1eqg=='
const org = 'my-org'
const bucket = 'my-bucket'
const client = new InfluxDB({url: 'http://127.0.0.1:8086', token: token})
Screenshot 2022-02-23 at 01 03 29

The node is configured as such:

Screenshot 2022-02-23 at 01 03 22

I don't see a problem - yet the write fails:

nodered      | WARN: Write to InfluxDB failed (attempt: 1). y [RequestTimedOutError]: Request timed out
nodered      |     at ClientRequest.<anonymous> (/usr/src/node-red/node_modules/@influxdata/influxdb-client/dist/index.js:16:4115)
nodered      |     at ClientRequest.emit (node:events:390:28)
nodered      |     at Socket.emitRequestTimeout (node:_http_client:763:9)
nodered      |     at Object.onceWrapper (node:events:509:28)
nodered      |     at Socket.emit (node:events:402:35)
nodered      |     at Socket._onTimeout (node:net:501:8)
nodered      |     at listOnTimeout (node:internal/timers:557:17)
nodered      |     at processTimers (node:internal/timers:500:7)
nodered      | 23 Feb 01:02:49 - [error] [influxdb out:influxdb out] RequestTimedOutError: Request timed out

Any idea what could be the problem? I didn't find anything related in the open issues.

tcurdt commented 2 years ago

Using the wrong token gives a 401. So it seems to be connecting. Could it be there is a compatibility problem with version 2.1?

mblackstock commented 2 years ago

I'm not sure what the issue is with your setup, but here's a simple docker-compose.yml file that worked for me. Hopefully this helps.

version: '3.7'
services:
  node-red:
    image: nodered/node-red:latest
    ports:
      - "1880:1880"
    volumes:
      - node-red-data:/data

  # Define an InfluxDB v2 service
  influxdb:
    container_name: influxdb
    ports:
      - '8086:8086'
    image: 'influxdb:2.1.1'
    restart: unless-stopped
    environment:
      - DOCKER_INFLUXDB_INIT_MODE=setup
      - DOCKER_INFLUXDB_INIT_USERNAME=root
      - DOCKER_INFLUXDB_INIT_PASSWORD=password
      - DOCKER_INFLUXDB_INIT_ORG=my-org
      - DOCKER_INFLUXDB_INIT_BUCKET=my-bucket
    volumes:
      - influxdb2-data:/var/lib/influxdb2

volumes:
  node-red-data:
  influxdb2-data:

Here's a very simple flow to test output and queries. You'll have to add the token.

[
    {
        "id": "95ef4b8453127c9f",
        "type": "inject",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 160,
        "y": 220,
        "wires": [
            [
                "e04a8bd6f6f09e02"
            ]
        ]
    },
    {
        "id": "e04a8bd6f6f09e02",
        "type": "influxdb out",
        "z": "f6f2187d.f17ca8",
        "influxdb": "db3bc7301913731b",
        "name": "",
        "measurement": "test",
        "precision": "",
        "retentionPolicy": "",
        "database": "database",
        "precisionV18FluxV20": "ms",
        "retentionPolicyV18Flux": "",
        "org": "my-org",
        "bucket": "my-bucket",
        "x": 470,
        "y": 220,
        "wires": []
    },
    {
        "id": "1a9025ca08718481",
        "type": "influxdb in",
        "z": "f6f2187d.f17ca8",
        "influxdb": "db3bc7301913731b",
        "name": "test",
        "query": "from(bucket: \"my-bucket\")\n          |> range(start: -1m, stop: 1h)\n          |> filter(fn: (r) => r._measurement == \"test\")",
        "rawOutput": false,
        "precision": "",
        "retentionPolicy": "",
        "org": "my-org",
        "x": 270,
        "y": 300,
        "wires": [
            [
                "15a5e1039ebf4a6f"
            ]
        ]
    },
    {
        "id": "15a5e1039ebf4a6f",
        "type": "debug",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 430,
        "y": 300,
        "wires": []
    },
    {
        "id": "957026f36bdad067",
        "type": "inject",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 120,
        "y": 300,
        "wires": [
            [
                "1a9025ca08718481"
            ]
        ]
    },
    {
        "id": "db3bc7301913731b",
        "type": "influxdb",
        "hostname": "127.0.0.1",
        "port": "8086",
        "protocol": "http",
        "database": "database",
        "name": "",
        "usetls": false,
        "tls": "",
        "influxdbVersion": "2.0",
        "url": "http://influxdb:8086",
        "rejectUnauthorized": true
    }
]
tcurdt commented 2 years ago

Odd. That very samedocker-compose keeps restarting my influxdb.

Error: config name "default" already exists

tcurdt commented 2 years ago

Here is my full docker-compose

version: '3.7'

volumes:
  influxdb_data:
  nodered_data:

networks:
  compose:
    name: compose

services:

  influxdb:
    container_name: influxdb
    image: influxdb:2.1.1-alpine
    restart: unless-stopped
    volumes:
      - influxdb_data:/var/lib/influxdb2
    environment:
      - DOCKER_INFLUXDB_INIT_USERNAME=my-user
      - DOCKER_INFLUXDB_INIT_PASSWORD=my-password
      - DOCKER_INFLUXDB_INIT_ORG=my-org
      - DOCKER_INFLUXDB_INIT_BUCKET=my-bucket
      - DOCKER_INFLUXDB_INIT_RETENTION=14d
      - INFLUXD_STORAGE_WAL_FSYNC_DELAY=15m
    ports:
      - 127.0.0.1:8086:8086
    networks:
      - compose

  nodered:
    container_name: nodered
    image: nodered/node-red:2.2.1-16
    restart: unless-stopped
    environment:
      - TZ=Europe/Berlin
    volumes:
      - nodered_data:/data
    ports:
      - 127.0.0.1:1880:1880
    networks:
      - compose

This time I used the root token from the UI. Same timeout. I am a bit flabbergasted.

I guess with it working for you it's at least not an incompatibility with 2.1.

mblackstock commented 2 years ago

I tried your setup and get the same errors now. The only significant difference is the environment variable INFLUXD_STORAGE_WAL_FSYNC_DELAY. I am not sure what this does or why you need it. I commented it out and it seems to solve the problem. Give that a try.

Yes, I've tested it with Influxdb 2.1 and its not a compatibility issue. I don't think this is a bug in the node. I'll close this for now, but if you become convinced it's a bug, feel free to reopen it.

tcurdt commented 2 years ago

This should cause the underlying the storage layer to fsync less. The idea was to go easier on the SD card.

Now - that's just crazy! Thanks for helping in debugging this. It didn't even cross my mind this could be related.

🙏