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

BatchOption doesn't support Precision. Defaults to nanosecond #532

Closed
maazkhan opened this issue Oct 11, 2018 · 8 comments
Closed

BatchOption doesn't support Precision. Defaults to nanosecond #532

maazkhan opened this issue Oct 11, 2018 · 8 comments

Comments

@maazkhan
Copy link

maazkhan commented Oct 11, 2018

Trying to write data to Influx async with batching enabled using this example below

influxDB.enableBatch(BatchOptions.DEFAULTS.actions(2000).flushDuration(100));

Point point1 = Point.measurement("cpu")
                    .time(System.currentTimeMillis() /1000, TimeUnit.SECONDS)
                    .addField("idle", 90L)
                    .addField("user", 9L)
                    .addField("system", 1L)
                    .build();
Point point2 = Point.measurement("disk")
                    .time(System.currentTimeMillis() /1000, TimeUnit.SECONDS)
                    .addField("used", 80L)
                    .addField("free", 1L)
                    .build();

influxDB.write(dbName, rpName, point1);
influxDB.write(dbName, rpName, point2);

There is no way to specify the Precision for the internal BatchPoints. It defaults to nanosecond whereas I am sending data with seconds precision only.

The BatchOption should have a feature to take precision as an input.
Am I missing something?

@maazkhan
Copy link
Author

@majst01 Any updates/comments on this one?

@asashour
Copy link
Contributor

I am afraid I can't reproduce this, with InfluxDB 1.7.3 and influx-java 2.14.

The results are not having any values below seconds:

Or do you mean you don't the trailing 0?

> select * from cpu
name: cpu
time                idle system user
----                ---- ------ ----
1548852474000000000 90   1      9
1548852477000000000 90   1      9
1548852480000000000 90   1      9

@maazkhan
Copy link
Author

@asashour
I am not sure if there is anything that needs to be reproduced here. I am just asking a way where a user can specify the precision when writing via Influx-java client.
If you see the above example that I posted, I don't see any option to pass "precision" parameter when writing via the client.

If you look at the above "point" I am sending time in "Seconds" but when influx-java client write that data to InfluxDB is write with precision=n (nanoseconds)

@asashour
Copy link
Contributor

I see, well I guess this is InfluxDB convention:

The timestamp for your data point in nanosecond-precision Unix time

https://docs.influxdata.com/influxdb/v1.7/write_protocols/line_protocol_tutorial/#timestamp

@maazkhan
Copy link
Author

This is the HTTP doc of Influx https://docs.influxdata.com/influxdb/v1.7/tools/api/#write-http-endpoint
It says that when writing data to influxDB via HTTP you can specify precision=[ns,u,ms,s,m,h]

It also says
** We recommend using the least precise precision possible as this can result in significant improvements in compression.

So coming back to the issue, the influx-java client is writing with a default precision of ns when using enableBatch option. It is missing the feature where user can choose what precision to write with.

@asashour
Copy link
Contributor

I see, the below case shows the that .toString() has the SECOND precision, but .lineProtocol() does not

BatchPoints bp = BatchPoints.database(dbName).point(point1).build();
System.out.println(bp);
System.out.println(bp.lineProtocol());

Which prints

BatchPoints [database=mydb, retentionPolicy=null, consistency=ONE, tags={}, precision=NANOSECONDS, points=[Point [name=cpu, time=1548923577, tags={}, precision=SECONDS, fields={idle=90, system=1, user=9}]]]
cpu idle=90i,system=1i,user=9i 1548923577000000000

@asashour
Copy link
Contributor

Actually, there is PatchPoints.Builder.precision():

BatchPoints bp = BatchPoints.database(dbName).point(point1).precision(TimeUnit.SECONDS).build();
System.out.println(bp);
System.out.println(bp.lineProtocol());

In the line protocol is with SECONDS, and the precision parameter is used from the BatchPoints:

cpu idle=90i,system=1i,user=9i 1548924066

@maazkhan
Copy link
Author

@asashour

I agree BatchPoints have the feature to set the precision but I am not using BatchPoints. I am using
influxDB.enableBatch(BatchOptions.DEFAULTS.actions(2000).flushDuration(100));
and then writing the data using influxDB.write(dbName, rpName, point1);

When using influxDB.enableBatch I can specify certain properties using BatchOption but it is missing precision properties and ultimately everything that is written via InfluxDB.enableBatch is written as nanosecond precision.

The bottom line is there is currently no way to set precision in this influxDB.enableBatch(BatchOptions.DEFAULTS.actions(2000).flushDuration(100));

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

2 participants