MikaelGRA / InfluxDB.Client

InfluxDB Client for .NET
MIT License
102 stars 22 forks source link

Adding TimeStamp removes Field.Value. #79

Open DezzardHD opened 3 years ago

DezzardHD commented 3 years ago

Hey, I've found that assigning DateTime.Now to info.Timestamp the field.Value is not getting written to InfluxDB2.0 using the v1 compatibility API. (Only tagKeyValue-Pairs and fieldKey appears in InfluxDB) When I do not assign the TimeStamp, then the value of the field is beeing written.

Debug log of InfluxDB2.0 for writing: 2021-09-22T20:30:45.520092Z debug Request {"log_id": "0Wko35_G000", "service": "http", "method": "POST", "host": "localhost:8086", "path": "/write", "query": "consistency=all&db=myDatabaseName&precision=ns", "proto": "HTTP/1.1", "status_code": 204, "response_size": 0, "content_length": 38, "referrer": "", "remote": "[::1]:61889", "user_agent": "unknown", "took": "50.035ms"}

My problematic #code:

    public async Task writeDynamicRowsToDataBase(string measurementTableName, string[] fieldKeys, string[,] tagKeyValuePair, double value)
    {
        var client = new InfluxClient(new Uri("http://" + this.IP.Value + ":" + this.Port.Value), this.username.Value, this.password.Value);
        var infos = CreateDynamicRowsStartingAt(this.schedulerService.Now, 1, fieldKeys, tagKeyValuePair, value);
        await client.WriteAsync(this.database.Value, measurementTableName, infos);
    }
    private DynamicInfluxRow[] CreateDynamicRowsStartingAt(DateTime timestamp, int rows, string[] fieldKeys,string[,] tagKeyValuePair, double value)
    {
        var infos = new DynamicInfluxRow[rows];
        var info = new DynamicInfluxRow();
        for (int cntFields = 0; cntFields < fieldKeys.GetLength(0); cntFields++)
        {
            info.Fields.Add(fieldKeys[cntFields], value);
        }
        for (int cntTags = 0; cntTags < tagKeyValuePair.GetLength(0); cntTags++)
        {
            info.Tags.Add(tagKeyValuePair[cntTags, 0], tagKeyValuePair[cntTags, 1]);
        }
        info.Timestamp = timestamp;
        infos[0] = info;
        return infos;
    }