influxdata / influxdb-client-js

InfluxDB 2.0 JavaScript client
https://influxdata.github.io/influxdb-client-js/
MIT License
327 stars 70 forks source link

InfluxQL with Influx 1.8 #195

Closed Infern1 closed 4 years ago

Infern1 commented 4 years ago

Expected Behavior

If I define type influxql I should be able to do a simple query

Current Behavior

Response with a bad request

const queryApi = this.influxClient.getQueryApi('').with({ type: 'influxql' });

Error log:

Error: 400 Bad Request : {"error":"unknown query type: influxql"}
WEB_TreCycWriter.ts:461
_retryAfter:0
body:"{"error":"unknown query type: influxql"}
"
message:"400 Bad Request : {"error":"unknown query type: influxql"}
"
stack:"Error: 400 Bad Request : {"error":"unknown query type: influxql"}

    at IncomingMessage.<anonymous> (D:\Public\WEB_InfluxDB\node_modules\@influxdata\influxdb-client\src\impl\node\NodeHttpTransport.ts:219:13)
    at IncomingMessage.emit (events.js:327:22)
    at endReadableNT (_stream_readable.js:1201:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)"
statusCode:400
statusMessage:"Bad Request"

Possible Solution

Accept influxql since I want to do an easy query: SHOW DATABASES since with 1.8 the buckets() doesn't work.

I can get a proper response by:

    const queryApi = this.influxClient.getQueryApi('');

    //const query = `SHOW DATBASES`;
    const query = `
                import "influxdata/influxdb/v1"
                v1.databases()
                `;
    const databases = [];
    queryApi.queryRows(query, {
      next(row: string[]) {
        //const o = tableMeta.toObject(row);
        //console.log(`${o._time} ${o._measurement} : ${o._field}=${o._value}`);
        //databases = row.
        console.log(row);
      },
      error(error) {
        console.error(error);
      },
      complete() {
        console.log('\nFinished');
      },

Steps/Code to Reproduce the Problem

  1. Run Influx 1.8.0 and try to do InfluxQL query

Specifications

sranka commented 4 years ago

Thank you for reporting this issue and describing your workaround.

InfluxDB1.8 server now does not support influxql queries in 2.0 compatibility endpoints that are used by this client, the code accepts only flux queries.

The 2.0 documentation mentions only flux queries, even though the 2.0 API offers the influxql query option, the support of influxql in 2.0 is not documented, therefore it is not something to rely upon. Your query would fail also in 2.0:

$ curl -X POST -H "Authorization: Token ${INFLUX_TOKEN}" "${INFLUX_HOST}/api/v2/query?org=${INFLUX_ORG}" -d '{"type": "influxql", "query": "SHOW DATABASES", "bucket": "my-bucket"}'
// returns {"error":"interface conversion: interface {} is nil, not v1.DatabasesDependencies"}

This client shall be used to post flux queries. Influxql queries returns json data that are neither recognized by this client nor documented in 2.0 API. The state of influxql support in 2.0 is unknown at the moment, it returns JSON data are not supported by this client anyway.

I would better remove the influxql option from this client, so that we will not confuse users that influxql is the way that could be used to query the DB through this client.

Infern1 commented 4 years ago

Thanks for the clarification

I would better remove the influxql option from this client, so that we will not confuse users that influxql is the way that could be used to query the DB through this client.

Yes I agree

The reason for trying this client is the statement:

If you are just getting started with InfluxDB 1.x today, we recommend adopting the latest client libraries. They allow you to easily move from InfluxDB 1.x to InfluxDB 2.0 Cloud or open source, (when you are ready).

Since we already have an existing nodejs application using the current node-influx client I was thinking it would be nice to prepare our self for the new 2.0 series. Using the compatibility mode by using influxql this would mean we don't have to rewrite all queries at once and can do it step by step and compare the results easily.

I will put our migration on hold for now, since we are running Influx on Windows environment and at the moment there are no binaries for 2.0. So no (easy) adoption for the 2.0 with Influx.

Issue can be closed from my point of view.