Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot invoke InfluxCloud 2.0 compatibility /query endpoint #536

Open
dgg opened this issue Nov 11, 2020 · 6 comments
Open

Cannot invoke InfluxCloud 2.0 compatibility /query endpoint #536

dgg opened this issue Nov 11, 2020 · 6 comments

Comments

@dgg
Copy link

dgg commented Nov 11, 2020

Expected Behavior

To be able to call the compatibility /query endpoint to get results from InfluxCloud 2.0 using 1.x javascript client and InfluxQL while we migrate our code to 2.x javascript client and Flux.

Actual Behavior

And error when performing the query:

ERROR querying Error: write EPROTO 4564213184:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332:

    at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:94:16) {
  errno: -100,
  code: 'EPROTO',
  syscall: 'write'
}

Steps/Code to Reproduce the Problem

  1. There is a bucket named "eitc" with id 99c9c933516b82de that contains the data.
GET /api/v2/buckets

{
  "links": {
    "self": "/api/v2/buckets?descending=false&limit=20&offset=0&orgID=6b5124ee414936d1"
  },
  "buckets": [
    ...,
    {
      "id": "99c9c933516b82de",
      "orgID": "6b5124ee414936d1",
      "type": "user",
      "name": "eitc",
      "retentionRules": [
        {
          "type": "expire",
          "everySeconds": 2592000
        }
      ],
      "createdAt": "2020-11-11T07:39:31.808241248Z",
      "updatedAt": "2020-11-11T07:39:31.808241348Z",
      "links": {
        ...
      },
      "labels": []
    }
  ]
}
  1. In the UI, executing the equivalent query in flux, data is returned
from(bucket: "eitc")
  |> range(start: -10d, stop: -2d)
  |> filter(fn: (r) => r._measurement == "22222222222222222222222222222222")
  |> filter(fn: (r) => r._field == "Outdoor_Temperature" or r._field == "HC1_ReturnTemperature_Ref")
  |> filter(fn: (r) => r.deviceId == "230601")
  |> aggregateWindow(every: 12h, fn: mean, createEmpty: false)
[
  {
    result: '_result',
    table: 0,
    _start: '2020-11-01T07:41:42.313011535Z',
    _stop: '2020-11-09T07:41:42.313011535Z',
    _time: '2020-11-04T00:00:00Z',
    _value: 45.47294642857121,
    _field: 'HC1_ReturnTemperature_Ref',
    _measurement: '22222222222222222222222222222222',
    deviceId: '230601',
    site: 'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB'
  },
  {
    result: '_result',
    table: 0,
    _start: '2020-11-01T07:41:42.313011535Z',
    _stop: '2020-11-09T07:41:42.313011535Z',
    _time: '2020-11-04T12:00:00Z',
    _value: 45.479958333333066,
    _field: 'HC1_ReturnTemperature_Ref',
    _measurement: '22222222222222222222222222222222',
    deviceId: '230601',
    site: 'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB'
  },
...
]
  1. There is already a dbrps mapping in the cloud:
GET /api/v2/dbrps

{
  "content": [
    {
      "id": "069990188f3eb000",
      "database": "eitc",
      "retention_policy": "autogen",
      "default": true,
      "organization_id": "6b5124ee414936d1",
      "bucket_id": "99c9c933516b82de"
    }
  ]
}
  1. Execute this sample javascript
const { InfluxDB: InfluxV1 } = require("influx")
const v1Client = new InfluxV1({
	host: "westeurope-1.azure.cloud2.influxdata.com",
	port: 80,
	protocol: "https",
	options: { auth: `Token ${token}` },
	database: "eitc"
})
const q = "select mean("Outdoor_Temperature") as "Outdoor_Temperature",mean("HC1_FlowTemperature_Ref") as "HC1_FlowTemperature_Ref" from "eitc"."autogen"."22222222222222222222222222222222" where "deviceId" = '230601' and time >= now() - 10d and time <= now() - 2d group by time(12h) fill(none)"
v1Client
	.query(q, { precision: "ms", database: "eitc", retentionPolicy: "autogen" })
	.then((results) => console.log(results))
	.catch((err) => console.error("ERROR querying", err))
// ...

Specifications

  • Version: Influx Cloud. Package version 5.6.3
  • Platform: Mac
  • Subsystem:

Extra information

I am able to perform the query using HTTP, both in a REST client and using axios, but not using the influx client:

