influxdb-matlab icon indicating copy to clipboard operation
influxdb-matlab copied to clipboard

Incompatible with API v2

Open jankap opened this issue 3 years ago • 8 comments

Thank you very much for this great tool! However, I upgraded my docker container to v2 and it seems that the API is incompatible. Are there any plans to migrate to API v2 or do you know if the old one is fully functional still? https://docs.influxdata.com/influxdb/v2.0/api/

Thanks!

jankap avatar Apr 12 '21 17:04 jankap

Hi @jankap,

Could you provide more details about the incompatibilities that you are facing?

According to the docs, both /query and /write endpoints should be compatible with v1: https://docs.influxdata.com/influxdb/v2.0/reference/api/influxdb-1x/

However, I am hitting HTTP 401 Unauthorized errors when running the tests with v2:

Error occurred in InfluxDbTest/basic_write_and_read and it did not run to completion.
    ---------
    Error ID:
    ---------
    'MATLAB:webservices:HTTP401StatusCodeError'
    --------------
    Error Details:
    --------------
    Error using matlab.internal.webservices.HTTPConnector/copyContentToByteArray
    (line 373)
    The server returned the status 401 with message "" in response to the
    request to URL http://localhost:8086/query.
    
    Error in readContentFromWebService (line 46)
            byteArray = copyContentToByteArray(connection);
    
    Error in webwrite (line 139)
        [varargout{1:nargout}] = readContentFromWebService(connection, options);
    
    Error in InfluxDB/runCommand (line 133)
                    response = webwrite(url, params{:}, opts);

    Error in InfluxDbTest/beforeEach (line 16)
                test.Client.runCommand(['CREATE DATABASE "', test.Database,
                '"'], true);

Is this similar to the problem that you are having?

EnricSala avatar Apr 12 '21 19:04 EnricSala

Hi @EnricSala,

I am also trying to access V2 of the API from matlab right now.

I have the same problem regarding the access.

Error using matlab.internal.webservices.HTTPConnector/copyContentToByteArray (line 373)
The server returned the status 401 with message "" in response to the request to URL
http://myip:myport/query?q=SHOW+DATABASES.

Error in readContentFromWebService (line 46)
        byteArray = copyContentToByteArray(connection);

Error in webread (line 125)
[varargout{1:nargout}] = readContentFromWebService(connection, options);

Error in InfluxDB/runCommand (line 136)
                response = webread(url, params{:}, opts);

Error in InfluxDB/databases (line 46)
            result = obj.runCommand('SHOW DATABASES');

Error in TEST (line 15)
dbs = influxdb.databases()

I think the problem is because the API V2 uses tokens for authentication.

Sp0b1e avatar Apr 15 '21 08:04 Sp0b1e

The token issue can be solved approx. like this:


            opts = weboptions();
            opts.HeaderFields = ["Authorization","Token <myTokenFromWebinterface>"];
           
            % api v2
            url = obj.Url + "api/v2/";

            % api v1, influxDb version >= 2
            url = [obj.Url '/query'];    
           

            if requiresPost
                opts.Timeout = obj.WriteTimeout;
                response = webwrite(url, params{:}, opts);
            else
                opts.Timeout = obj.ReadTimeout;
                response = webread(url, params{:}, opts);
            end

This is part of InfluxDB.m.

However, even with api v1 endpoint CREATE DATABASE does not work (first test in run_tests.m fails).

jankap avatar Apr 15 '21 08:04 jankap

Thanks, @jankap.

Can you tell me where in the Influxdb.m i have to put this?

@EnricSala can you maybe update the Influxdb.m to accept the token directly in the constructor?

According to the docs, both /query and /write endpoints should be compatible with v1: https://docs.influxdata.com/influxdb/v2.0/reference/api/influxdb-1x/

Have you already tried this? At the moment reading from and writing in a existing Database would be fine for me.

Sp0b1e avatar Apr 15 '21 13:04 Sp0b1e

The compatibility API supports InfluxQL, with the following caveats, InfluxQL database management commands are not supported.

@jankap ah it seems I had missed this ^ from the docs. That's unfortunate becase it will require changes to use the new APIs from v2.

@EnricSala can you maybe update the Influxdb.m to accept the token directly in the constructor?

@Sp0b1e That's tricky because the library should continue to support v1 users, which at this time is still probably most of them. Will see if I can find some time in the coming week to take a look at this :)

EnricSala avatar Apr 15 '21 16:04 EnricSala

The compatibility API supports InfluxQL, with the following caveats, InfluxQL database management commands are not supported.

@jankap ah it seems I had missed this ^ from the docs. That's unfortunate becase it will require changes to use the new APIs from v2.

@EnricSala can you maybe update the Influxdb.m to accept the token directly in the constructor?

@Sp0b1e That's tricky because the library should continue to support v1 users, which at this time is still probably most of them. Will see if I can find some time in the coming week to take a look at this :)

@EnricSala I just started using Influxdb V2 and was having the same 401 error as the others have explained above. Just was wanted to check if you've come up with a fix for it yet?

SaadArshad222 avatar Sep 03 '21 16:09 SaadArshad222

Hi @SaadArshad222, unfortunately I haven't been able to make much progress on this topic as I am quite busy at the moment. Will post a status update when there are new :)

EnricSala avatar Sep 07 '21 20:09 EnricSala