influxdata / influxdb-client-csharp

InfluxDB 2.x C# Client

Home Page:https://influxdata.github.io/influxdb-client-csharp/api/InfluxDB.Client.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

InfluxOSS writing data to bucket with retention period doesn't write data

aidanmorgan opened this issue · comments

I am attempting to write data to a bucket running in Influx OSS that is running inside docker (Macbook M2 Pro, Docker version: 24.0.5, Influx OSS Image Version: 2.7.1).

The WriteXXXAsyncWithIRestReponse() methods return a result that has the IsSuccessful returning True, but the status code is actually NoContent with no data actually written to the database.

Using a consistent inlux client and api configuration:

                using var influxClient = new InfluxDBClient(
                    new InfluxDBClientOptions(configuration.Url)
                    {
                        Bucket = configuration.Bucket,
                        Org = configuration.Organisation,
                        Token = configuration.Token,
                        PointSettings = { DefaultTags = configuration.DefaultTags},
                    }
                );

                var api = influxClient.GetWriteApiAsync();

The first snippet is using the WritePointsAsyncWithIRestResponse which returns NoContent, but no data is written as below:

                var response = await api.WritePointsAsyncWithIRestResponse(
                    metrics.Select(x => pointDataConverter(x, PointData.Measurement(configuration.MeasurementName)))
                        .ToList(),
                    configuration.Bucket,
                    configuration.Organisation
                );

The second snippet is using the WriteRecordsAsyncWithIRestResponse with also returns NoContent, but no data is written as below:

                var response = await api.WriteRecordsAsyncWithIRestResponse(
                    metrics.Select(x => pointDataConverter(x, PointData.Measurement(configuration.MeasurementName)))
                        .Select(x => x.ToLineProtocol()),
                    WritePrecision.Ms,
                    configuration.Bucket,
                    configuration.Organisation
                );

To try and understand what was going wrong, I thought I would put togther a quick harness that calls the API using HTTP calls directly using Flurl, which returns NoContent but the data is correctly written to the bucket:

                var request = configuration
                    .Url
                    .WithHeader("Authorization", $"Token {configuration.Token}")
                    .WithHeader("Content-Type", "text/plain; charset=utf-8")
                    .WithHeader("Accept", "application/json")
                    .AppendPathSegment("/api/v2/write")
                    .SetQueryParam("org", configuration.Organisation)
                    .SetQueryParam("bucket", configuration.Bucket)
                    .SetQueryParam("precision", "ms");

                using var response = await request.PostStringAsync(
                    string.Join("\n",
                        metrics
                            .Select(x => pointDataConverter(x, PointData.Measurement(configuration.MeasurementName)).ToLineProtocol()))
                );

Through all three different scenarios the data that is been generated is not changing (the same callback is used to convert from my internal data structure to the influx PointData structure), but only the third case actually persists data.

I would have expected that the second and third scenarios would have the same outcome given they are both writing line protocol directly, but this is not the case.

Hi @aidanmorgan,

thanks fro using our client.

The no-content - 204 is success response from InfluxDB server. For more info see https://docs.influxdata.com/influxdb/v2.6/api/#operation/PostWrite

image

Best

Thanks @bednar, as I said in the defect report it returns NoContent but it also doesn't write any data to the database unless I use the HTTP API directly (the third code snippet).

Hi @bednar I was wondering if there was anything else you can suggest on this topic, I'd prefer to use the official library rather than my own HTTP interface.