InfluxCommunity/influxdb3-java

`com.influxdb.v3.client.InfluxDBClient#getInstance()` should provide a variant that does not require a `token`

Closed this issue · 1 comments

Use Case

sdk install java 21.0.6-ms
git clone git@github.com:linghengqian/influxdb-3-core-jdbc-test.git
cd ./influxdb-3-core-jdbc-test/
sdk use java 21.0.6-ms
./mvnw -T 1C clean test
@Testcontainers
public class SqlTest {
    private final Instant magicTime = Instant.now().minusSeconds(10);
    @Container
    private final GenericContainer<?> container = new GenericContainer<>("quay.io/influxdb/influxdb3-core:911ba92ab4133e75fe2a420e16ed9cb4cf32196f")
            .withCommand("serve --node-id local01 --object-store file --data-dir /home/influxdb3/.influxdb3")
            .withExposedPorts(8181);
    @Test
    void test() throws Exception {
        try (InfluxDBClient client = InfluxDBClient.getInstance(
                "http://" + container.getHost() + ":" + container.getMappedPort(8181),
                null,
                "mydb")) {
            writeData(client);
            queryData(client);
        }
    }
    private void writeData(InfluxDBClient client) {
        Point point = Point.measurement("home")
                .setTag("location", "London")
                .setField("value", 30.01)
                .setTimestamp(magicTime);
        client.writePoint(point);
    }
    private void queryData(InfluxDBClient client) {
        try (Stream<Object[]> stream = client.query("select time,location,value from home order by time desc limit 10")) {
            List<Object[]> list = stream.toList();
            assertThat(list.size(), is(1));
            Object[] row = list.getFirst();
            assertThat(row[0], is(NanosecondConverter.convert(magicTime, WritePrecision.NS)));
            assertThat(row[1], is("London"));
            assertThat(row[2], is(30.01));
        }
    }
}

While in alpha, InfluxDB 3 Core does not require an authorization token.

  • Image
  • Always passing null to the constructor is not elegant from my point of view.

Expected behavior

  • com.influxdb.v3.client.InfluxDBClient#getInstance() should provide a variant that does not require a token. This is especially true considering the impact of the https://github.com/jspecify/jspecify specification on IDEs and various tools.

Actual behavior

  • com.influxdb.v3.client.InfluxDBClient#getInstance() always requires a token, and InfluxDB 3 Core never supported setting a token.

Additional info

Hi @linghengqian,

From a long-term perspective, InfluxDB 3 Core will require a token for connections. The current state is temporary, and future versions of InfluxDB 3 Core will break the client if no token is provided.

While passing null is not elegant, it’s a temporary solution until upcoming changes to InfluxDB 3 Core are implemented.

Best Regards