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

Allow write precision of TimeUnit other than Nanoseconds #182

Open
tony-aq opened this issue Jun 23, 2016 · 14 comments
Open

Allow write precision of TimeUnit other than Nanoseconds #182

tony-aq opened this issue Jun 23, 2016 · 14 comments

Comments

@tony-aq
Copy link

tony-aq commented Jun 23, 2016

Would like to make use of the compression gains based on using an appropriate time precision.

@viragkothari
Copy link

+1

1 similar comment
@har-ki
Copy link

har-ki commented Sep 23, 2016

+1

@andyfeller
Copy link

andyfeller commented Oct 18, 2016

+1

One of InfluxDB best practices is to lower point precision to improve service performance and disk usage. This is much more serious of a bug than a suggestion / feature request.

@andyfeller
Copy link

It seems there are 2 places where this issue take place:

  1. org.influxdb.dto.Point.formattedTime() automatically converts timestamps to nanoseconds; should take precision as parameter passed in whenever point is being converted and written.
    private StringBuilder formatedTime() {
        final StringBuilder sb = new StringBuilder();
        if (null == this.time) {
            this.time = this.precision.convert(System.currentTimeMillis(),TimeUnit.MILLISECONDS);
        }
        sb.append(" ").append(TimeUnit.NANOSECONDS.convert(this.time, this.precision));
        return sb;
    }
  1. org.influxdb.impl.InfluxDBImpl.write(BatchPoints) and org.influxdb.impl.InfluxDBImpl.write(String, String, ConsistencyLevel, String) force nanosecond precision.
    @Override
    public void write(final BatchPoints batchPoints) {
        this.batchedCount.addAndGet(batchPoints.getPoints().size());
        RequestBody lineProtocol = RequestBody.create(MEDIA_TYPE_STRING, batchPoints.lineProtocol());
        execute(this.influxDBService.writePoints(
                this.username,
                this.password,
                batchPoints.getDatabase(),
                batchPoints.getRetentionPolicy(),
                TimeUtil.toTimePrecision(TimeUnit.NANOSECONDS),
                batchPoints.getConsistency().value(),
                lineProtocol));
    }

    @Override
    public void write(final String database, final String retentionPolicy, final ConsistencyLevel consistency,
            final String records)   {
        execute(this.influxDBService.writePoints(
                this.username,
                this.password,
                database,
                retentionPolicy,
                TimeUtil.toTimePrecision(TimeUnit.NANOSECONDS),
                consistency.value(),
                RequestBody.create(MEDIA_TYPE_STRING, records)));
    }

The desired precision should be passed down to whatever is formatting points to be written defaulting to nanosecond if/when not specified.

@majst01
Copy link
Collaborator

majst01 commented Oct 18, 2016

Hi,

thanks for the analysis, can you prepare a PR to show howto solve this issue ?

@joelmarty
Copy link
Contributor

I am working on a PR for this but I am unsure how to test it. Since the tests are directly hitting on an influxdb instance, is there any way to know the time precision of inserted points using queries ?

@andyfeller
Copy link

@joelmarty so for testing this I imagine there would be a mock InfluxDB service that would examine if the points' timestamps were of nanosecond precision vs an expected precision.

could you post a link to your fork with the fix as I'm finally being freed to do more time series work and would like to contribute.

@joelmarty
Copy link
Contributor

I created a pull request there: #321

It's based on an older version of the client and I don't have the time to work on it atm so there's conflicts but I hope you'll be able to work with that.

@PavelSarek
Copy link

+1
We would really appreciate this feature. Thanks for the pull request.

@asashour
Copy link
Contributor

I guess this should be closed now.

@agolovenko
Copy link

I guess this should be closed now.

In batching writes all the batch still defaults to nanos. Regardless of points precision.

@andyfeller
Copy link

Unless there has been a PR elsewhere to fix this, this is still a legit bug. The fact this has sat here for 2+ years doesn’t reflect well on Influx as supporting its customers, which is probably why everyone moving to Prometheus.

@majst01
Copy link
Collaborator

majst01 commented Jan 13, 2020

@andyfeller this is not a defect of influxdb-java which only can write what influxdb supports. influxdb-java is not a influx.com product, its a community maintained open source project.

@fmachado
Copy link
Contributor

@andyfeller thanks for pointing out this is still a relevant issue that should be fixed. I'm reopening this ticket and I'll work on it when possible (obviously we would be happy to have your support here, in case you could submit a PR :) ).

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

No branches or pull requests

10 participants