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

line protocol #23

Merged
merged 5 commits into from
Apr 12, 2016
Merged

line protocol #23

merged 5 commits into from
Apr 12, 2016

Conversation

ngong
Copy link
Member

@ngong ngong commented Oct 27, 2015

ping @nzroller

@ngong
Copy link
Member Author

ngong commented Oct 27, 2015

@ngong
Copy link
Member Author

ngong commented Oct 27, 2015

closes #5

@nzroller
Copy link
Contributor

Nice one @ngong! I'll try to take a look at this soon. Maybe we don't need to leave the json protocol around and can just remove it? And in that case we could remove the jackson dependency too.

@ngong ngong force-pushed the line branch 2 times, most recently from ab4f48d to 47a93ce Compare November 10, 2015 14:59
@ngong
Copy link
Member Author

ngong commented Nov 10, 2015

Tested, now it is working.

return sb.toString();
}

public String lineProtocol(InfluxDbPoint point, TimeUnit precision) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also return StringBuilder, alternatively you could add the StringBuilder as a parameter to avoid having to initialize a new one every time. If you want to keep the String return type for the public methods, then you should refactor it, so that the StringBuilder logic is in a private method which is used by getLineProtocolString and the public method just uses toString.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really good point! Thanks

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, there is no need to use StringBuilder at all here

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not? You create a new String locally just to append it to in getLineProtocolString to a StringBuilder, I think it would be better to have the StringBuilder as parameter and also to pass it down to the other private methods, that currently create their own StringBuilder, e.g. concatenatedTags, concatenateFields, formattedTime... like @woidda pointed out

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean to build string in this method. Sure, it is nice to take StringBuilder as parameter

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is not necessary to keep this method public anymore.

@dkerwin
Copy link

dkerwin commented Apr 5, 2016

Great to see progress on this issue 👍 .
Today 0.12.0 was released and JSON endpoint was finally removed (https://github.com/influxdata/influxdb/blob/master/CHANGELOG.md)

@woidda
Copy link

woidda commented Apr 8, 2016

Are there any plans to merge the branch? 0.12.0 is out as @dkerwin mentioned and there seem to be a lot of improvements that would make an upgrade interesting...

@nzroller
Copy link
Contributor

Thanks @dkerwin for pointing that out (it wasn't clear when they would finally remove the JSON endpoint, was hoping for 1.0.0). @woidda we will do some testing soon, so hopefully within the next two weeks?

if (null == time) {
time = System.nanoTime();
}
sb.append(" ").append(TimeUnit.NANOSECONDS.convert(precision.convert(time, TimeUnit.MILLISECONDS), precision));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing that this means we have ms precision where we might want second or minute precision?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code here is, to convert ms (which is what we collected from system) to the precision you specified. And then, we need to convert it back to NANOSECONDS which is required by line protocol on passing time stamp

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the time = System.nanoTime(); is wrong, it should be time = System.currentTimeMillis();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or Instant.now().toEpochMilli() to avoid calling the System object? I don't know if this project supports java8 though.

v0.12.0 of influx has removed the deprecated json protocol, this
replaces that with their line protocol.

References:
 - https://docs.influxdata.com/influxdb/v0.12/write_protocols/line/
 - https://github.com/influxdata/influxdb-java/
@coveralls
Copy link

Coverage Status

Coverage increased (+4.3%) to 72.672% when pulling 0d7ede7 on line into 4e0c577 on master.

- remove string builder from lineProtocol method in InfluxDbWriteObjectSerializer

- fix a little bug in time format

- used pre-compiled Pattern to escape data

- optimized url construction
@coveralls
Copy link

Coverage Status

Coverage increased (+4.1%) to 72.525% when pulling fd50295 on line into 4e0c577 on master.

@ngong
Copy link
Member Author

ngong commented Apr 11, 2016

Currently, timestamps are sent in nano seconds, and precision is resolve in the code. However, according to InfluxDb's page, the best practice should be sending precision data in query string, and truncate the date in line protocol to that precision. I will address this option and try if this is working later.

@ngong
Copy link
Member Author

ngong commented Apr 11, 2016

Updated. Tested working fine. So it could potentially reduce some data size when pushing to InfluxDb server.

@coveralls
Copy link

Coverage Status

Coverage increased (+2.6%) to 70.949% when pulling c57b75f on line into 4e0c577 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+2.6%) to 71.006% when pulling 9359d7e on line into 4e0c577 on master.

@nzroller nzroller changed the title line protocol, not tested line protocol Apr 12, 2016
@coveralls
Copy link

Coverage Status

Coverage increased (+2.6%) to 71.006% when pulling 3e56c0a on line into 4e0c577 on master.

@nzroller nzroller merged commit 81a6d44 into master Apr 12, 2016
@nzroller nzroller deleted the line branch April 12, 2016 11:21
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

Successfully merging this pull request may close these issues.

None yet

7 participants