PragmaticFlow / NBomber.Sinks.InfluxDB

A NBomber sink that writes statistics to InfluxDB
Apache License 2.0
7 stars 9 forks source link

Exception with InfluxDb v2 #13

Closed MarkusGeigerDev closed 1 year ago

MarkusGeigerDev commented 1 year ago

When trying to write reports data to InfluxDB v2.7.1 the following exception is written to the log:

Reporting sink: NBomber.Sinks.InfluxDB failed to save realtime scenario stats
System.ArgumentException: Expecting a non-empty string for 'bucket' parameter. Please specify the bucket as a method parameter or use default configuration at 'InfluxDBClientOptions.Bucket'.
   at InfluxDB.Client.Core.Arguments.CheckNonEmptyString(String value, String name)
   at InfluxDB.Client.BatchWriteOptions..ctor(String bucket, String org, WritePrecision precision)
   at InfluxDB.Client.WriteApiAsync.WritePointsAsync(List`1 points, String bucket, String org, CancellationToken cancellationToken)
   at NBomber.DomainServices.TestHost.ReportingSinks.saveRealtimeStats@40.MoveNext()

My test setup starts InfluxDb in a docker compose file as follows:

version: '3'
services:
  influxdb:
    image: influxdb:latest
    environment:
      DOCKER_INFLUXDB_INIT_MODE: setup
      DOCKER_INFLUXDB_INIT_USERNAME: superuser
      DOCKER_INFLUXDB_INIT_PASSWORD: Passw0rd!
      DOCKER_INFLUXDB_INIT_ORG: BCI
      DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: N3Z_uUD...[ redacted ]...WFXoe62Q==
      DOCKER_INFLUXDB_INIT_BUCKET: NBomber
    ports:
      - 8086:8086
    volumes:
    - ./influxdb:/var/lib/influxdb2

and my infra-config.json in the NBomber test project looks like this:

{
  "InfluxDBSink": {
    "Url": "http://localhost:8086",
    "Database": "NBomber",
    "Token": "N3Z_uUD...[ redacted ]...WFXoe62Q==",
    "CustomTags": [
      {
        "Key": "environment",
        "Value": "linux"
      }
    ]
  }
}

from looking at the Source code at https://github.com/PragmaticFlow/NBomber.Sinks.InfluxDB/blob/8dd8313a38251576bbd85630d480f747b35734c8/src/NBomber.Sinks.InfluxDB/InfluxDBSink.cs#LL66C1-L68C74 it seems like the Database/bucket name is ignored when a v2 token is set.

Any ideas on how to solve this?

EDIT: I tried both v4.2 and 5.0 beta 2. Both show the same behavior.

AntyaDev commented 1 year ago

Hi @MarkusGeigerDev I never tried to run it for Influx 2.0

Next week we will release NBomber v5 and I think after this I will have time to debug this issue.

If you would like to contribute to NBomber please welcome :)

MarkusGeigerDev commented 1 year ago

Hi @AntyaDev, thanks for you prompt reply :)

From looking at the error message it seems like a small change. I'm afraid I cannot look into this issue next week but the week after that I'll be happy to help!

Thanks! Markus

AntyaDev commented 1 year ago

Sounds good! Take your time :)

MarkusGeigerDev commented 1 year ago

Turns out that the problem was not in your code but rather a documentation issue rooted in my total ignorance on how Influx v2 connection URLs are constructed.

This works (infra-config.json):

{
  "InfluxDBSink": {
    "Url": "http://localhost:8086?org=MyOrg&bucket=MyBucket",
    "Token" : "N3Z_uUD...[ redacted ]...WFXoe62Q=="
  }
}

I found a few issues with the Grafana dashboards if used with newer versions of Grafana, but I will propose my changes regarding that over in the NBomber.Grafana project.