> GET /query?db=eitc&rp=autogen&epoch=ms&q=select%20mean(%22Outdoor_Temperature%22)%20as%20%22Outdoor_Temperature%22,mean(%22HC1_FlowTemperature_Ref%22)%20as%20%22HC1_FlowTemperature_Ref%22%20from%20%22eitc%2Fautogen%22.%22autogen%22.%2222222222222222222222222222222222%22%20where%20%22deviceId%22%20%3D%20'230601'%20and%20time%20%3E%3D%20now()%20-%2010d%20and%20time%20%3C%3D%20now()%20-%202d%20group%20by%20time(12h)%20fill(none) HTTP/2
> Host: westeurope-1.azure.cloud2.influxdata.com
> user-agent: insomnia/2020.4.2
> authorization: Token ***REDACTED***
> content-type: application/json
> accept: */*

< HTTP/2 200 
< date: Wed, 11 Nov 2020 07:57:35 GMT
< content-type: text/plain; charset=utf-8
< content-length: 76
< request-id: 604b296bc6b2169d58cf1e751d0020be
< trace-id: 53905440c02a9bab
< x-request-id: 604b296bc6b2169d58cf1e751d0020be
< strict-transport-security: max-age=15724800; includeSubDomains
@MrWook
Copy link

MrWook commented Dec 4, 2020

Hey, i just stared with influxDB and found this issue. It looks like node-influx is not compatible with influxdb 2.x.x
You need to use the new package @influxdata/influxdb-client

@dgg
Copy link
Author

dgg commented Dec 4, 2020

Influx 2.x offers a v1 compatibility endpoint for /query that I can consume using any http library, except, ironically this influx library. It would very much ease our migration to 2.x if we could maintain our current way of querying: using the same library and our InfluxQL queries, until we are able to move to the supported 2.x library (which is not able -to my knowledge- to use this compatibility endpoint with InfluxQL) with Flux queries

@ivankudibal
Copy link

This usually means that client that has connected is attempting to talk some protocol other than SSL/TLS - or sometimes that the data has been corrupted somehow (usually due to an application bug). Is it ok to use the port 80 and https at the same time?

@ivankudibal
Copy link

ivankudibal commented Dec 16, 2020

I modified a bit.. the auth option did not send correct Authorization token based header. Without username and empty password, the client used the default "root" and "root" credentials.

const { InfluxDB: InfluxV1 } = require("influx")
const token = "influxdbv2token"
const v1Client = new InfluxV1({
//	host: "westeurope-1.azure.cloud2.influxdata.com",
	host: "us-central1-1.gcp.cloud2.influxdata.com",
	username: "yourorganization",
// leave password empty
	password: "",
	port: 443,
	protocol: "https",
	options: { 
		headers: {
		'Authorization' : `Token ${token}`
	        }
	}
});

const rp = "demorp";
const db = "demo";
const q = `SELECT mean("capacity_pods") AS "mean_capacity_pods" FROM "${db}"."${rp}"."kubernetes_node" WHERE time > now() - 1d GROUP BY time(1h), "host" FILL(null)`
v1Client
	.query(q, { precision: "ms", database: `${db}`, retentionPolicy: `${rp}` })
	.then((results) => console.log(results))
	.catch((err) => console.error("ERROR querying", err))

To create dbrp mapping: use the influx v1 dbrp command... eg

$ influx v1 dbrp list ....
ID			Database	Bucket ID		Retention Policy	Default	Organization ID
06b7a28fff5dc000	demo		1d165103b59eb20e	demorp			true	e81576123825396

To model InfluxQL use Chronograf v1 (1.8.9.1 has ootb support for connecting to Cloud2). This worked for me.. I hope this helps.

For 2.0 servers consider using https://github.com/influxdata/influxdb-client-js

@dgg
Copy link
Author

dgg commented Jan 4, 2021

I will try that later in the day and report what the results will be.

@dgg
Copy link
Author

dgg commented Jan 5, 2021

That totally worked!

Thanks for that, it is not very not intuitive:

  • using auth inside options
  • use the raw Authorization header
  • setting password to something that can be serialized in the querystring

BTW, I found out that only password needs to be set (for instance, to null -not undefined-) and user can be committed (the default "root" value works just fine) as is not verified.
No need to pass the organization anywhere, only the token in the header.

The port has to be indeed 443, not 80 as I was passing.

This v1 client works just fine:

const v1Client = new InfluxV1({
	host: "westeurope-1.azure.cloud2.influxdata.com",
	port: 443,
	protocol: "https",
	password: null,
	options: { headers: { Authorization: `Token ${token}` } },
	database
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants