influxdata / influxdb-client-java

InfluxDB 2 JVM Based Clients
https://influxdata.github.io/influxdb-client-java/
MIT License
445 stars 128 forks source link

InfluxDB Client 6.8.0 with createV1 uses POST /api/v2/write instead of POST /write #566

Open polarnik opened 1 year ago

polarnik commented 1 year ago

Steps to reproduce: List the minimal actions needed to reproduce the behavior.

  1. Install InfluxDB v2
  2. Create a bucket 28c2cbcbac4cf29f
  3. Create v1 auth token with a name UserName and password: Password
    influx v1 auth create \
    --read-bucket 28c2cbcbac4cf29f --write-bucket 28c2cbcbac4cf29f \
    --username UserName
  4. Create v1 database with name DataBase and retention policy auto
    influx v1 dbrp create \
    --bucket-id 28c2cbcbac4cf29f --db DataBase --rp auto
  5. Try to write some metrics via V1 endpoint:
        try (InfluxDBClient client = InfluxDBClientFactory.createV1(
               "http://127.0.0.1:8086",
               "UserName",
               "Password".toCharArray(),
                "DataBase",
               "auto"
        )) {
            try (WriteApi writeApi = client.makeWriteApi()) {
                writeApi.writePoint(point);
                writeApi.flush();
            }
        }

Expected behavior: HTTP request via https://docs.influxdata.com/influxdb/v2.7/reference/api/influxdb-1x/write/ HTTP request:

POST /write?db=DataBase&rp=auto HTTP/1.1
Accept: application/json
User-Agent: influxdb-client-java/6.8.0
Authorization: Basic XXXXXXXX=
Accept-Encoding: identity
Content-Type: text/plain; charset=utf-8
Content-Length: 275
Host: 127.0.0.1:8086
Connection: Keep-Alive

iteration_duration,TEST_NAME=XXXXXXXX_HTTP_INFLUXDB_V1,scenario=default avg=542.131667,count=1i,max=542.131667,med=542.131667,min=542.131667,p(30)=542.131667,p(70)=542.131667,p(80)=542.131667,p(90)=542.131667,p(95)=542.131667,p(99)=542.131667,p(99.9)=542.131667 1684842304679

Actual behavior: HTTP request:

POST /api/v2/write?org=-&bucket=DataBase%2Fauto&precision=ms HTTP/1.1
Accept: application/json
User-Agent: influxdb-client-java/6.8.0
Authorization: Token UserName:Password
Accept-Encoding: identity
Content-Type: text/plain; charset=utf-8
Content-Length: 275
Host: 127.0.0.1:8086
Connection: Keep-Alive

iteration_duration,TEST_NAME=XXXXXXXX_HTTP_INFLUXDB_V1,scenario=default avg=542.131667,count=1i,max=542.131667,med=542.131667,min=542.131667,p(30)=542.131667,p(70)=542.131667,p(80)=542.131667,p(90)=542.131667,p(95)=542.131667,p(99)=542.131667,p(99.9)=542.131667 1684842304679

It doesn't work. Only 401 Errors.

May 23, 2023 4:47:52 PM com.influxdb.client.write.events.WriteErrorEvent logEvent
SEVERE: The error occurred during writing of data
com.influxdb.exceptions.UnauthorizedException: HTTP status code: 401; Message: unauthorized access
    at com.influxdb.internal.AbstractRestClient.responseToError(AbstractRestClient.java:115)
    at com.influxdb.internal.AbstractRestClient.toInfluxException(AbstractRestClient.java:99)
    at com.influxdb.client.internal.AbstractWriteClient.lambda$new$8(AbstractWriteClient.java:174)
    at io.reactivex.rxjava3.internal.subscribers.LambdaSubscriber.onNext(LambdaSubscriber.java:65)
    at io.reactivex.rxjava3.internal.operators.flowable.FlowableDoFinally$DoFinallySubscriber.onNext(FlowableDoFinally.java:85)
    at io.reactivex.rxjava3.internal.operators.mixed.FlowableConcatMapMaybe$ConcatMapMaybeSubscriber.drain(FlowableConcatMapMaybe.java:238)
    at io.reactivex.rxjava3.internal.operators.mixed.ConcatMapXMainSubscriber.onNext(ConcatMapXMainSubscriber.java:106)
    at com.influxdb.client.internal.flowable.BackpressureBatchesBufferStrategy$OnBackpressureBufferStrategySubscriber.drain(BackpressureBatchesBufferStrategy.java:238)
    at com.influxdb.client.internal.flowable.BackpressureBatchesBufferStrategy$OnBackpressureBufferStrategySubscriber.onNext(BackpressureBatchesBufferStrategy.java:149)
    at com.influxdb.client.internal.flowable.BackpressureBatchesBufferStrategy$OnBackpressureBufferStrategySubscriber.onNext(BackpressureBatchesBufferStrategy.java:54)
    at io.reactivex.rxjava3.internal.operators.flowable.FlowableFlatMap$MergeSubscriber.tryEmitScalar(FlowableFlatMap.java:232)
    at io.reactivex.rxjava3.internal.operators.flowable.FlowableFlatMap$MergeSubscriber.onNext(FlowableFlatMap.java:150)
    at io.reactivex.rxjava3.internal.operators.flowable.FlowableFilter$FilterSubscriber.tryOnNext(FlowableFilter.java:75)
    at io.reactivex.rxjava3.internal.operators.flowable.FlowableFilter$FilterSubscriber.onNext(FlowableFilter.java:53)
    at io.reactivex.rxjava3.internal.operators.flowable.FlowableFlatMap$MergeSubscriber.tryEmit(FlowableFlatMap.java:270)
    at io.reactivex.rxjava3.internal.operators.flowable.FlowableFlatMap$InnerSubscriber.onNext(FlowableFlatMap.java:627)
    at io.reactivex.rxjava3.internal.operators.flowable.FlowableMap$MapSubscriber.onNext(FlowableMap.java:69)
    at io.reactivex.rxjava3.subscribers.SerializedSubscriber.onNext(SerializedSubscriber.java:103)
    at com.influxdb.client.internal.flowable.FlowableBufferTimedFlushable$BufferExactBoundedSubscriber.accept(FlowableBufferTimedFlushable.java:227)
    at com.influxdb.client.internal.flowable.FlowableBufferTimedFlushable$BufferExactBoundedSubscriber.accept(FlowableBufferTimedFlushable.java:85)
    at io.reactivex.rxjava3.internal.subscribers.QueueDrainSubscriber.fastPathOrderedEmitMax(QueueDrainSubscriber.java:107)
    at com.influxdb.client.internal.flowable.FlowableBufferTimedFlushable$BufferExactBoundedSubscriber.run(FlowableBufferTimedFlushable.java:281)
    at com.influxdb.client.internal.flowable.FlowableBufferTimedFlushable$BufferExactBoundedSubscriber.lambda$onSubscribe$0(FlowableBufferTimedFlushable.java:149)
    at io.reactivex.rxjava3.internal.subscribers.LambdaSubscriber.onNext(LambdaSubscriber.java:65)
    at io.reactivex.rxjava3.processors.PublishProcessor$PublishSubscription.onNext(PublishProcessor.java:361)
    at io.reactivex.rxjava3.processors.PublishProcessor.offer(PublishProcessor.java:298)
    at com.influxdb.client.internal.AbstractWriteClient.flush(AbstractWriteClient.java:190)

Specifications:

Workaround: Use https://github.com/influxdata/influxdb-java instead of https://github.com/influxdata/influxdb-client-java for working with v1

polarnik commented 1 year ago

Workaround with org.influxdb:influxdb-java:2.23

//Point from https://github.com/influxdata/influxdb-client-java
import com.influxdb.client.write.Point; 

// Client from https://github.com/influxdata/influxdb-java
import org.influxdb.InfluxDB;
import org.influxdb.InfluxDBFactory;

...

        final InfluxDB influxDB = InfluxDBFactory.connect(InfluxDBAddress, Username, Password);
        influxDB.setDatabase(DataBase);
        influxDB.setRetentionPolicy(RetentionPolicy);
        InfluxLineGenerator influxLineGenerator = new InfluxLineGenerator(); // Some generator
        ArrayList<Point> points = influxLineGenerator.getPointList();
        for(Point point: points) {
            influxDB.write(DataBase, RetentionPolicy, InfluxDB.ConsistencyLevel.ALL, TimeUnit.MILLISECONDS,
                    point.toLineProtocol());
        }
        influxDB.close();

Gradle config:

    implementation("org.influxdb:influxdb-java:2.23")
    implementation("com.influxdb:influxdb-client-java:6.8.0")

Some important case:

  1. Send a point with tags and values
  2. Send a point with the same tags and values but with a new time

InfluxDB 1.8 POST /write - we will see the 2nd point in the DB InfluxDB 2.6.1 POST /write - we will see the all points in the DB