GreptimeTeam / greptimedb

An open-source, cloud-native, unified time series database for metrics, logs and events with SQL/PromQL supported. Available on GreptimeCloud.
https://greptime.com/
Apache License 2.0
4.31k stars 312 forks source link

Influx write endpoint ignores `precision` parameter #4695

Closed akhilman closed 1 month ago

akhilman commented 1 month ago

What type of bug is this?

Unexpected error

What subsystems are affected?

Standalone mode

Minimal reproduce step

I'm trying to run the following example from https://docs.greptime.com/user-guide/ingest-data/for-iot/influxdb-line-protocol :

echo \
'create table if not exists monitor (
 host String,
 cpu Float32,
 memory Float32,
 ts TimestampMillisecond,
 primary key (host),
 time index(ts)
 );' | mariadb -h localhost -P 4002 public
curl -i -XPOST "http://localhost:4000/v1/influxdb/api/v2/write?db=public&precision=ms" \
    --data-binary \
'monitor,host=127.0.0.1 cpu=0.1,memory=0.4 1667446797450
 monitor,host=127.0.0.2 cpu=0.2,memory=0.3 1667446798450
 monitor,host=127.0.0.1 cpu=0.5,memory=0.2 1667446798450'

What did you expect to see?

Three data points should be added to table.

What did you see instead?

I have an error:

HTTP/1.1 400 Bad Request
content-type: application/json
content-length: 173
date: Sun, 08 Sep 2024 00:57:48 GMT

{"error":"Invalid request to region 4814658338816(1121, 0), reason: column ts expect type Timestamp(Millisecond(TimestampMillisecondType)), given: TIMESTAMP_NANOSECOND(18)"}⏎

What operating system did you use?

ArchLinux x64

What version of GreptimeDB did you use?

0.9.3 from docker.io

Relevant log output and stack trace

2024-09-08T00:57:48.513162Z  WARN servers::error: Failed to handle HTTP request  err=0: Execute gRPC query error, at src/frontend/src/instance/influxdb.rs:52:14
1: Table operation error, at src/frontend/src/instance/grpc.rs:264:14
2: Failed to insert data, at /greptimedb/src/operator/src/insert.rs:334:26
3: External error, at src/frontend/src/instance/standalone.rs:87:14
4: Operation to region server failed, at src/frontend/src/instance/standalone.rs:69:14
5: Execute gRPC request error, at src/datanode/src/region_server.rs:346:18
6: Failed to handle request for region 4814658338816(1121, 0), at src/datanode/src/region_server.rs:703:14
7: Invalid request to region 4814658338816(1121, 0), reason: column ts expect type Timestamp(Millisecond(TimestampMillisecondType)), given: TIMESTAMP_NANOSECOND(18), at src/mito2/src/request.rs:155:17
killme2008 commented 1 month ago

It's expected.

The precison only controls how to parse the timestamp values in protocol payloads, it doesn't determine the schema of the measurement tables.

GreptimeDB always uses TimestampNanosecond as the data type for timestamp data from the InfluxDB line protocol API and it will create the table automatically, so you don't need to create the table at first. In fact, all the ingestion protocols except SQL INSERT will create tables or add columns automatically for users.

Please read the data model https://docs.greptime.com/nightly/user-guide/ingest-data/for-iot/influxdb-line-protocol#data-model

akhilman commented 1 month ago

Got it.